Java Coding Problems

We have a programming error, some problems could have spawned from syntax errors. After I added in code for my team’s lift, the drive stopped working. please check our code at https://github.com/alexandrialim/FRC-2017-Team-3008/pull/3/files

It looks to me like you have an extra right brace in your code. If you right click on your source code in Eclipse and select Source -> Format, it should clean up some of your indentation and make it easier to track these types of errors down.

Also, it looks like you are attempting to mix Command based usage in with a SampleRobot project. I don’t know if this is possible, but I would not recommend it. For a sample based project, I would refactor your lift() command to check for user input and set the appropriate power level to your lift motor.

For example, if you want the driver to be able to move the lift up or down using two different buttons on their Joystick/gamepad, I would recommend defining some constants up top in your code to keep track of button usage. For example, to define two driver buttons for lift control, you could start with:


  // Constants used to map buttons on Driver joystick/gamepad
  private static final int DRIVER_BUTTON_LIFT_UP = 3;
  private static final int DRIVER_BUTTON_LIFT_DOWN = 4;

The following demonstrates one way to refactor the lift() method to always update the power setting for the lift motor so that the motor will be turned off unless the driver is holding down one of the buttons defined previously:


  /**
   * Method used to manually operate the lift (call often from operatorControl()).
   */
  private void lift() {
    // Assume no button is pressed and lift should be turned off
    double liftPower = 0.0;
    
    if (joystick.getRawButton(DRIVER_BUTTON_LIFT_UP)) {
      // Power level for lift when you want to go up (ADJUST for your robot)
      liftPower = 0.4;
    } else if (joystick.getRawButton(DRIVER_BUTTON_LIFT_DOWN)) {
      // Power level for lift when you want to go down (ADJUST for your robot)
      liftPower = -0.2;
    }
    
    // Apply selected power to lift motor
    lift.set(liftPower);
  }

You can use other methods from the driver joystick to determine if you want to move the lift up/down (or use the other joystick if you don’t want to have the driver operate the lift). However, you can track down raw button values for most Joysticks/gamepads by selecting the joystick/gamepad in the Driver Station (under the USB panel) and pressing buttons.

IMPORTANT: You will need to play with the liftPower values. You will likely need to increase their values. You may also need to invert the signs based on what your motors/gears do when you apply positive or negative voltage.

Finally, you will need to update your operatorControl() method to call the lift() method. You already have the code there, but it is currently commented out.

Hope that helps.