Author Topic: PID problem  (Read 2147 times)

0 Members and 1 Guest are viewing this topic.

Offline TheloniusMonkTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
PID problem
« on: October 19, 2012, 11:02:13 AM »
I am trying to make a car that stops a certain distance from a wall.  I have the servo of the car connected to my microcontroller output and a ultrasonic rangefinder connected to the microcontroller input with the microcontroller running a PID algorithm.

I understand the idea of the control feedback loop and I have a general sense of how PID works.  However, from a systems perspective, I am not able to conceptually match up the inputs and outputs.  The set point (a distance from the wall) and the output of the rangefinder are both distances, so that matches up well.  I understand they get subtracted to find a error value.  This error value is fed into a PID algorithm which spits out an output that (to me at least) doesn't have a physical meaning and this value goes into the car servo which takes an input of velocity (i.e. a pulse of a certain width).

The part in bold I am struggling with conceptually.  I would appreciate if someone more experienced could point me in the right direction.  Logically, it would seem that I have to map the range of possible output values of the PID algorithm (is there such a range?) to the range of possible velocities that the car can move in.  Is that right? How can I do this?

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 270
  • Helpful? 12
Re: PID problem
« Reply #1 on: October 19, 2012, 06:26:37 PM »
Think of the output of the PID as just whatever it takes to go to your actuator and make things work - I wouldn't worry about the units - you just need to pick the gains that will make everything work out.

I would just start out with a P control and start with a number that will send the steering (however you are doing it) to the limit when you are about half way to the wall. Too high and it will oscillate. Too low and it will wander. Just try it out.

Add some "D" if necessary. But derivative control can get messy. I would avoid integral control for a line following algorithm...

edit:

Oh, wait. You don't want to maintain a distance along a wall, you want to drive straight up to a wall and stop at a particular distance?

And, the speed you are coming at the wall changes?

This could get a bit messy. And I wouldn't take a PID with a distance error as the input because you would have to change the gains as a function of speed if you want decent performance (or just set the gains for the fastest speed...)

I would just create a function of maximum speed vs. distance from your stopping point. It will go to zero at the stopping distance and the slope will be something easy to obtain as you coast. You could then just reduce your commanded motor power if you exceed the target line - you could use a P controller that is enabled the first time you cross the line.
« Last Edit: October 19, 2012, 06:36:43 PM by jkerns »
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

Offline TheloniusMonkTopic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: PID problem
« Reply #2 on: October 19, 2012, 08:45:41 PM »
Thank you for the response, jkerns!  :D

Yes you are correct in that I want to drive up to a wall and stop at a certain distance.  Let me clarify that I don't have an actual PID controller, but rather an embedded system (SunSPOT if you're wondering) that is taking the input from a rangefinder, performing ADC, and running a PID algorithm with the digital value (distance).  As such, right now the output exists only as a number that is calculated by the algorithm.  I still have to do something based on this number that will change the PWM output that goes to the servo.  I don't know what that something is yet.

Quote
I would just create a function of maximum speed vs. distance from your stopping point. It will go to zero at the stopping distance and the slope will be something easy to obtain as you coast. You could then just reduce your commanded motor power if you exceed the target line - you could use a P controller that is enabled the first time you cross the line.

I like this idea.  I'm not sure if I am understanding correctly, so please allow me to summarize in my own words?  It sounds like you're telling me I should draw up a graph of velocity as a function of distance to the wall.  Then at each distance (or distance interval), have the set point in velocity based on this graph and read the error as difference in actual velocity vs set velocity.  However, this means the set point for velocity is always changing.  Is this an issue?  And say I don't know what distance away from the wall I want to stop at yet, but rather it is something the professor inputs when the program is run.  Now I can't quite draw up the function without that prior knowledge.

Sorry for all the questions.  This is my first "lab" in my first ever controls class.  I am finding it a very rich topic and am considering making it my concentration, despite all my current confusion.

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 270
  • Helpful? 12
Re: PID problem
« Reply #3 on: October 19, 2012, 09:37:01 PM »
Thank you for the response, jkerns!  :D

Yes you are correct in that I want to drive up to a wall and stop at a certain distance.  Let me clarify that I don't have an actual PID controller, but rather an embedded system (SunSPOT if you're wondering) that is taking the input from a rangefinder, performing ADC, and running a PID algorithm with the digital value (distance).  As such, right now the output exists only as a number that is calculated by the algorithm.  I still have to do something based on this number that will change the PWM output that goes to the servo.  I don't know what that something is yet.

It's just a number. Pick gains(for starters)  that will give you a number that is in the range that whatever is controlling your servos expect.

Quote
I would just create a function of maximum speed vs. distance from your stopping point. It will go to zero at the stopping distance and the slope will be something easy to obtain as you coast. You could then just reduce your commanded motor power if you exceed the target line - you could use a P controller that is enabled the first time you cross the line.

Quote
I like this idea.  I'm not sure if I am understanding correctly, so please allow me to summarize in my own words?  It sounds like you're telling me I should draw up a graph of velocity as a function of distance to the wall Then at each distance (or distance interval), have the set point in velocity based on this graph and read the error as difference in actual velocity vs set velocity.  However, this means the set point for velocity is always changing.  Is this an issue?  And say I don't know what distance away from the wall I want to stop at yet, but rather it is something the professor inputs when the program is run.  Now I can't quite draw up the function without that prior knowledge.

Make the graph a function of the distance at which you will stop then just subtract the input stop position from your measured distance before  you calculate the error. One graph fits all.

Changing the set point is no big deal as far as the control is concerned.
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

 


Get Your Ad Here