In reference to euhlmann's statement about your declaration of drive motors:
Quote:
|
Just make sure you define your arrays as "VictorSP[] driveMotors" for example, and not "Object[] driveMotors". That makes it a bit easier to read.
|
Not only does defining the array with type VictorSP make your code easy to read, it can prevent errors from happening in future.
Imagine this scenario:
Code:
Object driveMotor;
...
driveMotor = new VictorSP(1);
...
driveMotor.set(0.5);
Now you'll get a compiler error on the line "driveMotor.set(0.5);" This is because the compiler (and your code) doesn't know that driveMotor references a VictorSP. Sure, you know that since you assigned it to one in the previous line, but driveMotor was <i>declared</i> at the beginning as an object. You'd have to cast to a VictorSP, but that could lead to runtime errors because driveMotor could reference a USBCamera or a Date or a Potato.
The point is, when you declare a new variable, its type is all the rest of your code has to go by. Thus, you should be as specific as possible when declaring its type (by this I mean the lowest in the tree. In Java, every class extends Object. If a class has subclasses, unless for some reason the type isn't supposed to be known, you should declare it as one of those subclasses).
Amended:
Code:
VictorSP driveMotor;
...
driveMotor = new VictorSP(1);
...
//No Errors!
driveMotor.set(0.5);