Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   PID Loops (http://www.chiefdelphi.com/forums/showthread.php?t=93498)

Chris27 13-03-2011 14:43

Re: PID Loops
 
Quote:

Originally Posted by theNerd (Post 1038198)
when PID loops are used?

An example of a use of PID is our autonomous mode. We want to be able to drive out exactly x inches to our rack in a perfectly straight line to put us in a position to score a tube on the high rack. This isn't so straightforward as a 150lb robot has a lot of momentum and it is easy to overshoot a target distance (and crash into the wall). We can record the distance the robot has traveled by putting an encoder on the right side of the drive train. Using PID, we set the set point to x and read the encoder to get the current position. With our gains set correctly, we arrive at distance x rather smoothly.

However, we also want to drive in a perfectly straight line. If, say there is more friction on one side of the drive train, this will cause the robot to drive in an arc. You can add a gyro to the bot, use PID on it with the set point of whatever heading is defined to be "straight". Add this correction to the speed of the left wheel motors and you are 80% of the way to having a perfect one tube autonomous mode.

PriyankP 13-03-2011 15:21

Re: PID Loops
 
I've been reading this thread and could someone please post an example code with P, I and D implemented to control something? I saw the LabView code, but I never learned labview, so could someone please post a C++/Java example?! :)

EDIT: I did implement P loop to control our arm this year, but only for presets. Is it possible to implement PID loop for manual control? If yes, how so?

archaopteryx 13-03-2011 15:39

Re: PID Loops
 
I'm not a mathematician, but couldn't
Quote:

Pedal = K * Error
, where K is a constant, simply do without K? If pedal and error have a direct correlation, why can't you just say that pedal = error and leave it at that?

Chris27 13-03-2011 15:44

Re: PID Loops
 
Quote:

Originally Posted by archaopteryx (Post 1038616)
I'm not a mathematician, but couldn't , where K is a constant, simply do without K? If pedal and error have a direct correlation, why can't you just say that pedal = error and leave it at that?


If you are trying to move your car at 50 mph and currently, the error from this target is +10 mph, does it make sense to push the pedal down at 10 mph? A correlation does not mean an equivalent 1 to 1 relation. Another example is if you are trying to drive your robot 5 feet forward and the current error is 4 inches. Does it make sense to tell the motors to drive at 4 inches? Built into the k value is unit conversion among other things.

Ether 13-03-2011 15:44

Re: PID Loops
 
Quote:

Originally Posted by PriyankP (Post 1038608)
EDIT: I did implement P loop to control our arm this year, but only for presets. Is it possible to implement PID loop for manual control? If yes, how so?

Instead of preset, make the setpoint manually adjustable (like the output of a joystick axis) .



PriyankP 13-03-2011 15:53

Re: PID Loops
 
Quote:

Originally Posted by Ether (Post 1038621)
Instead of preset, make the setpoint manually adjustable (like the output of a joystick axis) .


So it would be something like target = currentPotValue + (Yaxis * 5) right?

I'm multiplying by 5 because the Yaxis is only between -1 and 1 so one would want to have a target that is significantly different compared to the currentPotValue

Ether 13-03-2011 15:54

Re: PID Loops
 
Quote:

Originally Posted by archaopteryx (Post 1038616)
I'm not a mathematician, but couldn't , where K is a constant, simply do without K? If pedal and error have a direct correlation, why can't you just say that pedal = error and leave it at that?

If you are trying to control position, then the error will be in inches (or feet or meters or whatever). In response to this error, you want to choose the appropriate command to your motors, which will be a voltage command... which roughly corresponds to a speed command. So the K is a scaling and gain factor to convert the error to an appropriate motor voltage (speed) command.

On the other hand, suppose you are trying to control motor speed. You want to go 2000 rpm and you are presently going 1900 rpm. So the error is 100 rpm. Would it make sense to give the motor a voltage command which is roughly equal to 100 rpm?



Chris27 13-03-2011 15:55

Re: PID Loops
 
Quote:

Originally Posted by PriyankP (Post 1038608)
EDIT: I did implement P loop to control our arm this year, but only for presets. Is it possible to implement PID loop for manual control? If yes, how so?

If a system of your robot has mechanical limits (e.g. an arm) you may want to use PID (or even just P) to not smash into those limits. I can also see PID used for speed control like in Chris's example.

Ether 13-03-2011 16:02

Re: PID Loops
 
Quote:

Originally Posted by PriyankP (Post 1038625)
So it would be something like target = currentPotValue + (Yaxis * 5) right?

Yaxis is your setpoint and (m*currentPotValue+b) is your process variable.

Adjust the gain "m" and the offset "b" so that your process variable corresponds to your Yaxis output.

Then,

error = setpoint - process_variable;

motor_voltage_command = Kp*error;

Kp is your proportional gain which you tune for the desired response.



PriyankP 13-03-2011 16:14

Re: PID Loops
 
Quote:

Originally Posted by Ether (Post 1038631)
Yaxis is your setpoint and (m*currentPotValue+b) is your process variable.

Adjust the gain "m" and the offset "b" so that your process variable corresponds to your Yaxis output.

Then,

error = setpoint - process_variable;

motor_voltage_command = Kp*error;

Kp is your proportional gain which you tune for the desired response.


So (m*(currentPotValue+b)) should have range of -1 to 1? or it doesn't matter because Kp takes care of that?

HarveyAce 13-03-2011 16:28

Re: PID Loops
 
Quote:

Originally Posted by Ether (Post 1038551)
What is your total gear ratio from motor to arm (gearbox plus external gears or sprockets or pulleys etc).


We are currently running two denso window motors in tandem to power the joint with a surgical tubing counter balance. I'm just curious because when we ram the fp, it was WAY too fast and couldn't hold the weight in one position, but I've seen teams do it with much success.

Ether 13-03-2011 16:52

Re: PID Loops
 
Quote:

Originally Posted by PriyankP (Post 1038640)
So (m*(currentPotValue+b)) should have range of -1 to 1? or it doesn't matter because Kp takes care of that?

Kp does not take care of that. Kp is the tuning constant, and is applied to the error. Take another look.



Ether 13-03-2011 16:53

Re: PID Loops
 
Quote:

Originally Posted by HarveyAce (Post 1038652)
I'm just curious because when we ram the fp,

when you "ran the fp" how did you run it? i.e. what total gear ratio did you use?



Ether 13-03-2011 16:55

Re: PID Loops
 
Quote:

Originally Posted by HarveyAce (Post 1038652)
We are currently running two denso window motors in tandem to power the joint with a surgical tubing counter balance.

In an earlier post, you mentioned 30-35 ft-lbs of torque on the arm. Was that with or without the surgical tubing in place?



PriyankP 13-03-2011 17:35

Re: PID Loops
 
Quote:

Originally Posted by Ether (Post 1038666)
Kp does not take care of that. Kp is the tuning constant, and is applied to the error. Take another look.



So (m*currentPotValue+b) doesn't have to be within -1 to +1? And what exactly does it, the process variable, do?


All times are GMT -5. The time now is 23:40.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi