# Arduino Forum

## Community => Exhibition / Gallery => Topic started by: Rivello on Aug 08, 2011, 05:37 am

Title: Self balancing waiter tray. (or almost it)
Post by: Rivello on Aug 08, 2011, 05:37 am
Ok, in truth it's not exactly that, but that's the nickname it got.

It's a self-stabilizing platform. It doesn't matter the angle you put the lower platform in, the upper platform will ever stay in the horizontal position.

I used the method from this post (http://arduino.cc/forum/index.php/topic,58048.75.html), by Lauzsus, and adapted to my needs, including the servo motors.

Check it here:
Title: Re: Self balancing waiter tray. (or almost it)
Post by: frank26080115 on Aug 08, 2011, 05:38 am
It needs to go on a roller coaster for testing
Title: Re: Self balancing waiter tray. (or almost it)
Post by: retrolefty on Aug 08, 2011, 06:23 am
That's pretty cool. Got any code you can share with us?

Lefty
Title: Re: Self balancing waiter tray. (or almost it)
Post by: Rivello on Aug 08, 2011, 07:06 am
Sure, the principle is the following:

It reads the inclination angle data given by the accelerometer and gyro, applies Kalman Filter to best predict the real inclination and write to the servo motors the inverse angle to compensate the inclination.

For my luck, I found an already made Kalman Filter algorithm for arduino in this post: http://arduino.cc/forum/index.php/topic,58048.msg417140.html#msg417140

Then I basically used the same code, just adapting it to write the angles to the servos:

#include <Servo.h>
Servo servo1;
Servo servo2;

servo1.attach(6);
servo2.attach(9);

// added in the end of loop() function:
servo1.writeMicroseconds(1560-yAngle*9.55);
servo2.writeMicroseconds(1510+xAngle*9.55);

Where 1560 and 1510 are the values corresponding to the center position of my servos and yAngle and xAngle varies from -90 to +90 and are scaled to fit the observed servo limits.

Title: Re: Self balancing waiter tray. (or almost it)
Post by: bld on Aug 08, 2011, 08:32 pm

Sure, the principle is the following:

It reads the inclination angle data given by the accelerometer and gyro, applies Kalman Filter to best predict the real inclination and write to the servo motors the inverse angle to compensate the inclination.

For my luck, I found an already made Kalman Filter algorithm for arduino in this post: http://arduino.cc/forum/index.php/topic,58048.msg417140.html#msg417140

Then I basically used the same code, just adapting it to write the angles to the servos:

#include <Servo.h>
Servo servo1;
Servo servo2;

servo1.attach(6);
servo2.attach(9);

// added in the end of loop() function:
servo1.writeMicroseconds(1560-yAngle*9.55);
servo2.writeMicroseconds(1510+xAngle*9.55);

Where 1560 and 1510 are the values corresponding to the center position of my servos and yAngle and xAngle varies from -90 to +90 and are scaled to fit the observed servo limits.

By sure, you mean "No, but I do what to show you how I use the servo lib"? :P
Title: Re: Self balancing waiter tray. (or almost it)
Post by: Rivello on Aug 08, 2011, 09:28 pm
Well, but it's exactly that,

why to complicate things? It's just an union of a kalman filter, an IMU and servo motors.   XD
Title: Re: Self balancing waiter tray. (or almost it)
Post by: retrolefty on Aug 08, 2011, 11:05 pm
Well it is your sketch, and your free to show what parts of it you wish.  ;)

Title: Re: Self balancing waiter tray. (or almost it)
Post by: liuzengqiang on Aug 09, 2011, 12:10 am
Very well done! Your machine passed bar exam ;)

If I had this, I would walk with it mounted on my right shoulder and put my drink on top of it.
Title: Re: Self balancing waiter tray. (or almost it)
Post by: Rivello on Aug 09, 2011, 09:20 am

Well it is your sketch, and your free to show what parts of it you wish.  ;)

I hope you didn't get me wrong. I didn't show the rest because it was not my creation. (I adapted from Lauszus post, which adapted from another project)

You can see the sketch I started from by downloading the file "IMU6DOFVer3.zip (http://arduino.cc/forum/index.php?action=dlattach;topic=58048.0;attach=5095)" which I got from this post Guide to gyro and accelerometer with Arduino including Kalman filtering (http://arduino.cc/forum/index.php/topic,58048.msg417140.html#msg417140) by Lauszus.

The only modifications I did was the mentioned above.

Cheers,   :)
Title: Re: Self balancing waiter tray. (or almost it)
Post by: dgxanadu on Oct 12, 2012, 04:04 am
Hi Rivello,
I'm not an expert...but I will like to know how to connect  (wire) all the listed components.