View previous topic :: View next topic |
Author |
Message |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
IMU - PID some question |
Posted: Fri Dec 16, 2016 6:35 am |
|
|
Hi friends,
-->I have some questions about IMU integrating with PID.
-->What is target and current ? How to associate with Kalman X,Y outputs to PID ?
-->Where is the deltaT in updatePid that is necessary to find integral and derivative ?
-->
-->deltaT that I used for gyroscope, can I use it for PID derivative and integral operation ? İf I cant, how to find deltaT for PID ?
-->Could you give me more detailed information ?
Thanks in advance
Giving Gyro values codes:
Code: |
if (abs(deltaR[j]) > Rth[j])
{
gyroRate[j] = deltaR[j] * 0.07 * deltaT;
} |
PID controller:
Code: |
int updatePid(int command, int targetValue, int currentValue)
{
float pidTerm = 0;
int error=0;
static int last_error=0;
error = abs(targetValue) - abs(currentValue);
pidTerm = (Kp * error) + (Kd * (error - last_error));
last_error = error;
return constrain(command + int(pidTerm), 0, 255);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Fri Dec 16, 2016 6:49 am |
|
|
First item is WHAT hardware ? You need to post mfr/make/model into of both PIC and IMU devices.
The BIG issue I have is whether the sensor is analog or digital. That makes a BIG difference as I've made/used analog gyros for 25 years.
The 'code' you show appears to be just a PD controller, not PID.
You'd also have to show us expected range of the plant, again my analog units go +-5 volts...
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
|
Posted: Fri Dec 16, 2016 6:59 am |
|
|
I'm using pic18f4550 and IMU(L3G4200D & ADXL345).
20Mhz operation.
I have got information on this website:
http://forum.arduino.cc/index.php?topic=8652.0
I have not much information about PID. I'm researching new. I learned PID in the automatic control course but not enough, not as code. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Fri Dec 16, 2016 8:59 am |
|
|
DeltaT, is just 'the change in time'. You can choose whatever units you want for it. All the factors for a PIC (the integral, differential etc.), _depend_ on your hardware. That includes what you decide to use as the unit for deltaT.
The point is that everything that happens, you measure over an interval. This is the deltaT. The larger your deltaT unit, the bigger the integral figure will be etc.. You decide in your code (based on your knowledge - which you have to calculate), of how quickly the code can actually run.
Now the shorter the deltaT, the quicker the code can react to errors. However conversely, if the interval is too short, there will be increased 'granularity' in the measurements, especially at low speed. So if (for instance) you had a system that measures the speed of a shaft based on just one pulse per rev, if the shaft was only doing 1000rpm, and you used a deltaT of 1mSec, there would often be no actual 'speed' figure available, since there hasn't been time to make a new measurement.
Getting a PID setup well is a matter of working out the capabilities of each part of the system, combining this with what you actually need to achieve, and then the capabilities of the sensors. These then are the inputs that you use the calculate the correction factors for the PID algorithm. If the motor can be allowed to respond slowly, no 'P' term at all is needed. The faster you need to respond, the bigger the P term. Long term error is handled by the I term, and overshoot can then be controlled by the D term. To actually calculate a good set of factors requires complete data - the inertia of the components, torque capabilities etc.. Since these vary, it is common to simplify and only calculate a P term, and I term, and then have the system auto adjust the 'D' if it overshoots or takes too long to correct. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Fri Dec 16, 2016 10:31 am |
|
|
First you need to get the basic hardware 'up and running'
That's a 5 volt PIC and those are 3 volt peripherals....
You'll NEED to make some changes to get basic hardware working....
1) read the 'electrical specs' of the 4550, chapter 28 I think, look a the charts...
2) read the specs for the peripherals, unless they are on some kind of 5 volt interface, you can't just 'connect/code/compile'.... this presumes you'll use the onboard I2C interface....
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
|
Posted: Fri Dec 16, 2016 11:03 am |
|
|
temtronic codes already works no problem, also Ttelmah I couldn't understand enough your writing. Now how can I get deltaT? I cant give random this value. Am I wrong? This is sampling frequency, right?
and actually for example normally deltaX = deltaX + gyroValue * 0.07 * 1/800(sampling frequency)
1/800 is datasheet information but I get this value little calculation like you see and now this is sampling frequency (0.03) in this case now is this value is my deltaT, right? I'm confused. |
|
![](templates/subSilver/images/spacer.gif) |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
|
Posted: Fri Dec 16, 2016 11:15 am |
|
|
If I want to get a derivative of the central difference, I need the parameter h is this h now deltaT?
df0/dt = (-3f0 +4f1 -f2)/2h |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Fri Dec 16, 2016 11:20 am |
|
|
Please supply the make/model of the IMU ( a 'link' ) that you've got working with the 4550. |
|
![](templates/subSilver/images/spacer.gif) |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19366
|
|
Posted: Sat Dec 17, 2016 3:01 am |
|
|
If you have two positions, then 'velocity', is the distance between these two points, over the time between the measurements. This time is the 'deltaT'.
So the equation for velocity in X, is :
(positionX1 - positionX2)/deltaT. so m/sec, or um/uSec etc.
Similarly 'acceleration' is the rate of change of velocity. So again the difference between two velocities over the time between the measurements.
deltaT, is just a way of saying 'difference between two measurement times'.
Units are down to you and your maths. So (for instance), it is much easier in most cases, to use something like a 1uSec 'tick' and then 'deltaT', can just be in integer uSeconds.
Now you need to choose your maths units to suit your hardware, and all the sensors being used. In a PID formula, you can adjust the factors used in the final equations, to suit the units you are using. So you sit down and think 'if I work in um and uSec, then all my values can be integer, which makes the maths much easier'. This is down to you choosing your units and designing your maths. |
|
![](templates/subSilver/images/spacer.gif) |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
|
Posted: Sat Dec 17, 2016 3:26 am |
|
|
When my reading is finished, I can take the value in the timer and see how many times it passes, right ? |
|
![](templates/subSilver/images/spacer.gif) |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
|
Posted: Sat Dec 17, 2016 7:51 am |
|
|
As Wikipedia codes PID:
Code: | previous_error = 0
integral = 0
start:
error = setpoint - measured_value
integral = integral + error*dt
derivative = (error - previous_error)/dt
output = Kp*error + Ki*integral + Kd*derivative
previous_error = error
wait(dt)
goto start |
dt is sampling time, If I do this, am I right?
--> I write all the codes into the loop for operation. (İncluding Gyro_Values();)
--> Like you know is including dt in Gyro_Values();
--> Just printing gyroRate[j] on LCD at 90 degree
Code: |
for (int j = 0; j<3; j++)
{
deltaR[j] = (float32)Rm[j] - Ro[j];
if (abs(deltaR[j]) > Rth[j])
{
gyroRate[j] = gyroRate[j] + deltaR[j] * 0.07;
}
}
|
--> and I get a value that I solve simple equation and find a scale-factor(dt(deltaT)).
--> Finally my new code include is this gyroRate[j] = gyroRate[j] + deltaR[j] * 0.07 * deltaT;
--> Why deltaT this value because Datasheet say this.
--> Now with this deltaT my Gyroscope works good and Kalman, too.
--> This means I can use this value with PID ?????
--> Last one, it is not necessary to use Wait(dt) in PID codes because program process already will wait because already I used this waiting to get deltaT.
Now am I right? |
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
Posted: Sat Dec 17, 2016 10:11 am |
|
|
Google "PID Without A PhD" by Tim Wescott. |
|
![](templates/subSilver/images/spacer.gif) |
Zek_De
Joined: 13 Aug 2016 Posts: 100
|
|
Posted: Fri Dec 23, 2016 1:49 pm |
|
|
Could you tell me how to get the data from the motor with encoder, no code, I need to sentences, what should I do, actually little like I know, but I need exact information.
Also why does the program work when I didn't use deltaT ? I couldn't understand exactly.
Quote: | Note: In practice, when we use this in PID control, we will skip dividing by 20 [ms] because we don't care about the exact value of velocity and we will always be multiplying the velocity by some constant (think of the divide by 20 as part of the constant) |
http://team3161.ca/resources/external/Introduction_to_PID_Control.pdf
İf I determine to deltaT, don't I have to use PID without PhD ? Also this _PID without PhD_ cause error accumulation for integral, dependent wrong deltaT (about system velocity). |
|
![](templates/subSilver/images/spacer.gif) |
newguy
Joined: 24 Jun 2004 Posts: 1903
|
|
![](templates/subSilver/images/spacer.gif) |
|