Thread: PID crossing 0
View Single Post
  #9   Spotlight this post!  
Unread 26-05-2011, 15:47
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
if what i am reading is correct, then:
i can use target-measured=setpoint; process =0
No. You left out the line "angle_error -= 360*floor(0.5+angle_error/360)"

If you leave that line out, you will get the following:


Example 1:

measured_angle = 359 degrees

target_angle = 2 degrees

angle_error = target_angle - measured_angle = 2 - 359 = -357 degrees


setpoint = angle_error = -357 degrees

process_variable = 0 degrees



In other words, the PID will try to rotate the steering counter-clockwise 357 degrees, which is NOT what you want.


Example 2:


measured_angle = 4 degrees

target_angle = 354 degrees

angle_error = target_angle - measured_angle = 354 - 4 = 350 degrees


setpoint = angle_error = 350 degrees

process_variable = 0 degrees



In other words, the PID will try to rotate the steering clockwise 350 degrees, which is NOT what you want.



If you are using radians instead of degrees, then replace "angle_error -= 360*floor(0.5+angle_error/360)" with "angle_error -= 2pi*floor(0.5+angle_error/2pi)".




Reply With Quote