Gearbox with Encoder -- how do you program it using Java?

My team and I have been stuck on this for two months now. We have this gearbox with a built-in encoder and we have tried wiring it as described in this thread. We’re trying to get it to move forward/backwards when a controller joystick is moved forward/backwards. Can anyone offer exact wiring steps (we’re using these sparks motor controllers). In isolation, this is the relevant pieces of code we’re using:

public class Robot extends IterativeRobot {
	 * The "gearbox with built-in encoder" is connected to a
	 * Sparks motorcontroller. This Sparks motorcontroller
	 * is, in turn, connected to PWM port 0 on the robo-rio.
	 * */
	Victor gearBox = new Victor(0); //should this be a 'Victor'?
	 * a controller is plugged into the driver's station, and
	 * is listed as being component #0 under the "USB Order" list
	 * in the driver station.
	 * */
	Joystick controller = new Joystick(0);
 public void teleopPeriodic() {
	  * Stores the direction of the joystick listed as
	  * #1 under "axis". The value stored here will 
	  * dictate the speed of the gearbox.
	  * */
	 double joystickValue = controller.getRawAxis(1);
	  * Set the speed of the gearbox.  The speed will 
	  * depend on how far forward, or backward, the
	  * joystick is moved.
	  * */

This is our first season with FRC and robotics. We simply want to get this gearbox to “spin”, but we’re completely stuck and don’t know where to turn :frowning:

Can you indicate the status of the LED on the spark motor controller when you turn the robot on, when you run teleop without moving the controller, and when you run teleop with moving the controller?

The LED lights on the Sparks motor controller during teleop look as follows:

  • Blue when we turn the robot on.
  • Green when moving the joystick forward, Red when moving it back.
  • Orange when not moving the joystick.

So, the joystick movement is detected and the signals are being sent. But the encoder/gearbox is not moving at all

The thread you referenced only covers the encoder wiring, not the motor wiring. How do you have the motor wired? You should be using the Spark class not the victor class, although that only provides a small performance improvement, and doesn’t explain why it doesn’t move.

@Joe Ross:

That’s a good point, I think that might be our problem (a correct wiring of the encoder, but incorrect wiring of the motor). As of now, the “Motor+” and “Motor-” channels of the gearbox/encoder are connected to the Sparks motor controller. Is that the correct wiring?


Connecting the motor to Motor + and - is correct (I can’t see your image). Are you able to move the mechanism (is this your drivetrain?) by hand? If it was jammed up, that would explain why it doesn’t move.
You could also try touching the wires from another motor to the Spark Motor+/- connections while operating the joystick and see if that motor operates. That would quickly isolate where the problem is.
Putting a multimeter on the Motor +/- connections and measuring output voltage with the joystick at full motion would also be helpful.
Let us know what these tests show and if you find a solution, please post what it was so others can be helped as well.

If you have an extra, you can eliminate the gearbox question by ensuring that your current code will drive a free standing motor in the way you expect.

Being new to FRC, if you have verified your code drives a motor correctly, then it’s easier to troubleshoot the gearbox. If you have two variables, harder to track down easily.