Thread: PID crossing 0
View Single Post
  Spotlight this post!  
Unread 26-05-2011, 09:28
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,100
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
Is there an alternative to a PID that will let me cross 0 or a way to make the PID cross 0? or do i need to write my own algorithm to render that?
If you want want to use the WPI library PIDs, you can create "setpoint" and "process_variable" inputs for them as follows (assuming angles in degrees):

angle_error = target_angle - measured_angle;
angle_error -= 360*floor(0.5+angle_error/360);


then:

setpoint = angle_error;
process_variable = 0;


OR

setpoint = 0;
process_variable = -angle_error;



The disadvantage of the first approach is that the Derivative term will be disabled since the WPI Lib PIDs only look at the derivative of the process_variable.

The disadvantage of the second approach is that, although the Derivative term will be active, it will respond to changes in BOTH the measured_angle as well as the target_angle, so be careful how you adjust it.

Notice that the first two lines of code above (calculating the angle_error) calculate the shortest angle distance to the target. You need extra conditional logic only if you want to change the sign of wheel speed. See the discussion here.




Last edited by Ether : 26-05-2011 at 09:44.
Reply With Quote