|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
|||||
|
|||||
|
Re: Programming Puzzle
Not to my knowledge. Here is the manpage for the basic PID VI we're given. Also, none other more advanced PID VIs seem to indicate that this functionality exists, either.
Bummer, because it'd be nice... Quote:
edit: here's a VI I quickly wrote up that demonstrates both of the methods Ether wrote up: zero_cross_test.vi Last edited by plnyyanks : 21-08-2012 at 21:49. Reason: responded to next post |
|
#17
|
|||||
|
|||||
|
Re: Programming Puzzle
You could also try using a PID to minimize error, rather than reach a setpoint.
IE: Rather than My setpoint is currently 4.5 my process variable is at .1 Say My setpoint is always 0, currently my process variable is -.6 (where -.6 is the circular difference between your 'goal' and your 'actual') then when your goal changes, the frame of reference you use to calculate your process variable changes, and your (probably only proportional gain?) controller will move your motor. |
|
#18
|
||||||
|
||||||
|
Re: Programming Puzzle
I wrote a vi called HeadingWrap.vi that we've used for autonomous. You can use it to convert an angle outside of +/-180 degrees to be within the +/-180 degree range. You can use it to do what you're trying to do.
This is how it's used: Calculate your angle error into your PID (i.e. desired - actual) and feed the result into HeadingWrap.vi. The output will come out within the +/-180 range and will give you the shortest turn to your desired angle. You can find it here: http://www.chiefdelphi.com/media/papers/2553 in the sample robot code zip file. Here's more or less how it works: Let's say you command your canon to 355 degrees and it overshoots so your sensor reads 3 degrees. For your next PID calculation, your error is 355 - 3 = 352 degrees. This is the problem you've had: it wants to command your canon to do another loop. To solve it, check your error to be within +/- 180. If not, subtract (or add, if the error is negative) 360 degrees. For this case, we subtract 360 so: 352 - 360 = -8 degrees. This will get your canon to head in the right direction by the correct number of degrees. Here's the basic algorithm: Code:
Error = desired - actual;
while (abs(Error) > 180)
{
if (Error > 180)
Error -= 360;
else
Error += 360;
}
EDIT: For your application, the while loop is unnecessary. We use it in autonomous since we allow the heading integrator to grow past 360 in both directions (i.e. we don't wrap the heading integral - we just take care of the wrap on the error term as stated above). Last edited by Chris Hibner : 22-08-2012 at 09:01. |
|
#19
|
||||||
|
||||||
|
Re: Programming Puzzle
While my above post solves your math issue, you may have a bigger problem.
A continuous pot has a gap in which the wiper will not contact the resister band (right where it will flip from 5V to 0V). When that happens, the A/D pin will be at a floating voltage. You may get weird voltage readings in that band depending on how the A/D pin is "wired". Is there a pull-up or pull-down resistor on your board? If not, you should definitely add one so when the wiper loses contact, you have a defined voltage that is either 0V or 5V (not somewhere in between). |
|
#20
|
||||
|
||||
|
Re: Programming Puzzle
Quote:
Code:
error -= 360*floor(0.5+error/360); |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|