|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#46
|
|||
|
|||
|
Re: PID control loops - closed loop feedback
I am planning to use PID on the arm for our end of year mini-game bot
(we make a mini game w/ the robotic class (sadly only 7 students one being a moderator) split into 2 teams w/ a 2X2X3' 80 lbs robot its really cool) any ways for ours (i'm not sure if this will work) I will basically just put a gyro on the arm and compare the "wanted speed" to the real speed and then just add a bit to the PWM (dependent on how close real is to wanted) to calibrate it just move the gyro away from or closer to the joint! to get the real speed i'm just going to multiply the accel*time/looptime + previous...that should probly give me speed.. Will this work? Also i'm using the PBasic controller so i'll have to learn that a bit... do i have to keep loop time constant or not...does it really matter that mucH? This part really bugs me out because i read about everyone keeping loop times constant and what not but on the Edubot controller I just wrote the code...heck to loop time and everything worked (for our little autonomous gyro guidance thing) IF it does matter a LOT i might take a educontroller and connect it to the maincontroller so it can receive gyro inputs and then simply output the amount to add to the PWM through dig_out which plugs into dig in on the RC Also can someone explain why it matters so much (in reality ) do the loop times really vary by so much that it would greatly affect operation (i imagine if it loops so quickly it wouldn't matter...the differences would be averaged out to a menial number??) Thanks! |
|
#47
|
||||
|
||||
|
Re: PID control loops - closed loop feedback
if you are matching rotational speed then the amount of time the loop takes doenst matter
its when you are integrating it to get angles that the loop time alters the output - and even that averages out if the loop is not the same every time I wouldnt worry about the loop speed - PID loops always have some trial and error testing to get the constants right sounds like fun. |
|
#48
|
|||
|
|||
|
Re: PID control loops - closed loop feedback
Also...this is kind of a side question...if i integrate twice...wouldn't i get a 0-254 value? (from the gyro) ...that is Total V? ....i guess it wouldn't be so hard to convert to an angle given that its 150 deg/sec...but i don't really trust that so I'm thinking i'll not convert to degrees (useless anyways)...
just wondeing... |
|
#49
|
||||
|
||||
|
Re: PID control loops - closed loop feedback
Im not sure what you mean by integrating the sensor twice?
the output of a yaw rate sensor is degrees/second when you integrate its somewhat like multipling by seconds, so you end up with degrees (in units that do not directly read out in degrees, you would need a constant added in if you want actually degrees, or radians, or whatever standard unit you want but if you integrate that again? Im not sure what that gives you? degreeSeconds?! I dont know what that would be measuring? |
|
#50
|
|||
|
|||
|
Re: PID control loops - closed loop feedback
degree seconds? i thought it would give the degree angle of the arm ...like a potentiometer... (degree/seconds * seconds = degrees ) right?
btw this is the actual code it hasn't been compiled or tested yet just theory...just notepad: Code:
p2_y=armin;
targetv=armin; //just temporary...
//////get gyro input conv to 8bit
(int)gyroin10bit=Get_Analog_Value(rc_anlg_in01);
gyroval=gyroin10bit/4;
////convert gyro values to usable values....
armaccel=gyroval-127;
///integrate
realv=(armaccel+realv)/time;
time++;
//////////////
if((hicutoff+targetv)>realv>(locutoff+targetv))
{
armout=(targetv-realv)/proportion;
}
pwm03=pwm03+armout;
but why integrate the error....i don't get this and how it works ? i read some stuff about how it is an automatic reset which doesn't quite make sense to me...... Also can someone explain the derivative...part... ![]() Last edited by Salik Syed : 25-04-2004 at 18:08. |
|
#51
|
|||
|
|||
|
Re: PID control loops - closed loop feedback
OKay...nevermind...i figured out what it does......now for the derivative ....the longer an error has stayed the more it adds...
![]() |
|
#52
|
||||
|
||||
|
Re: PID control loops - closed loop feedback
I think I understand your statements now.
when you intergrate the sensor output you are changing the 'signal' from degrees/second to degrees so now you can create an error signal by subtracting that from what the operator is commanding (desired angle) and do a PID feedback with intergral, proprotional and deriviative (or differentail) components so you would not really be intergating the sensor single twice - you would be integrating it once to get the angle then if you wanted tight feedback you could integrate the error signal over time. |
|
#53
|
|||
|
|||
|
Re: PID control loops - closed loop feedback
yeah...i know i'm not gonna integrate twice...just once..(see code) but i was just wondering...
I've tweaked the code to include an integral term, now i'm wondering how to do the derivative...its hard because i'm trying to read ahead in the textbook...(we haven't learned derivitves yet!) ..... and then apply it to this....all the articles I find on PID are a bit too complex... btw... we also did the whole tape interpolation thing for autonomous..we didn't use it because we didn't need the precision, we used a gyro to track heading, then tape for distance, we didn't have a legal gyro at times so i also implemented a timer that would measure time between the tape being seen and calculate dist to a much finer degree then 1/6 wheel circumfrence...alot like what u did... Last edited by Salik Syed : 25-04-2004 at 20:46. |
|
#54
|
||||
|
||||
|
Re: PID control loops - closed loop feedback
derivative is easy. its the delta or change since the last loop
create a new variable to keep track of the 'last_error' signal - then compair the current error signal to the last one - thats the derivate - you are interested in how fast the error signal is changing which can be due to the driver making a sudden change, or the bot moving suddenly. Last edited by KenWittlief : 26-04-2004 at 09:08. |
|
#55
|
|||
|
|||
|
Re: PID control loops - closed loop feedback
okay....i get it now
Thanks! |
|
#56
|
|||
|
|||
|
Re: PID control loops - closed loop feedback
Heres our PID code so far...the constants u multiply by really have to be tweaked once the actual robot is built
! ... P+I+D should not be over 127 or under -127...so i'll have to definitely calibrate it A LOT IF( any one spots obvious mistakes ...(not like syntax error type mistakes) ){please tell me...} Code:
////get joystick input///////////////
p2_y=armin;
targetv=armin; //just temporary...
//////get gyro input conv to 8bit
(int)gyroin10bit=Get_Analog_Value(rc_anlg_in01);
gyroval=gyroin10bit/4;
////convert gyro values to usable values....
armaccel=gyroval-127;
///integrate
realv=(armaccel+realv)/time;
//////////////
//////////Calculate the proportional.....
if((hicutoff+targetv)>realv>(locutoff+targetv))
{
armout=(targetv-realv)*proportion; /// as the real gets closer to target pwm addition is lowered...
/// this is basically "Gain"
}
/////////////calculate the integral of the error....
error=realv-targetv;
errorint=(error+errorint/time)*intprop;
/////calculate the derivative of the error;
derivative=(lasterror-error)*devprop;
///////////////////Output;////////////////////
if(tripped!=1)
{
pwm03=armout+errorint+derivative+127;
}
///////update time
time++;
////update error
lasterror=error;
////motor heating control....
///basically take current sensor values and make sure not too much
//is being drawn or else it will let down on the motors
(int)current=(Get_Analog_Value(rc_anlg_in02))/4;
///+127 = 100 amps...... so + or - 50 = 40 AMPS!!! I set it to "trip" at 27 amps
/// since we have 30 amps breakers ... so that you don't trip the actual breaker.!
//// divide current by .79 to get anlgreading-127~! so 100/.79+127=254!
if(current>161 || <93)
{
pwm03=p2_y;
tripped=1;
}
Am I doing the Proportional correctly? It says Gain= Input / Ouput ... but in stead i just compare the target to the actual...thats not exactly the same but should give me the result i'm looking for (to lower speed when target is closer to actual)?? Correct me if i'm wrong please.... |
|
#57
|
||||
|
||||
|
Re: PID control loops - closed loop feedback
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|