Quote:
Originally Posted by GuyM142
What I'm trying to accomplish is a vi which turns X degrees (rather than the shortest way to a certain angle), it doesn't even matter in which direction...
I hope I've explained it well 
|
It's still not clear to me what you are trying to do. If it doesn't matter which direction, what's wrong with taking the shortest angle to get to the target?
Let's say at some point in time your gyro reads "g" degrees and you want the robot to rotate X degrees CW from that reading.
Compute target_angle = g + X at that point in time. Then use that target_angle in each iteration of your closed-loop controller as follows:
error = target_angle - gyro_reading;
error = error - 360.0*floor(0.5 + error/360.0);
Then set your SetPoint and ProcessVariable inputs to your closed-loop controller as follows:
SetPoint= error;
ProcessVariable = 0;
or
SetPoint=0;
Process_Variable= -error;
( choose one or the other depending on how your closed-loop controller handles d/dt(error) )
Once you've turned the desired X degrees, you can receive a new X command and compute a new target_angle and start the process anew. Or you can re-start the process if you receive a new X command before the previous one has completed.
Example:
The gyro reads 179 degrees and you want to rotate 10 degrees CW.
Compute target_angle = 179 + 10 = 189 degrees
first iteration:
error = 189 - 179 = 10
error = 10 - 360.0*floor(0.5 + 10/360.0) = 10
SetPoint= 10;
ProcessVariable = 0;
assume that the gyro angle increases by 2 degrees (from 179 to -179) and now look at the second iteration of the closed-loop controller:
error = 189 - (-179) = 368
error = 368 - 360.0*floor(0.5 + 368/360.0) = 8
SetPoint= 8;
ProcessVariable = 0;
... and so on until the target of 189 is reached (at which point the gyro will read -171 degrees).