DC motor control with PID

Accelerometers are used to sense both static (gravity) and dynamic (sudden starts/stops) acceleration - in m/s² or g.
Gyroscopes measure angular velocity, how fast something is spinning about an axis - in RPM, or degrees per second.
Accelerometer data are noisy, Gyros tend to drift; the combination (data fusing) gives usable information

See: http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=167

how high does your little car? ;D

How are things going with your project Kas?

haha97: 33cm (13")
Gibby623: I received my 3800mAh 12V Battery, the robot will (should) balance this weekend

Here is a comparaison between the raw accelerator angle (red) and the Kalman filtered angle (blue)
The smoothing effect is impressive :o
P1020588 - YouTube?

Hi kas,
where did the graph display s/w (in the youtube video) come from?

This is a simple custom development in LabView.
The Arduino sends 2 integers separated by a comma

void serialOut_labView() {
  Serial.print(Angle + 512);           Serial.print(",");         // in Quids
  Serial.print(ACC_angle + 512);       Serial.print("\n");
}

Data can be sent alternatively to IDE serial monitor or to LabView

Angles are scaled in Quids (360° = 2 PI = 1024 Quids)
This unit is convenient and can be manipulated as integer while retaining a good resolution

Can you explain combining the accelerometer values and gyro values with a little more detail?

I know you are going to get swarmed for your code for the Kalman, but I am really struggling getting this to work. Can you detail how you went about this? Was the programming intensive? ...

Hi Gibby623, sorry, I just got your PM's
If your robot rolls about the x axis, you only need GYR_X, ACC_Y and ACC_Z
I notice that signal quality is much better when the sensor is upward, apparently, the IMU does not appreciate to be up side down
I will publish the full code pretty soon

here is the Kalman module:

// Kalman filter module

 float Q_angle  =  0.001;
 float Q_gyro   =  0.003;
 float R_angle  =  0.03; 

 float x_angle = 0;
 float x_bias = 0;
 float P_00 = 0, P_01 = 0, P_10 = 0, P_11 = 0;      
 float dt, y, S;
 float K_0, K_1;


  float kalmanCalculate(float newAngle, float newRate,int looptime) {
    dt = float(looptime)/1000;                                  
    x_angle += dt * (newRate - x_bias);
    P_00 +=  - dt * (P_10 + P_01) + Q_angle * dt;
    P_01 +=  - dt * P_11;
    P_10 +=  - dt * P_11;
    P_11 +=  + Q_gyro * dt;
    
    y = newAngle - x_angle;
    S = P_00 + R_angle;
    K_0 = P_00 / S;
    K_1 = P_10 / S;
    
    x_angle +=  K_0 * y;
    x_bias  +=  K_1 * y;
    P_00 -= K_0 * P_00;
    P_01 -= K_0 * P_01;
    P_10 -= K_1 * P_00;
    P_11 -= K_1 * P_01;
    
    return x_angle;
  }

The function parameters:

  • newAngle = ACC_angle (Accelerometers angle)
  • newRate = GYRO_rate (Gyro angle rate)
  • looptime = lastLoopTime (time between sensors measurement)

More info this week end, lets keep it public

It's balancing (at first try) :slight_smile: :slight_smile: :slight_smile:

See it live: Balancing robot - YouTube?

As soon as I install the battery on top (charger still not received), I will open a new thread with a more relevant title

This is freaking awesome!!! Congratulations!

I was so busy with my other projects that I neglected my balancing robot (I bought smaller motors and same Pololu wheels, they plug in directly on the motor shaft). I have a 2 axis accelerometer and a one axis gyro, do you think it will suffice or should I get a 5 axis IMU?

That is amazing, why is mine so bad... Sigh... What controller are you using for he wheels?

// Kalman filter module
float Q_angle = 0.001;
float Q_gyro = 0.003;
float R_angle = 0.03;

Hi Kas, awesome work on the project! My mate at uni was showing this to me today looks cool, great progress!

I am also working with an IMU a 6dof one and just wondering for your kalman filter above, how did you find the covariance matrices for measurement error and process error? lke what did you do and stuff?
Because im upto that aswell, i have my state space of the kalman filter, just dont understand how to get the covariance matrix.
Any help would be appreciated.

Thanks!!

Hi Ro-Bot-X, nice to see you around :wink:

I hope your robot will balance soon
Two axis accelerometer & one axis gyro are OK for the job
If you use separate breakout boards, make sure that axis are orthogonal, you may end up having the gyro board being perpendicular to the main board.
Also sensors units should match, don't fuse radian with deg/sec in your code
Finally the backlash we talked about is noticiable, but manageable

Please keep me informed of your progress, here
or there http://letsmakerobots.com/node/19558

@Gibby623

What controller are you using for he wheels?
Not sure I understand your question, please elaborate
If you mean motor driver,here it is: Pololu - Dual VNH2SP30 Motor Driver Carrier MD03A

why is mine so bad... Sigh...
I understand your frustration, :wink: I have been pursuing this quest nearly for 2 years
Please post photos of your bot, together with the code, I will look for possible obvious reasons

i will do this later,if i success[ch65292]i'll show my pictures.
i got a question ,why do you put the battery on the top[ch65311]
i think that if you put it on the bottom,you can controll the balance better.

i think that if you put it on the bottom,you can controll the balance better.

I know nothing about balancing robots, but I would tend to think having the mass at the top would be easier to balance. Try to balance a pencil on your hand, then try it with a weight on top (blob of clay), then a weight near the hand - you'll find its easier with the weight at the top. I imagine the same would be true for a robot (ie, inverted pendulum)...

:slight_smile:

Quote:

i think that if you put it on the bottom,you can controll the balance better.

I know nothing about balancing robots, but I would tend to think having the mass at the top would be easier to balance. Try to balance a pencil on your hand, then try it with a weight on top (blob of clay), then a weight near the hand - you'll find its easier with the weight at the top. I imagine the same would be true for a robot (ie, inverted pendulum)...

Your are right cr0sh
the robot acts as an inverted pendulum and works better when the weight is high (it increases intertia and allows more reaction time).
Try to balance a broom in the palm of your hand and see which side is easier to balance.
However, PID parameters need different tuning

// Kalman filter module

float Q_angle = 0.001;
float Q_gyro = 0.003;
float R_angle = 0.03;

Hi Kas, awesome work on the project! My mate at uni was showing this to me today looks cool, great progress!

I am also working with an IMU a 6dof one and just wondering for your kalman filter above, how did you find the covariance matrices for measurement error and process error? lke what did you do and stuff?
Because im upto that aswell, i have my state space of the kalman filter, just dont understand how to get the covariance matrix.
Any help would be appreciated.

Thanks!!

Kalman filter module works pretty well but is still a Black Box for me
I tried hard to understand and finally gave up. :o

This code is a modified version from the AeroQuad project from Ted Carancho
http://code.google.com/p/aeroquad/

I spent some hours playing with Q_angle, Q_gyro and R_angle, and finally reverted to the original parameters

Some additional lectures for the brave:
http://academic.csuohio.edu/simond/courses/eec644/kalman.pdf

http://forum.sparkfun.com/viewtopic.php?t=6186

Kas,

I am confused, on the let's make Robots site, you stated that thanks to Dallaby your robot balances. Now, Dallaby uses a complementary filter. You mention you are using a Kalman filter. So, is this the case, if so what is the contribution from Dallaby?

I am asking because I am trying to start similar project and not sure whether to spend more time trying to be able to run the kalman routines or go ahead with the complementary filter. Several sites talks very good about this simpler approach.

Thanks !

Kas,
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284650649/0#0

How do you add photos?