Thread: PID crossing 0
View Single Post
  #11   Spotlight this post!  
Unread 26-05-2011, 16:20
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
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: PID crossing 0

Quote:
Originally Posted by ratdude747 View Post
i see... but what exactly do you mean by "floor"? never seen that math operation before.

edit- i see now... its the lowest integer function.

Yes, it's part of the standard C library.


For LabVIEW users, the calculation "angle_error -= 360*floor(0.5+angle_error/360)" can be coded as shown in the attachments to this post.


Notice that it doesn't matter if your angles are from 0 to 360 or from -180 to +180. All that matters is that they are both zeroed at the same point and that they are both measured in the same direction.


For example, let's re-do the Example2 calculation in this post, but with the calculated steering angle being from -180 degrees to +180 degrees instead of 0 to 360 degrees, to show that the exact same code can be used to give the proper result


So, your steering angle encoder ("measured_angle") reads 0 to 360 degrees clockwise, with zero being "straight ahead".

And your calculated desired steering angle ("target_angle") is -180 to +180 degrees, again with 0 being straight ahead.



Example 2:


measured_angle = 4 degrees

target_angle = -6 degrees (instead of +354 degrees)

angle_error = target_angle - measured_angle = -6 - 4 = -10 degrees

angle_error -= 360*floor(0.5+angle_error/360) = -10 degrees (you still get -10 degrees, which is what you want)







Reply With Quote