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

Commit c7a5809

Browse files
committed
Formatted commands and added infra to test
1 parent 393d31c commit c7a5809

6 files changed

Lines changed: 245 additions & 54 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77

88
package org.usfirst.frc.team199.Robot2018;
99

10-
import org.usfirst.frc.team199.Robot2018.commands.*;
10+
import org.usfirst.frc.team199.Robot2018.commands.PIDMove;
11+
import org.usfirst.frc.team199.Robot2018.commands.PIDTurn;
12+
import org.usfirst.frc.team199.Robot2018.commands.SetDistancePerPulse;
13+
import org.usfirst.frc.team199.Robot2018.commands.ShiftDriveType;
14+
import org.usfirst.frc.team199.Robot2018.commands.ShiftHighGear;
15+
import org.usfirst.frc.team199.Robot2018.commands.ShiftLowGear;
16+
import org.usfirst.frc.team199.Robot2018.commands.UpdatePIDConstants;
1117

1218
import edu.wpi.first.wpilibj.Joystick;
1319
import edu.wpi.first.wpilibj.buttons.JoystickButton;
@@ -73,16 +79,16 @@ public OI() {
7379
shiftDriveType = new JoystickButton(leftJoy, getButton("Shift Drive Type", 2));
7480
shiftDriveType.whenPressed(new ShiftDriveType());
7581
PIDMove = new JoystickButton(leftJoy, getButton("PID Move", 7));
76-
PIDMove.whenPressed(new PIDMove(40));
82+
PIDMove.whenPressed(new PIDMove(40), Robot.dt);
7783
PIDTurn = new JoystickButton(leftJoy, getButton("PID Turn", 8));
78-
PIDTurn.whenPressed(new PIDTurn(30));
79-
84+
PIDTurn.whenPressed(new PIDTurn(30), Robot.dt);
85+
8086
rightJoy = new Joystick(1);
8187
updatePidConstants = new JoystickButton(rightJoy, getButton("Get PID Constants", 8));
8288
updatePidConstants.whenPressed(new UpdatePIDConstants());
8389
updateEncoderDPP = new JoystickButton(rightJoy, getButton("Get Encoder Dist Per Pulse", 9));
8490
updateEncoderDPP.whenPressed(new SetDistancePerPulse());
85-
91+
8692
manipulator = new Joystick(2);
8793
}
8894
}

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.usfirst.frc.team199.Robot2018.commands;
22

33
import org.usfirst.frc.team199.Robot2018.Robot;
4+
import org.usfirst.frc.team199.Robot2018.subsystems.DrivetrainInterface;
45

56
import edu.wpi.first.wpilibj.command.Command;
67

@@ -10,35 +11,37 @@
1011
public class PIDMove extends Command {
1112

1213
double target;
14+
DrivetrainInterface dt;
1315

14-
public PIDMove(double targ) {
16+
public PIDMove(double targ, DrivetrainInterface dt) {
1517
// Use requires() here to declare subsystem dependencies
1618
// eg. requires(chassis);
1719
target = targ;
20+
this.dt = dt;
1821
requires(Robot.dt);
1922
}
2023

2124
// Called just before this Command runs the first time
2225
protected void initialize() {
23-
Robot.dt.resetEnc();
24-
Robot.dt.enableMovePid();
25-
Robot.dt.setMoveSetpoint(target);
26+
dt.resetEnc();
27+
dt.enableMovePid();
28+
dt.setMoveSetpoint(target);
2629
}
2730

2831
// Called repeatedly when this Command is scheduled to run
2932
protected void execute() {
30-
Robot.dt.arcadeDrive(Robot.dt.getPidOut(), 0);
33+
dt.arcadeDrive(dt.getPidOut(), 0);
3134
}
3235

3336
// Make this return true when this Command no longer needs to run execute()
3437
protected boolean isFinished() {
35-
return Robot.dt.onDriveTarg();
38+
return dt.onDriveTarg();
3639
}
3740

3841
// Called once after isFinished returns true
3942
protected void end() {
40-
Robot.dt.disableMovePid();
41-
Robot.dt.stopDrive();
43+
dt.disableMovePid();
44+
dt.stopDrive();
4245
}
4346

4447
// Called when another command which requires one or more of the same

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.usfirst.frc.team199.Robot2018.commands;
22

33
import org.usfirst.frc.team199.Robot2018.Robot;
4+
import org.usfirst.frc.team199.Robot2018.subsystems.DrivetrainInterface;
45

56
import edu.wpi.first.wpilibj.command.Command;
67

@@ -10,35 +11,37 @@
1011
public class PIDTurn extends Command {
1112

1213
double target;
14+
DrivetrainInterface dt;
1315

14-
public PIDTurn(double targ) {
16+
public PIDTurn(double targ, DrivetrainInterface dt) {
1517
// Use requires() here to declare subsystem dependencies
1618
// eg. requires(chassis);
1719
target = targ;
20+
this.dt = dt;
1821
requires(Robot.dt);
1922
}
2023

2124
// Called just before this Command runs the first time
2225
protected void initialize() {
23-
Robot.dt.resetAHRS();
24-
Robot.dt.setTurnSetpoint(target);
25-
Robot.dt.enableTurnPid();
26+
dt.resetAHRS();
27+
dt.setTurnSetpoint(target);
28+
dt.enableTurnPid();
2629
}
2730

2831
// Called repeatedly when this Command is scheduled to run
2932
protected void execute() {
30-
Robot.dt.arcadeDrive(0, Robot.dt.getPidOut());
33+
dt.arcadeDrive(0, dt.getPidOut());
3134
}
3235

3336
// Make this return true when this Command no longer needs to run execute()
3437
protected boolean isFinished() {
35-
return Robot.dt.onTurnTarg();
38+
return dt.onTurnTarg();
3639
}
3740

3841
// Called once after isFinished returns true
3942
protected void end() {
40-
Robot.dt.disableTurnPid();
41-
Robot.dt.stopDrive();
43+
dt.disableTurnPid();
44+
dt.stopDrive();
4245
}
4346

4447
// Called when another command which requires one or more of the same

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

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,37 @@
1111
public class SetDistancePerPulse extends Command {
1212

1313
Timer tim;
14-
public SetDistancePerPulse() {
15-
// Use requires() here to declare subsystem dependencies
16-
// eg. requires(chassis);
17-
}
18-
19-
// Called just before this Command runs the first time
20-
protected void initialize() {
21-
tim = new Timer();
22-
tim.reset();
23-
tim.start();
24-
}
25-
26-
// Called repeatedly when this Command is scheduled to run
27-
protected void execute() {
28-
Robot.dt.setDistancePerPulseLeft(Robot.getConst("Distance Per Pulse Left", 0.184));
29-
Robot.dt.setDistancePerPulseRight(Robot.getConst("Distance Per Pulse Right", 0.184));
30-
}
31-
32-
// Make this return true when this Command no longer needs to run execute()
33-
protected boolean isFinished() {
34-
return tim.get() > Robot.getConst("Update Constants Time", 0.1);
35-
}
36-
37-
// Called once after isFinished returns true
38-
protected void end() {
39-
}
40-
41-
// Called when another command which requires one or more of the same
42-
// subsystems is scheduled to run
43-
protected void interrupted() {
44-
end();
45-
}
14+
15+
public SetDistancePerPulse() {
16+
// Use requires() here to declare subsystem dependencies
17+
// eg. requires(chassis);
18+
}
19+
20+
// Called just before this Command runs the first time
21+
protected void initialize() {
22+
tim = new Timer();
23+
tim.reset();
24+
tim.start();
25+
}
26+
27+
// Called repeatedly when this Command is scheduled to run
28+
protected void execute() {
29+
Robot.dt.setDistancePerPulseLeft(Robot.getConst("Distance Per Pulse Left", 0.184));
30+
Robot.dt.setDistancePerPulseRight(Robot.getConst("Distance Per Pulse Right", 0.184));
31+
}
32+
33+
// Make this return true when this Command no longer needs to run execute()
34+
protected boolean isFinished() {
35+
return tim.get() > Robot.getConst("Update Constants Time", 0.1);
36+
}
37+
38+
// Called once after isFinished returns true
39+
protected void end() {
40+
}
41+
42+
// Called when another command which requires one or more of the same
43+
// subsystems is scheduled to run
44+
protected void interrupted() {
45+
end();
46+
}
4647
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import edu.wpi.first.wpilibj.command.Subsystem;
2525
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
2626

27-
public class Drivetrain extends Subsystem implements PIDOutput, PIDSource {
27+
public class Drivetrain extends Subsystem implements PIDOutput, PIDSource, DrivetrainInterface {
2828
// Put methods for controlling this subsystem
2929
// here. Call these from Commands.
3030

0 commit comments

Comments
 (0)