Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I'm trying to stabilize a robot with a servo motor attached to two wheels of a robot. I already built the system as following:

  • Apply Kalman filter to gyrometer/accelerometer output
  • Calculate a roll angle (accurate one)

Now I use these results and feed it back to incremental PID controller. My problem is that the PID controller output is very high or some times is negative, I want to scale it to a proper servo angle, for example:

The PID output is 5000, but the servo understands "commands" between 1 & 180 degrees. So how to scale the output via a scientific method to make sure that the motor receives the right commands from PID?

My target is when the robot wheel goes right, the motor should make it in the opposite direction and so on.

Update #1: The error of PID output depends on the refrence roll angle i want to be at and the cureent roll angle measured from IMU (that depends on the the accelerometer & gyro meter ) ,

the input to the servo is the servo angle position which lies between 1 degree to 180 degree

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

To do this "scientifically", you need to decide exactly what physical quantity the output of your PID controller represents, and in exactly what units. Does it represent course error, heading error, steering angle or something else?

Also, what physical quantity does the input signal to the servo represent? Steering angle?

If both quantities represent, say, steering angle, then you're mostly done. You just need to apply a scale factor to convert the units.

But if they represent different physical quantities to begin with, you need to figure out a way to translate from one to the other. This is called "kinematics" (or sometimes "reverse kinematics", depending on how your control algorithm works). It's basically a mathematical description of how the various physical quantities (mainly angles and distances, but could also include forces, masses and velocities) are related in your system.

share|improve this answer
    
Thanks for replying, thr error of PID output depends on the refrence roll angle i want to be at and the cureent roll angle measured from IMU (that depends on the the accelerometer & gyro meter ) , the input to the servo is the servo angle position which lies between 1 degree to 180 degree –  user44231 Jun 8 at 14:40
    
Also is there a something to read about this "kinematics" ? –  user44231 Jun 8 at 14:46
    
What is the physical relationship between "servo angle" and "roll angle"? –  Dave Tweed Jun 8 at 14:59
    
There is no relation , roll angle comes from the IMU , the servo should tune himself till the reading of IMU becomes same as the refrence roll angle .. –  user44231 Jun 8 at 15:02
    
There has to be some relationship -- you obviously expect the servo to have some effect on the roll angle; otherwise, you wouldn't have a closed-loop system in the first place. Furthermore, you asked for a "scientific" way to figure out the scaling required. But if you're not interested in working out the physical details, any attempt at a "scientific" approach is going to be meaningless. Even if you're building an adaptive system, you still need to have some idea of what the physical relationships are and what the required ranges of "adaptation parameters" are. –  Dave Tweed Jun 8 at 16:20
add comment

Using an Anti Windup compensator would be helpful, it applies a feedback loop to the output of the PID to prevent it from going beyond the limits, enter image description here

Just adjust the gains by hit and trial, and in the saturation block put the limits 1 and 180.

share|improve this answer
    
Hit-and-miss, trial-and-error, whatever. The problem is that the question isn't about tuning the PID algorithm, it's about scaling the results to feed the servo. –  Dave Tweed Jun 8 at 13:04
    
the "hit and trial" part was just to tune the anti-windup compensator, it does exactly what you're asking for i.e., mapping the output of PID which could be any real number to the range of angles(1 to 180) you want to give as input to your plant(the circuit or code driving the servo in this case), –  Salman Azmat Jun 8 at 14:57
    
anti-windup compensator is just another feedback loop in your main loop, this loop just tries to keep the output of your PID in the range of 1-180,, isn't that what you're asking for? I didn't tell you to tune the PID, it's the blocks after the PID, –  Salman Azmat Jun 8 at 15:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.