LabVIEW PID for angles

Is there a LabVIEW PID vi that has the built-in smarts
to generate the proper error angle (magnitude and sign)
if given a joystick command (e.g atan2(Xj,-Yj)
(180/pi)) as the setpoint
and the gyro angle as the process variable?

**

I don’t fully understand what your question says, but I think I can figure out why you’re asking it.

Would it be sufficient for your purpose if there were a function that took two angles and added a multiple of 360 degrees to the first angle so that it was within 180 degrees of the second one?

Or maybe you want to subtract two angles and modify the difference by adding a multiple of 360 degrees so that it was within the range -180 to +180?

I should clarify things a bit.

I am asking if LabVIEW has a PID designed to handle angular process_variable and setpoint inputs directly, without having to do something like this externally:


angle_error = joystick_command - gyro_angle;
while(angle_error>180)angle_error-=360;
while(angle_error<-180)angle_error+=360;
setpoint = gyro_angle + angle_error;

… and then feed the fabricated setpoint and the gyro_angle into the PID’s setpoint and process_variable inputs, respectively.

Not that this is difficult to do, just wondering if there is a PID with this built-in capability.

**

LabVIEW PID functions don’t care whether the variables represent angles, speeds, temperatures, etc. They’re just numbers.

It seems that the specific application you have in mind assumes motor control of a mechanism capable of continuous rotation and negligible time for changing direction. That’s not the only kind of mechanism one might want to control based on angle. Since each application is going to have its own requirements, a built-in function would have to have a lot of options, and it still might not accommodate some needs.

I think you’re trying to ask whether there is a built-in function that combines PID with the specific way you want angular errors to be computed. You’re the one who knows how you want it to work, so I don’t think it’s any great burden to have you implement that part of it yourself.

Just to confirm, no. If there are special conditions with the input or output of the PID, you add those to the front or back.

By the way, the integer divide is the LV way to do modulo math.

Greg McKaskle

The pre-processing shown above is of course a general solution to a wide class of angular position-control applications, of which FRC robot rotational orientation is but one example. Unlike linear position control or limited-rotation angular position control, control of angular rotational position in continuous-rotation situations requires that the wrap-around be considered.

There is a lot of interest here on CD about using gyro angular position to control robot orientation. A continuous-rotation wrapper around the LabVIEW PID might for some folks be a helpful addition to the WPI Library next year.

**

OK, thanks Greg.

By the way, the integer divide is the LV way to do modulo math.

Yeah, I gave some passing thought to that but didn’t spend the time to-rework it to get the same result with modulo.

**

OK, I came back and took a closer look at this. The mod function is not the way to do it. The floor function gives the desired result:

*
*angle_error = joystick_command - gyro_angle;
angle_error -= 360*floor(0.5+angle_error/360);
setpoint = gyro_angle + angle_error;

If your compiler supports the REMAINDER function “x REM y” per IEC 60559 (mine does not so I have not tested this) as specified on Page 235 Section 7.12.10.2 of ISO/IEC 9899:TC3, then I believe the following should work:

*
*angle_error = remainder(angle_error,360);

The above can be done in LabVIEW as shown in either of the two attached screenshots.

**

angle_error correction floor.png
angle_error correction.png


angle_error correction floor.png
angle_error correction.png