Skip to content

Add a safe mode to the robot #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/com/teamcautionrobotics/robot2018/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ public void robotInit() {
SmartDashboard.putData("Angulator PID", harvester.pidController);

missionSelector = new MissionSelector(commandFactory);

// Remove the true to have this not default to safe mode; it will save the setting instead
if (!SmartDashboard.getKeys().contains("normal mode")) {
SmartDashboard.putBoolean("normal mode", true);
}
}

@Override
Expand Down Expand Up @@ -219,6 +224,11 @@ public void autonomousPeriodic() {

@Override
public void teleopPeriodic() {
// Safe mode will disable lift, run drive at half speed, and reduce the power of the
// harvester
boolean normalModeArmed = SmartDashboard.getBoolean("normal mode", false);
boolean safeModeEnabled = !(normalModeArmed && driverRight.getRawButton(2));

// TODO(Schuyler): fix this
// SmartDashboard.putString("selected mission", autoModeChooser.getSelected().getName());

Expand All @@ -233,6 +243,12 @@ public void teleopPeriodic() {
double rightPower = forwardCommand - turnCommand;

double speedLimit = speedLimitFromElevatorHeight(elevator.getCurrentHeight());

// Speed limiter
if (safeModeEnabled) {
speedLimit *= 0.4;
}

leftPower *= speedLimit;
rightPower *= speedLimit;

Expand All @@ -253,6 +269,9 @@ public void teleopPeriodic() {
if (driverRight.getTrigger()) {
grabberPower = 0.5;
}
if (safeModeEnabled) {
grabberPower *= 0.5;
}
} else {
int dPadAngle = manipulator.getPOV();
switch (dPadAngle) {
Expand Down Expand Up @@ -330,17 +349,25 @@ public void teleopPeriodic() {
// Joystick down moves the elevator up
double elevatorMoveCommand = manipulator.getAxis(Axis.RIGHT_Y);

// The driver has controls for the lift on the left joystick. These override the manipulator
elevatorMoveCommand = driverLeft.getRawButton(3) ? 1 : elevatorMoveCommand;
elevatorMoveCommand = driverLeft.getRawButton(2) ? -1 : elevatorMoveCommand;

SmartDashboard.putBoolean("Elevator manual mode enabled", elevatorPIDManualModeEnabled);
SmartDashboard.putNumber("Elevator Move Command (manip)", elevatorMoveCommand);

if (elevatorPIDManualModeEnabled) {
elevator.move(elevatorMoveCommand);
if (!safeModeEnabled) {
elevator.move(elevatorMoveCommand);
}
} else {
// Use the manipulator right joystick Y to adjust the PID controller's setpoint
double dt = this.getPeriod();
double changeInHeight = ELEVATOR_NUDGE_SPEED * elevatorMoveCommand * dt; // inches
if (elevatorMoveCommand != 0) {
elevator.setDestinationHeight(elevator.getCurrentHeight() + changeInHeight);
if (!safeModeEnabled) {
// Use the manipulator right joystick Y to adjust the PID controller's setpoint
double dt = this.getPeriod();
double changeInHeight = ELEVATOR_NUDGE_SPEED * elevatorMoveCommand * dt; // inches
if (elevatorMoveCommand != 0) {
elevator.setDestinationHeight(elevator.getCurrentHeight() + changeInHeight);
}
}
}
}
Expand Down