Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit b899642

Browse files
teleop working on practice bot
After much arduous troubleshooting and a bad CIM, it works! Proper inversions for joysticks and motors, shifting gears works as expected (changed buttons a bit though), shifting drive type works as expected
1 parent 55965bd commit b899642

6 files changed

Lines changed: 53 additions & 34 deletions

File tree

Robot2018/src/org/usfirst/frc/team199/Robot2018/OI.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public int getButton(String key, int def) {
4545

4646
public OI() {
4747
leftJoy = new Joystick(0);
48-
shiftLowGearButton = new JoystickButton(leftJoy, getButton("Shift Low Gear", 3));
49-
shiftLowGearButton.whenPressed(new ShiftLowGear());
50-
shiftHighGearButton = new JoystickButton(leftJoy, getButton("Shift High Gear", 5));
51-
shiftHighGearButton.whenPressed(new ShiftHighGear());
5248
shiftDriveTypeButton = new JoystickButton(leftJoy, getButton("Shift Drive Type", 2));
5349
shiftDriveTypeButton.whenPressed(new ShiftDriveType());
5450
PIDMoveButton = new JoystickButton(leftJoy, getButton("PID Move", 7));
@@ -57,6 +53,10 @@ public OI() {
5753
PIDTurnButton.whenPressed(new PIDTurn(30, Robot.dt, RobotMap.fancyGyro));
5854

5955
rightJoy = new Joystick(1);
56+
shiftHighGearButton = new JoystickButton(rightJoy, getButton("Shift High Gear", 3));
57+
shiftHighGearButton.whenPressed(new ShiftHighGear());
58+
shiftLowGearButton = new JoystickButton(rightJoy, getButton("Shift Low Gear", 2));
59+
shiftLowGearButton.whenPressed(new ShiftLowGear());
6060
updatePIDConstantsButton = new JoystickButton(rightJoy, getButton("Get PID Constants", 8));
6161
updatePIDConstantsButton.whenPressed(new UpdatePIDConstants());
6262
updateEncoderDPPButton = new JoystickButton(rightJoy, getButton("Get Encoder Dist Per Pulse", 9));

Robot2018/src/org/usfirst/frc/team199/Robot2018/Robot.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,17 @@ public void testPeriodic() {
174174
// if(firstTime) {
175175
// Robot.dt.enableVelocityPIDs();
176176
// firstTime = false;
177-
// }
178-
Robot.dt.setVPIDs(Robot.getConst("VPID Test Set", 0.5));
179-
SmartDashboard.putNumber("Drivetrain/Left VPID Targ", Robot.dt.getLeftVPIDSetpoint());
180-
SmartDashboard.putNumber("Drivetrain/Right VPID Targ", Robot.dt.getRightVPIDSetpoint());
181-
SmartDashboard.putNumber("Left VPID Error", Robot.dt.getLeftVPIDerror());
182-
SmartDashboard.putNumber("Right VPID Error", Robot.dt.getRightVPIDerror());
183-
SmartDashboard.putNumber("Left Enc Rate", Robot.dt.getLeftEncRate());
184-
SmartDashboard.putNumber("Right Enc Rate", Robot.dt.getRightEncRate());
177+
//// }
178+
// Robot.dt.setVPIDs(Robot.getConst("VPID Test Set", 0.5));
179+
// SmartDashboard.putNumber("Drivetrain/Left VPID Targ", Robot.dt.getLeftVPIDSetpoint());
180+
// SmartDashboard.putNumber("Drivetrain/Right VPID Targ", Robot.dt.getRightVPIDSetpoint());
181+
// SmartDashboard.putNumber("Left VPID Error", Robot.dt.getLeftVPIDerror());
182+
// SmartDashboard.putNumber("Right VPID Error", Robot.dt.getRightVPIDerror());
183+
// SmartDashboard.putNumber("Left Enc Rate", Robot.dt.getLeftEncRate());
184+
// SmartDashboard.putNumber("Right Enc Rate", Robot.dt.getRightEncRate());
185+
186+
dt.dtLeft.set(-oi.leftJoy.getY());
187+
dt.dtRight.set(-oi.rightJoy.getY());
185188

186189
}
187190
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/RobotMap.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,20 @@ public class RobotMap {
6868
* the TalonSRX to configure
6969
*/
7070
private void configSRX(WPI_TalonSRX mc) {
71+
// stuff cole said to put
7172
int kTimeout = (int) Robot.getConst("kTimeoutMs", 10);
7273
mc.configNominalOutputForward(0, kTimeout);
7374
mc.configNominalOutputReverse(0, kTimeout);
7475
mc.configPeakOutputForward(1, kTimeout);
7576
mc.configPeakOutputReverse(-1, kTimeout);
77+
78+
// current limiting stuff cole said to put
79+
mc.configPeakCurrentLimit(0, 0);
80+
mc.configPeakCurrentDuration(0, 0);
81+
// 40 amps is the amp limit of a CIM. also, the PDP has 40 amp circuit breakers,
82+
// so if we went above 40, the motors would stop completely
83+
mc.configContinuousCurrentLimit(40, 0);
84+
mc.enableCurrentLimit(true);
7685
}
7786

7887
/**
@@ -83,6 +92,7 @@ private void configSRX(WPI_TalonSRX mc) {
8392
* the VictorSPX to configure
8493
*/
8594
private void configSPX(WPI_VictorSPX mc) {
95+
// stuff cole said to put
8696
int kTimeout = (int) Robot.getConst("kTimeoutMs", 10);
8797
mc.configNominalOutputForward(0, kTimeout);
8898
mc.configNominalOutputReverse(0, kTimeout);
@@ -92,12 +102,12 @@ private void configSPX(WPI_VictorSPX mc) {
92102

93103
public RobotMap() {
94104

95-
// intakeMotor = new WPI_TalonSRX(getPort("IntakeTalonSRX", 4));
96-
// configSRX(intakeMotor);
97-
// liftMotor = new WPI_TalonSRX(getPort("LiftTalonSRX", 5));
98-
// configSRX(liftMotor);
99-
// climberMotor = new WPI_TalonSRX(getPort("ClimberTalonSRX", 6));
100-
// configSRX(climberMotor);
105+
// intakeMotor = new WPI_TalonSRX(getPort("IntakeTalonSRX", 4));
106+
// configSRX(intakeMotor);
107+
// liftMotor = new WPI_TalonSRX(getPort("LiftTalonSRX", 5));
108+
// configSRX(liftMotor);
109+
// climberMotor = new WPI_TalonSRX(getPort("ClimberTalonSRX", 6));
110+
// configSRX(climberMotor);
101111

102112
leftEncPort1 = new DigitalInput(getPort("1LeftEnc", 1));
103113
leftEncPort2 = new DigitalInput(getPort("2LeftEnc", 0));
@@ -107,12 +117,14 @@ public RobotMap() {
107117
leftEncRate.setPIDSourceType(PIDSourceType.kRate);
108118
leftEncDist.setDistancePerPulse(Robot.getConst("Distance Per Pulse Left", 0.184));
109119
leftEncRate.setDistancePerPulse(Robot.getConst("Distance Per Pulse Left", 0.184));
110-
111-
dtLeftMaster = new WPI_TalonSRX(getPort("LeftTalonSRXMaster", 2));
120+
121+
dtLeftMaster = new WPI_TalonSRX(getPort("LeftTalonSRXMaster", 1));
112122
configSRX(dtLeftMaster);
113-
dtLeftSlave = new WPI_VictorSPX(getPort("LeftVictorSPXSlave", 0));
123+
dtLeftSlave = new WPI_VictorSPX(getPort("LeftVictorSPXSlave", 2));
114124
configSPX(dtLeftSlave);
115125
dtLeft = new SpeedControllerGroup(dtLeftMaster, dtLeftSlave);
126+
//inverted bc gear boxes invert from input to output
127+
dtLeft.setInverted(true);
116128

117129
leftVelocityController = new VelocityPIDController(Robot.getConst("VelocityLeftkP", 0),
118130
Robot.getConst("VelocityLeftkI", 0), Robot.getConst("VelocityLeftkD", 0),
@@ -122,6 +134,7 @@ public RobotMap() {
122134
leftVelocityController.setOutputRange(-1.0, 1.0);
123135
leftVelocityController.setContinuous(false);
124136
leftVelocityController.setAbsoluteTolerance(Robot.getConst("VelocityToleranceLeft", 2));
137+
SmartDashboard.putData(leftVelocityController);
125138

126139
rightEncPort1 = new DigitalInput(getPort("1RightEnc", 3));
127140
rightEncPort2 = new DigitalInput(getPort("2RightEnc", 2));
@@ -131,13 +144,15 @@ public RobotMap() {
131144
rightEncRate.setPIDSourceType(PIDSourceType.kRate);
132145
rightEncDist.setDistancePerPulse(Robot.getConst("Distance Per Pulse Right", 0.184));
133146
rightEncRate.setDistancePerPulse(Robot.getConst("Distance Per Pulse Right", 0.184));
134-
135-
dtRightMaster = new WPI_TalonSRX(getPort("RightTalonSRXMaster", 1));
147+
148+
dtRightMaster = new WPI_TalonSRX(getPort("RightTalonSRXMaster", 4));
136149
configSRX(dtRightMaster);
137150
dtRightSlave = new WPI_VictorSPX(getPort("RightVictorSPXSlave", 3));
138151
configSPX(dtRightSlave);
139152
dtRight = new SpeedControllerGroup(dtRightMaster, dtRightSlave);
140-
153+
//inverted bc gear boxes invert from input to output
154+
dtRight.setInverted(true);
155+
141156
rightVelocityController = new VelocityPIDController(Robot.getConst("VelocityRightkP", 0),
142157
Robot.getConst("VelocityRightkI", 0), Robot.getConst("VelocityRightkD", 0),
143158
1 / Robot.getConst("Max Low Speed", 84), rightEncRate, dtRight);
@@ -147,13 +162,14 @@ public RobotMap() {
147162
rightVelocityController.setContinuous(false);
148163
rightVelocityController.setAbsoluteTolerance(Robot.getConst("VelocityToleranceRight", 2));
149164

150-
// robotDrive = new DifferentialDrive(leftVelocityController, rightVelocityController);
151-
// robotDrive.setMaxOutput(Robot.getConst("Max High Speed", 204));
165+
// robotDrive = new DifferentialDrive(leftVelocityController,
166+
// rightVelocityController);
167+
// robotDrive.setMaxOutput(Robot.getConst("Max High Speed", 204));
152168
robotDrive = new DifferentialDrive(dtLeft, dtRight);
153-
169+
154170
distEncAvg = new PIDSourceAverage(leftEncDist, rightEncDist);
155171
fancyGyro = new AHRS(SerialPort.Port.kMXP);
156-
// dtGear = new DoubleSolenoid(getPort("1dtGearSolenoid", 0), getPort("2dtGearSolenoid", 1));
172+
dtGear = new DoubleSolenoid(getPort("1dtGearSolenoid", 0), getPort("2dtGearSolenoid", 1));
157173
}
158174

159175
/**

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/ShiftHighGear.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ShiftHighGear() {
1919
// Called just before this Command runs the first time
2020
@Override
2121
protected void initialize() {
22-
// Robot.dt.shiftGears(true);
22+
Robot.dt.shiftGears(true);
2323
SmartDashboard.putBoolean("High Gear", true);
2424
Robot.dt.resetVelocityPIDkFConsts();
2525
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/commands/ShiftLowGear.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public ShiftLowGear() {
1919
// Called just before this Command runs the first time
2020
@Override
2121
protected void initialize() {
22-
// Robot.dt.shiftGears(false);
22+
Robot.dt.shiftGears(false);
2323
SmartDashboard.putBoolean("High Gear", false);
2424
Robot.dt.resetVelocityPIDkFConsts();
2525
}

Robot2018/src/org/usfirst/frc/team199/Robot2018/subsystems/Drivetrain.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,15 @@ public double getRightEncDist() {
264264
* Activates the solenoid to push the drivetrain into high or low gear.
265265
*
266266
* @param highGear
267-
* If the solenoid is to be pushed into high gear (true, kForward) or
268-
* low gear (false, kReverse)
267+
* If the solenoid is to be pushed into high gear (true, kReverse) or
268+
* low gear (false, kForward)
269269
*/
270270
@Override
271271
public void shiftGears(boolean highGear) {
272272
if (highGear ^ Robot.getBool("Drivetrain Gear Shift Low", false)) {
273-
dtGear.set(DoubleSolenoid.Value.kForward);
274-
} else {
275273
dtGear.set(DoubleSolenoid.Value.kReverse);
274+
} else {
275+
dtGear.set(DoubleSolenoid.Value.kForward);
276276
}
277277
}
278278

0 commit comments

Comments
 (0)