View Single Post
  Spotlight this post!  
Unread 12-02-2011, 23:58
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,004
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: LabVIEW PID for angles


Quote:
Originally Posted by Ether View Post
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:

Code:

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:

Code:

angle_error = remainder(angle_error,360);

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


Attached Thumbnails
Click image for larger version

Name:	angle_error correction floor.png
Views:	285
Size:	2.5 KB
ID:	10083  Click image for larger version

Name:	angle_error correction.png
Views:	265
Size:	2.0 KB
ID:	10084  
Reply With Quote