Git Product home page Git Product logo

6cimdrive's People

Contributors

themkrage avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

6cimdrive's Issues

Follow best practices in code style

There are a lot of well-established best practices for code in Java that you should be following.
Google has published a really good style guide that you should familiarize yourself with and follow. A lot of people, especially relatively new programmers don't understand the importance of good style but it is very important for other people reading your code and your future self.

A few that I've noticed you're not following:

  • Controller should not be capitalized here
  • modifiedGyro should be ModifiedGyro

Declare all your variables in one spot

It is generally best practice to declare all member variables at the top of the class. You have some declarations interspersed everywhere in Drive mixed in among the methods, that way it's impossible to look in one place and see all of the variables contained in the class

Run auto-format

Sometimes your indentation and other spacing is messed up and it bothers me. I always run auto-format in my IDE before saving a file. It might not seem like a big deal but the code is much more aesthetically pleasing and easier to read if the formatting is consistent everywhere

Package declaration

You should have everything in a package. (org.team3309.frc2015 is a good name for the season's code). When you have everything in the default package, other classes cannot import them, it is always best practice to never use the default package and always specify a package name. See 2014 for a sample package organization

modifiedGyro

Class names should always start with an upper case character and then camel-case after that. This would then be ModifiedGyro

You should also add a Javadoc comment on the declaration of the class to say what it does. Specifically, what does it do that a regular Gyro doesn't? I know, but other people reading it might not

Use arrays for motor controllers

Instead of having 6 separate variables to hold the 3 Victors for each side, you can declare two arrays of 3 Victors each, and loop through the array when you set a value for them

Better commenting

You should have comments on parts of code that people are likely to have difficulty understanding. Comments are also useful for yourself in the future, not just other people.
Comments like the following are useless:

I felt bad for giving so many bad examples so here are some examples of good comments (from your code):

A lot of teams have experimented with auto-shifting in the past and it has ended badly

I've read a lot about teams like 33 experiment with auto-shifting like it seems as if you are doing here and the general consensus is that it's a bad thing to do. My opinion (and maybe Michael has a different one) is that the driver should have full control over when they shift gears. There are countless different scenarios that could happen during a match, and you can't possibly think of all of them beforehand. Auto-shifting could have undesired consequences if for example you can't try and ram someone in low gear because it shifted to high automatically and now you brown-out while trying to push another robot.

Having a separate boolean for enable/disable state of each state is a recipe for disaster

Speaking from experience, it is really easy to forget to update all necessary variables when some are linked like this. Instead of having haloDriveEnabled and tankDriveEnabled, you should use an int for driveMode and private static final ints to represent something like MODE_HALO_DRIVE = 0 MODE_TANK_DRIVE = 1, etc and check if driveMode == one of those (this way you could also have more than 2 states)

Member variable/method access control

As a general rule of thumb, everything other than static variables should always be declared as private. If you need to access or set the value of a class's member variable, you should have getter and setter methods to access/set the value respectively.

Here are some spots where I noticed you either didn't declare an access modifier or used it incorrectly:

  • the drive mode booleans
    • should be private and have getters/setters if necessary
  • the constructor of Drive
    • The constructor of Drive should be declared as private, not public
    • This might not make immediate sense but the reason for making it private is to enforce that no one else can create a Drive instance except code in the Drive class. Since a robot can only have one drivetrain, you should employ the Singleton pattern.
    • For an example of a Singleton, see this part of the Drive code from 2014
  • gyroEnabled
    • should be private and have getter/setter if necessary
  • driveHalo and driveTank
    • Since these methods are public, anyone can call them to control the drivetrain, completely bypassing the current mode selection. This is allowing other code to potentially circumvent your selected driving mode, which could cause hard to debug issues.
    • They should both be private and only called from the public drive() method that will then call the appropriate choice based on the current driving mode.
  • setDriveshifter
    • this should obviously be private for the same reason as directly above
    • you even say not to call it in the comment right above the method declaration
      • you shouldn't just "ask nicely" to not call it, you should not allow anyone to call it at all by declaring it private
  • straightPidEnabled
    • should be private and have getter/setter if necessary

Scheduler use in Robot

There's no reason to have anything with a Scheduler in there if you don't have any Commands. See my 2014 code or the WPILib docs for more info. If you are going to use the Command based architecture, there should be a Command subclass for driving that you just start in teleopInit and stop in disabledInit again see 2014 code for more info

XboxControllerMap

This should not be its own class, but instead make all of the fields in here (public static) members of XboxController. You really only need to use it in XboxController so it would make the code cleaner, but you still want them to be accessible if you want to use the JoystickButton class provided with the command-based framework from FRC

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.