![]() |
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" |
Re: Off Season Programming Question: Switch Statements
Autonomous only gets called once, so the switch statement only gets executed once. You need to add a loop inside Autonomous not unlike the loop you have in OperatorControl.
|
Re: Off Season Programming Question: Switch Statements
Once I add the while loop will the method I am using for switching between case statements work?
Code:
void Autonomous(void) |
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){ |
Re: Off Season Programming Question: Switch Statements
Quote:
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. |
Re: Off Season Programming Question: Switch Statements
Quote:
|
Re: Off Season Programming Question: Switch Statements
Quote:
Yes. I figured out the problem and I'm trying to think of a way to fix it. Code:
case 2:EDIT: I just put the pid.OnTarget(); on the smart dashboard; it never changes to true. I cant figure out why. |
Re: Off Season Programming Question: Switch Statements
Quote:
|
Re: Off Season Programming Question: Switch Statements
Quote:
|
Re: Off Season Programming Question: Switch Statements
Quote:
Edit, I see that Tolerance is a percentage, so your answer must be above 496.5031 to have onTarget return true. Re-edit: the percentage is a fraction of the range defined in SetInputRange(), which you have never called, so it defaults to zero. I suggest using SetAbsoluteTolerance() with a value of 2.0 or greater. |
Re: Off Season Programming Question: Switch Statements
That fixed it! Thanks for the help one last question. Shouldn't the input to .SetAbsoluteTolerance() be something like .4 instead of 4? I thought in the code it converted it to a percentage.
|
Re: Off Season Programming Question: Switch Statements
SetAbsoluteTolerance() bypasses the percentage calculation, so that you specify the tolerance directly in terms of sensor output. SetTolerance() and SetPercentTolerance() are functionally equivalent and set the tolerance to a percentage of the range specified in the latest call to SetOutputRange(). Since you never called SetOutputRange, my reading of the source code makes me believe that these default to zero, so SetTolerance() will always produce a zero tolerance if SetOutputRange() has not been called.
|
| All times are GMT -5. The time now is 10:50 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi