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

Commit 6d0f590

Browse files
committed
2 parents 8fad3f6 + ce120cd commit 6d0f590

21 files changed

Lines changed: 786 additions & 263 deletions

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

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
package org.usfirst.frc.team199.Robot2018;
99

1010
import org.usfirst.frc.team199.Robot2018.commands.CloseIntake;
11+
import org.usfirst.frc.team199.Robot2018.commands.FindTurnTimeConstant;
1112
import org.usfirst.frc.team199.Robot2018.commands.IntakeCube;
1213
import org.usfirst.frc.team199.Robot2018.commands.OpenIntake;
13-
import org.usfirst.frc.team199.Robot2018.commands.OutakeCube;
14+
import org.usfirst.frc.team199.Robot2018.commands.OuttakeCube;
1415
import org.usfirst.frc.team199.Robot2018.commands.PIDMove;
1516
import org.usfirst.frc.team199.Robot2018.commands.PIDTurn;
1617
import org.usfirst.frc.team199.Robot2018.commands.ResetEncoders;
@@ -38,26 +39,28 @@ public class OI {
3839
*/
3940

4041
public Joystick leftJoy;
42+
public Joystick rightJoy;
4143
private JoystickButton shiftLowGearButton;
4244
private JoystickButton shiftHighGearButton;
4345
private JoystickButton shiftDriveTypeButton;
44-
private JoystickButton PIDMoveButton;
45-
private JoystickButton PIDTurnButton;
46+
private JoystickButton pIDMoveButton;
47+
private JoystickButton pIDTurnButton;
4648
private JoystickButton resetEncButton;
47-
private JoystickButton MoveLiftUpButton;
48-
private JoystickButton MoveLiftDownButton;
49-
public Joystick rightJoy;
49+
private JoystickButton moveLiftUpButton;
50+
private JoystickButton moveLiftDownButton;
51+
private JoystickButton findTurnTimeConstantButton;
5052
private JoystickButton updatePIDConstantsButton;
5153
private JoystickButton updateEncoderDPPButton;
54+
5255
public Joystick manipulator;
53-
private JoystickButton closeIntake;
54-
private JoystickButton openIntake;
55-
private JoystickButton raiseIntake;
56-
private JoystickButton lowerIntake;
57-
private JoystickButton intake;
58-
private JoystickButton outake;
59-
private JoystickButton toggleLeftIntake;
60-
private JoystickButton toggleRightIntake;
56+
private JoystickButton closeIntakeButton;
57+
private JoystickButton openIntakeButton;
58+
private JoystickButton raiseIntakeButton;
59+
private JoystickButton lowerIntakeButton;
60+
private JoystickButton intakeCubeButton;
61+
private JoystickButton outakeCubeButton;
62+
private JoystickButton toggleLeftIntakeButton;
63+
private JoystickButton toggleRightIntakeButton;
6164

6265
public int getButton(String key, int def) {
6366
if (!SmartDashboard.containsKey("Button/" + key)) {
@@ -69,20 +72,24 @@ public int getButton(String key, int def) {
6972
return (int) SmartDashboard.getNumber("Button/" + key, def);
7073
}
7174

72-
public OI() {
75+
public OI(Robot robot) {
7376
leftJoy = new Joystick(0);
7477
shiftDriveTypeButton = new JoystickButton(leftJoy, getButton("Shift Drive Type", 2));
7578
shiftDriveTypeButton.whenPressed(new ShiftDriveType());
76-
PIDMoveButton = new JoystickButton(leftJoy, getButton("PID Move", 7));
77-
PIDMoveButton
79+
pIDMoveButton = new JoystickButton(leftJoy, getButton("PID Move", 7));
80+
pIDMoveButton
7881
.whenPressed(new PIDMove(Robot.sd.getConst("Move Targ", 24), Robot.dt, Robot.sd, RobotMap.distEncAvg));
79-
PIDTurnButton = new JoystickButton(leftJoy, getButton("PID Turn", 8));
82+
pIDTurnButton = new JoystickButton(leftJoy, getButton("PID Turn", 8));
8083
// PIDTurnButton.whenPressed(new PIDTurn(Robot.getConst("Turn Targ", 90),
8184
// Robot.dt, Robot.sd RobotMap.fancyGyro));
82-
PIDTurnButton
85+
pIDTurnButton
8386
.whenReleased(new PIDTurn(Robot.getConst("Turn Targ", 90), Robot.dt, Robot.sd, RobotMap.fancyGyro));
8487
resetEncButton = new JoystickButton(leftJoy, getButton("Reset Dist Enc", 10));
8588
resetEncButton.whenPressed(new ResetEncoders());
89+
findTurnTimeConstantButton = new JoystickButton(leftJoy, getButton("Find Turn Time Constant", 11));
90+
// the command will only run in test mode
91+
findTurnTimeConstantButton
92+
.whenPressed(new FindTurnTimeConstant(robot, Robot.dt, Robot.rmap.fancyGyro, Robot.sd));
8693

8794
rightJoy = new Joystick(1);
8895
shiftHighGearButton = new JoystickButton(rightJoy, getButton("Shift High Gear", 3));
@@ -93,30 +100,34 @@ public OI() {
93100
updatePIDConstantsButton.whenPressed(new UpdatePIDConstants());
94101
updateEncoderDPPButton = new JoystickButton(rightJoy, getButton("Get Encoder Dist Per Pulse", 9));
95102
updateEncoderDPPButton.whenPressed(new SetDistancePerPulse());
96-
MoveLiftUpButton = new JoystickButton(rightJoy, getButton("Run Lift Motor Up", 10));
97-
MoveLiftDownButton = new JoystickButton(rightJoy, getButton("Run Lift Motor Down", 11));
98-
MoveLiftUpButton.whileHeld(new RunLift(Robot.lift, true));
99-
MoveLiftDownButton.whileHeld(new RunLift(Robot.lift, false));
103+
moveLiftUpButton = new JoystickButton(rightJoy, getButton("Run Lift Motor Up", 10));
104+
moveLiftDownButton = new JoystickButton(rightJoy, getButton("Run Lift Motor Down", 11));
105+
moveLiftUpButton.whileHeld(new RunLift(Robot.lift, true));
106+
moveLiftDownButton.whileHeld(new RunLift(Robot.lift, false));
100107

101108
manipulator = new Joystick(2);
102-
closeIntake = new JoystickButton(manipulator, getButton("Close Intake Button", 1));
103-
closeIntake.whenPressed(new CloseIntake());
104-
openIntake = new JoystickButton(manipulator, getButton("Open Intake Button", 2));
105-
openIntake.whenPressed(new OpenIntake());
106-
// raiseIntake = new JoystickButton(manipulator, getButton("Raise Intake
107-
// Button", 3));
108-
// raiseIntake.whenPressed(new RaiseIntake());
109-
// lowerIntake = new JoystickButton(manipulator, getButton("Lower Intake
110-
// Button", 4));
111-
// lowerIntake.whenPressed(new LowerIntake());
112-
intake = new JoystickButton(manipulator, getButton("Intake Button", 5));
113-
intake.whenPressed(new IntakeCube());
114-
outake = new JoystickButton(manipulator, getButton("Outake Button", 6));
115-
outake.whenPressed(new OutakeCube());
116-
toggleLeftIntake = new JoystickButton(manipulator, getButton("Toggle Left Intake Button", 3));
117-
toggleLeftIntake.whenPressed(new ToggleLeftIntake());
118-
toggleRightIntake = new JoystickButton(manipulator, getButton("Toggle Right Intake Button", 4));
119-
toggleRightIntake.whenPressed(new ToggleRightIntake());
109+
if (manipulator.getButtonCount() == 0) {
110+
System.out.println("Manipulator not plugged in!");
111+
} else {
112+
closeIntakeButton = new JoystickButton(manipulator, getButton("Close Intake Button", 1));
113+
closeIntakeButton.whenPressed(new CloseIntake());
114+
openIntakeButton = new JoystickButton(manipulator, getButton("Open Intake Button", 2));
115+
openIntakeButton.whenPressed(new OpenIntake());
116+
// raiseIntake = new JoystickButton(manipulator, getButton("Raise Intake
117+
// Button", 3));
118+
// raiseIntake.whenPressed(new RaiseIntake());
119+
// lowerIntake = new JoystickButton(manipulator, getButton("Lower Intake
120+
// Button", 4));
121+
// lowerIntake.whenPressed(new LowerIntake());
122+
intakeCubeButton = new JoystickButton(manipulator, getButton("Intake Button", 5));
123+
intakeCubeButton.whenPressed(new IntakeCube());
124+
outakeCubeButton = new JoystickButton(manipulator, getButton("Outake Button", 6));
125+
outakeCubeButton.whenPressed(new OuttakeCube());
126+
toggleLeftIntakeButton = new JoystickButton(manipulator, getButton("Toggle Left Intake Button", 3));
127+
toggleLeftIntakeButton.whenPressed(new ToggleLeftIntake());
128+
toggleRightIntakeButton = new JoystickButton(manipulator, getButton("Toggle Right Intake Button", 4));
129+
toggleRightIntakeButton.whenPressed(new ToggleRightIntake());
130+
}
120131
}
121132

122133
// /**

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

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,26 @@ public double getConst(String key, double def) {
7171
return pref.getDouble("Const/" + key, def);
7272
}
7373

74+
public void putConst(String key, double def) {
75+
Preferences pref = Preferences.getInstance();
76+
pref.putDouble("Const/" + key, def);
77+
if (pref.getDouble("Const/ + key", def) != def) {
78+
System.err.println("pref Key" + "Const/" + key + "already taken by a different type");
79+
}
80+
}
81+
7482
public void putData(String string, PIDController controller) {
7583
SmartDashboard.putData(string, controller);
7684
}
7785

7886
public void putNumber(String string, double d) {
7987
SmartDashboard.putNumber(string, d);
8088
}
89+
90+
public void putBoolean(String string, boolean b) {
91+
SmartDashboard.putBoolean(string, b);
92+
}
93+
8194
/*
8295
* if (!SmartDashboard.containsKey("Const/" + key)) { if
8396
* (!SmartDashboard.putNumber("Const/" + key, def)) {
@@ -91,6 +104,10 @@ public static double getConst(String key, double def) {
91104
return sd.getConst(key, def);
92105
}
93106

107+
public static void putConst(String key, double def) {
108+
sd.putConst(key, def);
109+
}
110+
94111
public static boolean getBool(String key, boolean def) {
95112
Preferences pref = Preferences.getInstance();
96113
if (!pref.containsKey("Bool/" + key)) {
@@ -114,8 +131,8 @@ public void robotInit() {
114131
climberAssist = new ClimberAssist();
115132
intakeEject = new IntakeEject();
116133
lift = new Lift();
117-
dt = new Drivetrain();
118-
oi = new OI();
134+
dt = new Drivetrain(sd);
135+
oi = new OI(this);
119136

120137
// auto position chooser
121138
for (Autonomous.Position p : Autonomous.Position.values()) {
@@ -151,7 +168,7 @@ public void robotInit() {
151168
*/
152169
@Override
153170
public void disabledInit() {
154-
171+
dt.disableVelocityPIDs();
155172
}
156173

157174
@Override
@@ -195,6 +212,9 @@ public void autonomousPeriodic() {
195212

196213
@Override
197214
public void teleopInit() {
215+
System.out.println("In teleopInit()");
216+
dt.resetAHRS();
217+
AutoUtils.state = new State(0, 0, 0);
198218
// This makes sure that the autonomous stops running when
199219
// teleop starts running. If you want the autonomous to
200220
// continue until interrupted by another command, remove
@@ -224,14 +244,21 @@ public void teleopPeriodic() {
224244
// SmartDashboard.putNumber("Right Enc Dist", dt.getRightDist());
225245
// SmartDashboard.putNumber("Avg Enc Dist", dt.getEncAvgDist());
226246
//
247+
248+
System.out.printf("Left: %1$5.2f; Right: %2$5.2f\n", RobotMap.dtLeft.get(), RobotMap.dtRight.get());
249+
227250
SmartDashboard.putNumber("Angle", dt.getAHRSAngle());
228251
SmartDashboard.putNumber("Left Current draw", rmap.pdp.getCurrent(4));
229252
SmartDashboard.putNumber("Right Current draw", rmap.pdp.getCurrent(11));
230253
}
231254

232255
boolean firstTime = true;
233256

257+
@Override
234258
public void testInit() {
259+
System.out.println("In testInit()");
260+
dt.resetAHRS();
261+
AutoUtils.state = new State(0, 0, 0);
235262
}
236263

237264
/**
@@ -243,26 +270,39 @@ public void testPeriodic() {
243270
// Robot.dt.enableVelocityPIDs();
244271
// firstTime = false;
245272
//// }
246-
// Robot.dt.setVPIDs(Robot.getConst("VPID Test Set", 0.5));
273+
// dt.getLeftVPID().setConsts(getConst("VelocityLeftkI", 0), 0,
274+
// getConst("VelocityLeftkD", rmap.calcDefkD(dt.getCurrentMaxSpeed())),
275+
// /* 1 / dt.getCurrentMaxSpeed() */Robot.getConst("VelocityLeftkF",
276+
// 1 / Robot.getConst("Max Low Speed", 84)));
277+
// dt.getRightVPID().setConsts(getConst("VelocityRightkI", 0), 0,
278+
// getConst("VelocityRightkD", rmap.calcDefkD(dt.getCurrentMaxSpeed())),
279+
// /* 1 / dt.getCurrentMaxSpeed() */Robot.getConst("VelocityRightkF",
280+
// 1 / Robot.getConst("Max Low Speed", 84)));
281+
// dt.resetAllVelocityPIDConsts();
282+
283+
// dt.setVPIDs(getConst("VPID Test Set", 0.5));
247284

248285
Scheduler.getInstance().run();
249286

250-
SmartDashboard.putNumber("Drivetrain/Left VPID Targ", Robot.dt.getLeftVPIDSetpoint());
251-
SmartDashboard.putNumber("Drivetrain/Right VPID Targ", Robot.dt.getRightVPIDSetpoint());
252-
SmartDashboard.putNumber("Left VPID Error", Robot.dt.getLeftVPIDerror());
253-
SmartDashboard.putNumber("Right VPID Error", Robot.dt.getRightVPIDerror());
254-
SmartDashboard.putNumber("Left Enc Rate", Robot.dt.getLeftEncRate());
255-
SmartDashboard.putNumber("Right Enc Rate", Robot.dt.getRightEncRate());
287+
// System.out.println("Left VPID Targ: " + dt.getLeftVPIDOutput());
288+
// System.out.println("Right VPID Targ: " + dt.getRightVPIDOutput());
289+
// System.out.println("Left VPID Error: " + dt.getLeftVPIDerror());
290+
// System.out.println("Right VPID Error: " + dt.getRightVPIDerror());
291+
// System.out.println("Left Enc Rate: " + dt.getLeftEncRate());
292+
// System.out.println("Right Enc Rate: " + dt.getRightEncRate());
293+
//
294+
// System.out.println("Left Talon Speed: " + rmap.dtLeftMaster.get());
295+
// System.out.println("Right Talon Speed: " + rmap.dtRightMaster.get());
256296

257-
SmartDashboard.putNumber("Left Enc Dist", dt.getLeftDist());
258-
SmartDashboard.putNumber("Right Enc Dist", dt.getRightDist());
259-
SmartDashboard.putNumber("Avg Enc Dist", dt.getEncAvgDist());
297+
// System.out.println("Left Enc Dist " + dt.getLeftDist());
298+
// System.out.println("Right Enc Dist " + dt.getRightDist());
299+
// System.out.println("Avg Enc Dist" + dt.getEncAvgDist());
260300

261301
// dt.dtLeft.set(0.1);
262302
// dt.dtRight.set(-oi.rightJoy.getY());
263303
// dt.dtLeft.set(-oi.leftJoy.getY());
264304
// dt.dtRight.set(-oi.rightJoy.getY());
265305

266-
dt.putVelocityControllersToDashboard();
306+
// dt.putVelocityControllersToDashboard();
267307
}
268308
}

0 commit comments

Comments
 (0)