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

Commit 7170ab4

Browse files
getting new teleop working
fixed motor ports and joystick inversion commented out all VPID stuff for now --> next to test changed encoder ports a bit but might need revision
1 parent 87d1e16 commit 7170ab4

6 files changed

Lines changed: 66 additions & 29 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,7 @@ public void teleopPeriodic() {
170170
*/
171171
@Override
172172
public void testPeriodic() {
173+
// Robot.dt.setLeft(0.2);
174+
Robot.dt.setRight(0.2);
173175
}
174176
}

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

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,63 +92,72 @@ private void configSPX(WPI_VictorSPX mc) {
9292

9393
public RobotMap() {
9494

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);
101-
102-
leftEncPort1 = new DigitalInput(getPort("1LeftEnc", 0));
103-
leftEncPort2 = new DigitalInput(getPort("2LeftEnc", 1));
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);
101+
102+
leftEncPort1 = new DigitalInput(getPort("1LeftEnc", 1));
103+
leftEncPort2 = new DigitalInput(getPort("2LeftEnc", 0));
104104
leftEncDist = new Encoder(leftEncPort1, leftEncPort2);
105105
leftEncDist.setPIDSourceType(PIDSourceType.kDisplacement);
106106
leftEncRate = new Encoder(leftEncPort1, leftEncPort2);
107107
leftEncRate.setPIDSourceType(PIDSourceType.kRate);
108-
dtLeftMaster = new WPI_TalonSRX(getPort("LeftTalonSRXMaster", 0));
108+
leftEncDist.setDistancePerPulse(Robot.getConst("Distance Per Pulse Left", 0.184));
109+
leftEncRate.setDistancePerPulse(Robot.getConst("Distance Per Pulse Left", 0.184));
110+
111+
dtLeftMaster = new WPI_TalonSRX(getPort("LeftTalonSRXMaster", 2));
109112
configSRX(dtLeftMaster);
110-
dtLeftSlave = new WPI_VictorSPX(getPort("LeftTalonSPXSlave", 1));
113+
dtLeftSlave = new WPI_VictorSPX(getPort("LeftVictorSPXSlave", 0));
111114
configSPX(dtLeftSlave);
112115
dtLeft = new SpeedControllerGroup(dtLeftMaster, dtLeftSlave);
113116

114117
leftVelocityController = new VelocityPIDController(Robot.getConst("VelocityLeftkP", 1),
115118
Robot.getConst("VelocityLeftkI", 0), Robot.getConst("VelocityLeftkD", 0),
116119
1 / Robot.getConst("Max Low Speed", 84), leftEncRate, dtLeft);
117-
leftVelocityController.enable();
120+
// leftVelocityController.enable();
118121
leftVelocityController.setInputRange(-Robot.getConst("Max High Speed", 204),
119122
Robot.getConst("Max High Speed", 204));
120123
leftVelocityController.setOutputRange(-1.0, 1.0);
121124
leftVelocityController.setContinuous(false);
122125
leftVelocityController.setAbsoluteTolerance(Robot.getConst("VelocityToleranceLeft", 2));
123126

124-
rightEncPort1 = new DigitalInput(getPort("1RightEnc", 2));
125-
rightEncPort2 = new DigitalInput(getPort("2RightEnc", 3));
126-
rightEncDist = new Encoder(leftEncPort1, leftEncPort2);
127+
rightEncPort1 = new DigitalInput(getPort("1RightEnc", 3));
128+
rightEncPort2 = new DigitalInput(getPort("2RightEnc", 2));
129+
rightEncDist = new Encoder(rightEncPort1, rightEncPort2);
127130
rightEncDist.setPIDSourceType(PIDSourceType.kDisplacement);
128-
rightEncRate = new Encoder(leftEncPort1, leftEncPort2);
131+
rightEncRate = new Encoder(rightEncPort1, rightEncPort2);
129132
rightEncRate.setPIDSourceType(PIDSourceType.kRate);
130-
dtRightMaster = new WPI_TalonSRX(getPort("RightTalonSRXMaster", 2));
133+
rightEncDist.setDistancePerPulse(Robot.getConst("Distance Per Pulse Right", 0.184));
134+
rightEncRate.setDistancePerPulse(Robot.getConst("Distance Per Pulse Right", 0.184));
135+
136+
dtRightMaster = new WPI_TalonSRX(getPort("RightTalonSRXMaster", 1));
131137
configSRX(dtRightMaster);
132-
dtRightSlave = new WPI_VictorSPX(getPort("RightTalonSPXSlave", 3));
138+
dtRightSlave = new WPI_VictorSPX(getPort("RightVictorSPXSlave", 3));
133139
configSPX(dtRightSlave);
134140
dtRight = new SpeedControllerGroup(dtRightMaster, dtRightSlave);
141+
// dtRight.setInverted(true);
135142

136143
rightVelocityController = new VelocityPIDController(Robot.getConst("VelocityRightkP", 1),
137144
Robot.getConst("VelocityRightkI", 0), Robot.getConst("VelocityRightkD", 0),
138145
1 / Robot.getConst("Max Low Speed", 84), rightEncRate, dtRight);
139-
rightVelocityController.enable();
146+
// rightVelocityController.enable();
140147
rightVelocityController.setInputRange(-Robot.getConst("Max High Speed", 204),
141148
Robot.getConst("Max High Speed", 204));
142149
rightVelocityController.setOutputRange(-1.0, 1.0);
143150
rightVelocityController.setContinuous(false);
144151
rightVelocityController.setAbsoluteTolerance(Robot.getConst("VelocityToleranceRight", 2));
145152

146-
robotDrive = new DifferentialDrive(leftVelocityController, rightVelocityController);
147-
robotDrive.setMaxOutput(Robot.getConst("Max High Speed", 204));
153+
// robotDrive = new DifferentialDrive(leftVelocityController, rightVelocityController);
154+
robotDrive = new DifferentialDrive(dtLeft, dtRight);
155+
156+
// robotDrive.setMaxOutput(Robot.getConst("Max High Speed", 204));
148157

149158
distEncAvg = new PIDSourceAverage(leftEncDist, rightEncDist);
150159
fancyGyro = new AHRS(SerialPort.Port.kMXP);
151-
dtGear = new DoubleSolenoid(getPort("1dtGearSolenoid", 0), getPort("2dtGearSolenoid", 1));
160+
// dtGear = new DoubleSolenoid(getPort("1dtGearSolenoid", 0), getPort("2dtGearSolenoid", 1));
152161
}
153162

154163
/**

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/commands/TeleopDrive.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ protected void initialize() {
2828
// Called repeatedly when this Command is scheduled to run
2929
@Override
3030
protected void execute() {
31+
Robot.dt.resetVPIDInputRanges();
3132
Robot.dt.teleopDrive();
3233
}
3334

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

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@
2020
import edu.wpi.first.wpilibj.SpeedControllerGroup;
2121
import edu.wpi.first.wpilibj.command.Subsystem;
2222
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
23+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
2324

2425
public class Drivetrain extends Subsystem implements DrivetrainInterface {
2526
// Put methods for controlling this subsystem
2627
// here. Call these from Commands.
2728

2829
private final Encoder leftEncDist = RobotMap.leftEncDist;
2930
private final Encoder rightEncDist = RobotMap.rightEncDist;
31+
private final Encoder leftEncRate = RobotMap.leftEncRate;
32+
private final Encoder rightEncRate = RobotMap.rightEncRate;
3033
private final PIDSourceAverage distEncAvg = RobotMap.distEncAvg;
31-
private final SpeedControllerGroup dtLeft = RobotMap.dtLeft;
32-
private final SpeedControllerGroup dtRight = RobotMap.dtRight;
34+
public final SpeedControllerGroup dtLeft = RobotMap.dtLeft;
35+
public final SpeedControllerGroup dtRight = RobotMap.dtRight;
3336
private final DifferentialDrive robotDrive = RobotMap.robotDrive;
3437
private final VelocityPIDController leftVelocityController = RobotMap.leftVelocityController;
3538
private final VelocityPIDController rightVelocityController = RobotMap.rightVelocityController;
@@ -41,6 +44,14 @@ public class Drivetrain extends Subsystem implements DrivetrainInterface {
4144
public void initDefaultCommand() {
4245
setDefaultCommand(new TeleopDrive());
4346
}
47+
48+
public void setLeft(double spd) {
49+
dtLeft.set(spd);
50+
}
51+
52+
public void setRight(double spd) {
53+
dtRight.set(spd);
54+
}
4455

4556
/**
4657
* Drives based on joystick input and SmartDashboard values
@@ -49,13 +60,21 @@ public void initDefaultCommand() {
4960
public void teleopDrive() {
5061
if (Robot.getBool("Arcade Drive", true)) {
5162
if (Robot.getBool("Arcade Drive Default Setup", true)) {
52-
Robot.dt.arcadeDrive(Robot.oi.leftJoy.getY(), Robot.oi.rightJoy.getX());
63+
Robot.dt.arcadeDrive(-Robot.oi.leftJoy.getY(), Robot.oi.rightJoy.getX());
5364
} else {
54-
Robot.dt.arcadeDrive(Robot.oi.rightJoy.getY(), Robot.oi.leftJoy.getX());
65+
Robot.dt.arcadeDrive(-Robot.oi.rightJoy.getY(), Robot.oi.leftJoy.getX());
5566
}
5667
} else {
57-
Robot.dt.tankDrive(Robot.oi.leftJoy.getY(), Robot.oi.rightJoy.getY());
68+
Robot.dt.tankDrive(-Robot.oi.leftJoy.getY(), -Robot.oi.rightJoy.getY());
5869
}
70+
SmartDashboard.putNumber("Drivetrain/Left VPID Targ", leftVelocityController.getSetpoint());
71+
SmartDashboard.putNumber("Drivetrain/Right VPID Targ", rightVelocityController.getSetpoint());
72+
SmartDashboard.putNumber("Drivetrain/Current Max Speed", getCurrentMaxSpeed());
73+
SmartDashboard.putNumber("Drivetrain/Left Enc Dist", leftEncDist.getDistance());
74+
SmartDashboard.putNumber("Drivetrain/Left Enc Rate", leftEncRate.getRate());
75+
SmartDashboard.putNumber("Drivetrain/Right Enc Dist", rightEncDist.getDistance());
76+
SmartDashboard.putNumber("Drivetrain/Right Enc Rate", rightEncRate.getRate());
77+
SmartDashboard.putNumber("Drivetrain/Enc Avg Dist", distEncAvg.pidGet());
5978
}
6079

6180
/**
@@ -249,6 +268,12 @@ public double resetVelocityPIDkFConsts() {
249268
rightVelocityController.setF(newKF);
250269
return newKF;
251270
}
271+
272+
public double resetVPIDInputRanges() {
273+
double currentMaxSpd = getCurrentMaxSpeed();
274+
leftVelocityController.setInputRange(-currentMaxSpd, currentMaxSpd);
275+
return currentMaxSpd;
276+
}
252277

253278
/**
254279
* Gets the current max speed of the DT based on gearing (high or low gear)

0 commit comments

Comments
 (0)