Go to Post Woody, If there is any chance your reading this ... you've changed my life. - Gope [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:50 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi