Quote:
Originally Posted by ratdude747
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)".