View Single Post
  #4   Spotlight this post!  
Unread 11-25-2015, 12:44 PM
GeeTwo's Avatar
GeeTwo GeeTwo is offline
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,539
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Off Season Programming Question: Switch Statements

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.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 11-25-2015 at 12:47 PM.
Reply With Quote