View Single Post
  #1   Spotlight this post!  
Unread 11-25-2015, 12:25 PM
tomy tomy is offline
Registered User
FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 490
tomy has a spectacular aura abouttomy has a spectacular aura about
Off Season Programming Question: Switch Statements

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);
Reply With Quote