I am trying to implement a switch statement in auto mode. The code goes to the first statement then never goes to the second statement. Any suggestions?
Code:
#include "WPILib.h"
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot;
Talon motor;
Joystick stick;
Encoder en;
PIDController pid;
int step;
public:
RobotDemo(void):
myRobot(7,8),
motor (2),
stick(1),
en(1,2, true,Encoder::k4X),
pid(.1, 0, .003, &en, &motor)
{
myRobot.SetExpiration(0.1);
en.Start();
step = 1;
}
void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
switch (step){
case 1:
pid.Enable();
pid.SetTolerance(.1);
pid.SetOutputRange(-.5, .5);
pid.SetSetpoint(497);
if(pid.OnTarget()){
step++;
}
break;
case 2:
pid.Enable();
pid.SetTolerance(.1);
pid.SetOutputRange(-.25, .25);
pid.SetSetpoint(800);
if(pid.OnTarget()){
step++;
}
break;
default:
break;
}
}
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(false);
while (IsOperatorControl() && IsEnabled())
{
Wait(0.005);
}
}
void Test() {
}
};
START_ROBOT_CLASS(RobotDemo);