Go Down

Topic: Balancing robot for dummies (Read 41177 times) previous topic - next topic

batista1987

@Lauszus,
Quote

Okay, it seems alright then.

the code is correct, but the result is not correct.

Quote

But I really see no point of converting it to deg/s, unless you want a speedometer or something like that?
Because it really doesn't matter if just need it to make it balance.
But of course it's always nice to know what your robot is capable of

Is necessary to know the speed, because my control system are a LQR and pole placement.
These two control systems, can be applied to a dynamic system whose equations are written in the form of state.
In fact, after writing the dynamical system in the form of state (taking into account the masses, the moment of inertia, the motor inertia, the height of the robot, the radius of the wheels, the weight of the robot) I get the equations whose variables are precisely the state of the system. In my case they are
1) the position that the robot reaches (practically is a linear position, obtained by knowing the angular position multiplied by the radius, obtained in meters) = x1
2) the speed of the robot (ie, angular velocity multiplied by the radius obtained in m / s) = x2
3) the angular position (obtained in rad / s) = x3
4) the angular acceleration (obtained in rad / (s ^ 2)) = x4

Knowing these variables that represent the state vector x, I can provide a control action u =-k * x, where exploding are: u =-k1x1-k2x2-k3x3-k4x4,
then it is necessary that the values ??x1, x2, x3, x4 are in units of measurement right.
The various k (k1, k2, k3, k4) are obtained by means of the algorithms LQR, or pole placement, which can be applied directly from matlab
I hope I made you understand something

Lauszus

@batista1987
That makes perfectly sense. I have never seen a implementation like that in action. I'm really looking forward to se the outcome and see how well it balances.

batista1987

@lauszus,

I hope to make it work.
For now I still have problems with the speed of the engine :-(

batista1987

hi my gyro ITG-3200 has this sensitivity 2000 [degrees/second]. As regards to you what is the sensitivity in [mV/degrees]? So why as regards to you the measures of gyro (that give an angle ) is explain in [degrees/second] and not only [degrees]?

Lauszus

#94
Jun 15, 2012, 12:29 am Last Edit: Jun 15, 2012, 12:54 am by Lauszus Reason: 1
@batista1987
The sensitivity is 14.375 LSB/(º/s) - see the datasheet: http://invensense.com/mems/gyro/documents/PS-ITG-3200A.pdf
Also take a look at the following line of some code I wrote: https://github.com/TKJElectronics/Example-Sketch-for-IMU-including-Kalman-filter/blob/master/IMU6DOF/Digital_IMU/Digital_IMU.ino#L31 for this guide: http://arduino.cc/forum/index.php/topic,58048.0.html
A gyro will always output in º/s and not in an angle - remember that if the gyro drift just a tiny bit the angle can be very incorrect. That's why you often use a filter to find the bias for the gyro - see the following line of the kalman filter for my balancing robot: https://github.com/TKJElectronics/BalancingRobotArduino/blob/master/BalancingRobotArduino.ino#L300

Regards
Lauszus

batista1987

#95
Jun 23, 2012, 11:15 am Last Edit: Jun 24, 2012, 10:03 am by batista1987 Reason: 1
tks lauszus. I've some questions :)
1)If i set the PWM frequency on 20Khz as you say, the value to have max speed is 400. as regards to you 400 is corresponding to 100% of duty cycle? and 14 is corresponding to 0% of duty cycle? or aare corresponding to other %?


2)If the timing loop is 10 ms, so has a frequency of 1Khz, is possible use a PWM at 20 Khz?

3) can you explain the function void moveMotor(Command motor, Command direction, double speedRaw)? particularly the moveMotor function, this code
Code: [Select]
  int speed = speedRaw*((double)PWMVALUE)/100; // Scale from 100 to PWMVALUE i think is to have the value not in per cent. Is true? so i think that (F_CPU/PWM_FREQUENCY/2)/100=4000, but in your opinion should not be equal to 400?

Lauszus

@batista1987
1)
A 100% duty cycle is equal to 400, but a 0% duty cycle is equal to 0. That means 25% is equal to 100, 50% equal to 200, 75% equal to 300 and so on.

2)
Yes, the frequency of the PWM has nothing to do with the frequency of your loop. As long as your are using a hardware timer you can set the frequency to what ever you like, as it uses a timer to operate. But if you had to implement a software PWM you would rely on the frequency of your loop.

3)
It's pretty simple. The speedRaw is the duty cycle in percentage (0-100%), i just convert it to the right number corresponding to the percentage - so 50% would be converted to 200 and so on.
The reason why I implemented it that way, is because then you can easily change the CPU frequency or PWM frequency and the code would take care of the rest.

Where do you get that equation from? This is the right one (see https://github.com/TKJElectronics/BalancingRobotArduino/blob/master/BalancingRobot.h#L7):
Code: [Select]

F_CPU/PWM_FREQUENCY/2


And since my Arduino is running at 16MHz and the PWM frequency is 20kHz, the equation look like this:
(16*10^6)/(20*10^3)/2=400

You can use wolframalpha if you like: http://www.wolframalpha.com/input/?i=%2816Mhz%2F20kHz%29%2F2

Regards
Lauszus

batista1987

@Lauszus,
you are always very clear. thanks
So with my tecnique, i've many problem, so i would use your code, so i've a different imu(but works fine), and a different gearmotor (http://www.pololu.com/catalog/product/1442). according to you separately Ki, Kd and Kp, where do I go to edit?

Lauszus

@batista1987
You should see this reply on my blog: http://blog.tkjelectronics.dk/2012/03/the-balancing-robot/comment-page-1/#comment-20170 on how to tune the PID values.

sebnil

This forum post was probably the one I got most of my ideas from when I wanted to build my own robot. This is my how it looks right now:
http://www.youtube.com/watch?v=QH83A746gS0
In the video you can see that the robot stays at roughly the same spot on the floor and handles a lighter push without any problem. To achieve this I have two cascade PID controllers and low pass filter on both wheel speed and the robot's angle.

Now I am thinking about improvements. Better stabilization is a first. And radio control would be nice.

More info and component list on http://sebastiannilsson.com/en/k/projekt/selfbalancing-robot/

http://sebastiannilsson.com

pseddon

Is this code available? When I click on the link on this page http://www.x-firm.com/?page_id=148 I get a an encoder test app.

regards Peter

Lauszus

@pseddon
Just click at the code labeled "KasBotV2" instead :)

pseddon


pseddon

The KasBotv2 code does not include for steering only standing. Were there any developments done to allow the BalBot to be driven around?

regards Peter

Lauszus

I don't know, but you should have a look at my robot: http://blog.tkjelectronics.dk/2012/03/the-balancing-robot/.
The code can be found at the following link: https://github.com/TKJElectronics/BalancingRobotArduino

Go Up