View Single Post
  #5   Spotlight this post!  
Unread 11-25-2015, 12:55 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
Re: Off Season Programming Question: Switch Statements

Quote:
Originally Posted by GeeTwo View Post
Once you have it in a loop, you'd probably do much better not to be constantly resetting the PID parameters while it's enabled. I'd try something more like:

Code:
                    switch (step){
			case 1:
				pid.SetTolerance(.1);
				pid.SetOutputRange(-.5, .5);
				pid.SetSetpoint(497);
				pid.Enable();
                                step++;
				break;

			case 2:
				if(pid.OnTarget()){
					step++;
				}
				break;

			case 3:
                                pid.Disable();
				pid.SetTolerance(.1);
				pid.SetOutputRange(-.25, .25);
				pid.SetSetpoint(800);
				pid.Enable();
                                step++;
				break;

			case 4:
				if(pid.OnTarget()){
					step++;
				}
				break;

			default:
				break;
		}
Or, for brevity at the cost of readability, you could remove the case 4 block and move the case 4 statement up next to the case 2 statement, or remove case 4 entirely and never disable the PID in autonomous if you want to leave it on until the end; in this case, you should put the disable outside the loop.

When I ran that code it went into the first case statement got to the target then stopped. It doesn't seem to want to go into the second case statement.
Reply With Quote