about PID control problem
ggg558877
Posts: 40
Hi everyone
now i have some problem about PID control
I'm trying to do is have an rc car go toward a heading if i want to go straight on heading angle = 0
so i set the setpoint = 0 and input is Current heading angle and get the output
my qusetion is the output value is the PWM pulse width to control the servo?
thanks
now i have some problem about PID control
I'm trying to do is have an rc car go toward a heading if i want to go straight on heading angle = 0
so i set the setpoint = 0 and input is Current heading angle and get the output
my qusetion is the output value is the PWM pulse width to control the servo?
thanks
Comments
What are you using for feedback?
Do you have a digital compass?
Or do you just want to set the servo to drive the car straight?
The attached file looks like a template to be used with other code. You need a parent object to control the output and monitor sensors.
Depending on what you want to do, you may not need the PID object at all. Very few of my projects require PID (and I have lots of Propeller projects).
I think if you describe what you want to do, and what equipment you're using, we'll be better able to suggest where to look for information you may need.
in my project i have use compass to get heading angle and gps to navigation
and if i want go straight on heading angle = 0 maybe it can offset to heading angle = 30
and I want to use PID let my car Correction on heading angle = 0
and i use PID.spin calculated the PID output
but i don't certain know is the output value is use in PWM pulse width to control the servo or ?
Can you program the car to move forward and in a circle? If not, put the compass, GPS and PID aside and develop a simple program to drive the car.
One of the first tasks I try to accomplish with a new robot is to get to drive in a figure 8. There's a thread in the robot forum where forum members post videos of there robot performing a figure 8.
Once I figured out how to control the robot enough to drive a figure 8, I start adding sensors and making the program more complicated. (Here's a figure 8 using a compass to sense when the robot should change directions and stop.)
You still haven't given us information about the car you want to control. I assume it uses a servo to steer?
What kind of Propeller board do you have?
If you have a QuickStart board, you can try out my QuickStart servo tester. Post #15 of that thread has very simple servo demo. It may help you learn to control a servo if you don't already know how.
I had a target encoder value I wanted to hit, and I used PID to make it work. The PID objects in OBEX didn't work correctly, so I had to improve them to make them work as intended.
You have a compass, which is the current point, the set point is your desired heading. The trick is the servo. I was using a servo in my experiment too.
You need to limit the bandwidth of the PID algorithm so your wheels aren't going bang-bang against the stops.
I chose +-200 counts from the center position (1500). You can see in the code where I did this. I just take 1500 and add the value returned from the PID algorithm to get a velocity value. In your case the PID algorithm will tell the car to turn left or right, and slowly bring it back to center once you're on heading.
Very simply the output of the PID consists of three parts added up. One is proportional to the error, that is it equals the current error multiplied by a number (called the gain) the next part is the integral which adds the current error to an accumulator, this is multiplied by another gain and added to the output. Finally the derivative part is proportional to the rate of change in the error, this too has a gain.
So the output depends on the way you measure the current system state as well as these gain terms. Bigger gains make this number bigger, different sensors would change it too.
So most likely you will need to scale the output, offset it and probably limit it. You might get +/- 1000 out of the system but you might want to convert that to a different range you can send to your servos, that depends on your servo driver.
I would also advise just putting the I and D gains to zero to start with and begin with a small P gain. Play with it and look at the very simple maths and the numbers it is generating and you will start to get it and as mentioned you may want to slow down the rate the loop repeats.
Graham
Graham
I spent plenty of time looking at data streaming from the serial to not only tune the parameters, but adjust the algorithm.
You need to implement time decay without requiring the algorithm be called synchronously, and this turns out to be a rather simple fix, so I did it.
Graham
It may even be helpful, especially the table of coefficients on page 8, although it is geared towards relatively long period heat control.
It may be that instead of using integral alone to provide "reset", that you need to implement a table of responses known to be contextually appropriate, and use PID to finesses errors.
now i have understand how to use PID in my project
thanks