Programming a wrist is very similar to programming an elevator. The primary differences are that the elevator has 5 different levels, whereas the wrist only had 3. Other notable differences are that the elevator is controlled by 2 SPX's and 2 SRX's, while the wrist is controlled by one SRX. The wrist also has a limit switch, that tell you wheater the wrist is flat or not (very similar to how the banner sensor tells you if the elevator is all the way down or not).
To write the wrist program, we will be working with both the Robot.java file, and the Wrist.java file. You can also feel free to look at the Elevator.java file for assitance.
- First create a static
WPI_TalonSRX
motor calledwristMotor
. - Create a static function called
moveWrist()
that takes in the parameterspeed
. In this function you will set the speed of thewristMotor
to thespeed
variable.wristMotor.set(ControlMode.PercentOutput, speed);
- Create a function called
stopWrist
that sets the speed of thewristMotor
to 0. - For testing purposes go to the
runElevator()
function and addWrist.moveWrist(joy.leftJoySticky1);
aftereleVader.setElevatorEncoder();
. To test if this works you would have to move the right joystick on the co-driver controller. - Make sure that the wrist moves up when you send it a positive value to the
moveWrist()
function that the wrist rotates upward, and that the wrist moves downward if you send a negative value to themoveWrist()
function. If it is flipped, changewristMotor.set(ControlMode.PercentOutput, -speed);
towristMotor.set(ControlMode.PercentOutput, speed);
For steps 1 - 3 use the Wrist.java file, and for step 4 use the Robot.java file.
Since I am out of town, set the wrist to a constant speed for now. Try to pick a speed value that is not too fast, not too slow. So for example if you set .2
as your speed, make the wrist move at .2
whenever the joystick value is greater than 0
, and make the wrist move at -.2
when the joystick value is less than 0
. You guys are smart enough to figure this out.
- The limit switch works the same way the banner sensor does. Remember that the purpose of the limit switch is to that tell us wheater the wrist is flat or not. If it is flat, it must return
true
, otherwisefalse
. Name the limit switch objectlimitSwitch
(it's aDigitalInput
. If you have trouble, reference to ElevatorLevel.java to see how the banner sensor was programmed). - Create a static
testLimitSwitch()
andsetLimitSwitch()
function to see if the limit switch works. Remember to uselimitSwitch.get()
to recieve the boolean variable. Make sure it returnstrue
when the wrist is flat, andfalse
otherwise. If it is flipped, change theflat
variable statement toflat = !limitSwitch.get();
instead offlat = limitSwitch.get();
in thesetLimitSwitch()
function. Test the limit switch - For getting the encoder values use
wristMotor.getSensorCollection().getQuadraturePosition();
. Test if the encoder works. Make the following functions like we always do:setEncoderValues()
,resetEncoders()
,testEncoders()
. Make sure to call thesetEncoderValues()
function in Robot.java from theWrist
class right aftereleVader.setElevatorEncoder();
in therunElevator()
function. - Call the
resetEncoders()
function whenever the wrist is flat (when theflat
variable istrue
). For reseting the encoders,wristMotor.getSensorCollection().setQuadraturePosition(0, 10);
Very similar to how each elevator position had its own encoder position, the same thing applies for the wrist.
// These are the encoder values for these elevator positions
public static final double stop = 0;
public static final double pickUp = 3000;
public static final double sWitch = 13000;
public static final double lowerScale = 36300;
public static final double scale = 41500;
Remember to reset the wrist encoder when its flat before you measure the tick count. You can view the tick count by just printing the encoder value from the wristMotor
. The code you will be editing is in Constants.java:
//Wrist
public final static int flat = 0;
public final static int sixtyDegrees = 0;
public final static int up = 0;
Obvious clues:
- The encoder count for the
flat
variable is0
, very similar to how thestop
variable had a value of 0. - For printing the enoder values, you would use the
testEncoders()
function.