Cleaned up SampleRobot template and added warning about disabling motor safety (#766)

This commit is contained in:
Tyler Veness
2017-12-04 20:28:31 -08:00
committed by Peter Johnson
parent 64bfdc1a69
commit 350b741adc
2 changed files with 33 additions and 20 deletions

View File

@@ -61,27 +61,30 @@ public:
// "Auto Selector", kAutoNameDefault);
std::cout << "Auto selected: " << autoSelected << std::endl;
// MotorSafety improves safety when motors are updated in loops
// but is disabled here because motor updates are not looped in
// this autonomous mode.
m_robotDrive.SetSafetyEnabled(false);
if (autoSelected == kAutoNameCustom) {
// Custom Auto goes here
std::cout << "Running custom Autonomous" << std::endl;
m_robotDrive.SetSafetyEnabled(false);
// spin at half speed for two seconds
// Spin at half speed for two seconds
m_robotDrive.ArcadeDrive(0.0, 0.5);
frc::Wait(2.0);
// stop robot
// Stop robot
m_robotDrive.ArcadeDrive(0.0, 0.0);
} else {
// Default Auto goes here
std::cout << "Running default Autonomous" << std::endl;
m_robotDrive.SetSafetyEnabled(false);
// drive forwards at half speed for two seconds
// Drive forwards at half speed for two seconds
m_robotDrive.ArcadeDrive(-0.5, 0.0);
frc::Wait(2.0);
// stop robot
// Stop robot
m_robotDrive.ArcadeDrive(0.0, 0.0);
}
}
@@ -92,11 +95,11 @@ public:
void OperatorControl() override {
m_robotDrive.SetSafetyEnabled(true);
while (IsOperatorControl() && IsEnabled()) {
// drive with arcade style (use right stick)
// Drive with arcade style (use right stick)
m_robotDrive.ArcadeDrive(
m_stick.GetY(), m_stick.GetX());
-m_stick.GetY(), m_stick.GetX());
// wait for a motor update time
// The motors will be updated every 5ms
frc::Wait(0.005);
}
}

View File

@@ -96,19 +96,28 @@ public class Robot extends SampleRobot {
// defaultAuto);
System.out.println("Auto selected: " + autoSelected);
// MotorSafety improves safety when motors are updated in loops
// but is disabled here because motor updates are not looped in
// this autonomous mode.
m_robotDrive.setSafetyEnabled(false);
switch (autoSelected) {
case kCustomAuto:
m_robotDrive.setSafetyEnabled(false);
m_robotDrive.arcadeDrive(0.0, 0.5); // spin at half speed
Timer.delay(2.0); // for 2 seconds
m_robotDrive.arcadeDrive(0.0, 0.0); // stop robot
// Spin at half speed for two seconds
m_robotDrive.arcadeDrive(0.0, 0.5);
Timer.delay(2.0);
// Stop robot
m_robotDrive.arcadeDrive(0.0, 0.0);
break;
case kDefaultAuto:
default:
m_robotDrive.setSafetyEnabled(false);
m_robotDrive.arcadeDrive(-0.5, 0.0); // drive forwards
Timer.delay(2.0); // for 2 seconds
m_robotDrive.arcadeDrive(0.0, 0.0); // stop robot
// Drive forwards for two seconds
m_robotDrive.arcadeDrive(-0.5, 0.0);
Timer.delay(2.0);
// Stop robot
m_robotDrive.arcadeDrive(0.0, 0.0);
break;
}
}
@@ -130,9 +139,10 @@ public class Robot extends SampleRobot {
public void operatorControl() {
m_robotDrive.setSafetyEnabled(true);
while (isOperatorControl() && isEnabled()) {
// drive arcade style
m_robotDrive.arcadeDrive(m_stick.getX(), m_stick.getY());
// wait for a motor update time
// Drive arcade style
m_robotDrive.arcadeDrive(-m_stick.getY(), m_stick.getX());
// The motors will be updated every 5ms
Timer.delay(0.005);
}
}