The Balancing Robot

Now avaliable as a kit
A balancing robot kit is now avaliable via Kickstarter: http://www.kickstarter.com/projects/tkjelectronics/balanduino-balancing-robot-kit. Check out the blog post as well: http://blog.tkjelectronics.dk/2013/03/balanduino-balancing-robot-kit-kickstarter/.


Hello everybody
I have for a long time wanted to build a remote controllable balancing robot aka Segway – that’s was actually the main reason why I created the PS3 Bluetooth Library both for Arduino and the FEZ Devices. It has been a long time since the sneak peak and the performance has been improved a lot since then. The original one had a FEZ Rhino as the main processor, but I discovered that it was not fast enough to read the encoders, as it is not running embedded code. Also I was already using more than 10ms per loop, which I used as a fixed time loop, so I decided to step up a notch and go for a much more powerful device: the mbed microcontroller, which is an ARM Cortex-M3 running 96MHz.

It might have been possible with just a normal Arduino (NB: I have now ported the code to Arduino, see update for the code), but I didn’t want the speed of the processor to be an issue, so I decided to go for the mbed. The robot also features an Arduino Duemilanove with a USB Host Shield on top running a sketch based on my PS3 Bluetooth Library. The mbed board actually has USB Host functionality, but I decided not to port the PS3 Bluetooth Library as my original thought were to use an Arduino Due, but as you might know it hasn’t been released yet, despite the Arduino team announced, that it would be released by the end of 2011. But as soon as it is released I think I will port the code to it instead.

Video Demonstration
Here is a short video demonstration of the robot and me explaining some of the concepts of the design and how it works:


The Hardware
Here are some pictures of the robot:


Here is a list of all the hardware I used:

I also used:

The robot itself is made of three pieces of 215x75x7.5mm MDF wood and four threaded rods. The distance between the plates is 7cm at the bottom and 7.5 at the top. In total the robot is 27cm high including the battery.
See the 3D model for more information.

3D Model
I have created a 3D model in Autodesk Inventor with true dimensions, this will hopefully inspire other people for there robot design. All files can be found at github.
The 3D model can also be viewed at the following site: http://grabcad.com/library/balancing-robot.

Check out these rendered images of the robot:

The Code
All the code and 3D model can be found at our github. Here is a list of hyperlinks for all the repositories:

Also check out the wiki.

Update
I have now ported the code to Arduino. The code can be found at github: https://github.com/TKJElectronics/BalancingRobotArduino.

Improvements
I have thought about how I could improve the performance of the robot. First of all I could try to use an accelerometer with a smaller resolution, as the one I got is a ±3g and ±1.5g would be sufficient for my needs. Also my gyro got a resolution of ±300 deg/s and I have seen people use gyro with a resolution as low as ±50 deg/s.

Another aspect would to use belts to minimize backlash, instead of connecting the wheels directly to the motors – a bit like this one.

Also I don’t compensate for the battery level in the code – so it behaves differently depending on the battery level.

Conclusion
Overall I am really happy about the end result – it balances pretty well and the remote control works perfect!

It has been a really good learning experience for me and a really fun project to do, but also very time-consuming – I have spend many nights tweaking the PID values and adjusting tiny bits of the code before I accomplished the end result.

The next step would to build a full size one, but I don’t know if I will do it the near future – but hopefully some day :)

That’s all for now. Hope you like my robot. Feel free to post a comment below and I will answer as quickly as possible.

  1. nela
    April 11th, 2015 at 19:25 | #1

    Hi Lauszus,
    I got it working! :D My robot balances now pretty well. Thank your for all your help!

  2. April 14th, 2015 at 15:16 | #2

    @nela
    You are welcome :) Glad to hear you got it working!

  3. ali
    April 20th, 2015 at 17:19 | #3

    dear lauszus

    i am making a self balancing robot using arduino mega ,mpu6050 and polulu’s 30:1 12v 350 rpm motors with encoder, i am using jeff rowberg library for mpu sensor to get pitch values, the data from mpu comes on interrupt pin which is triggered when fifo buffer has a value , i want to know how can i read encooders using interrupts, because everytime i use ISR for encoders i get false values which i do understand because arduino is already busy on mpu data interrupt ,

    pls help me

    regards

  4. Greg
    April 21st, 2015 at 18:28 | #5

    I just had a question about how you implemented the PID loop onto your robot. I have built a robot very similar to yours and I do have it balancing. To do this, I have two PID loops. One varies the angle on which to set the robot to which is determined by how far away from zero the wheels have moved using encoders and the other PID loop gets the robot to that determined angle. Mine is not quite as stable as yours however. Is this similar to how you have set your PID loops up or have you taken a different approach?

  5. April 21st, 2015 at 23:16 | #6

    @Greg
    Yes that is the same approach I have used. Can you share your code somewhere, then I will have a look at your code :)

  6. Mansor
    April 23rd, 2015 at 12:35 | #7

    Hi Lauszus,

    Any chance porting the code to Due?

  7. April 24th, 2015 at 21:33 | #8

    @Mansor
    No unfortunately that is not something I will be working on in the near future.

  8. arpit
    May 6th, 2015 at 14:13 | #9

    hi lauszus, ur robot balances very well …. great work.
    1.I would like to know can the same robot balance for polulu’s 19:1 12v 500 rpm motor with encoder…??
    2. what was ur pwm value and how to adjust pwm value for 500rpm motor…

  9. May 6th, 2015 at 14:15 | #10

    @arpit
    It possible will, but why not just use the same ones as I used?

    You will have to tune the PID controller, so it works with your motors.

  10. arpit
    May 7th, 2015 at 05:19 | #11

    @Kristian Lauszus
    thanks…kristian
    i will tune the pid controller…because my robot is heavier some what larger in size than urs …. so for my application those motor were suitable…
    by the way thanks for ur suggestion.

  11. May 7th, 2015 at 18:11 | #12

    @arpit
    I would have recommended motors with more torque if it is heaver i.e. a higher gear ratio.

  12. arpit
    May 13th, 2015 at 03:43 | #13

    hi kirstian,
    how did u tune ur PID values so precise ??did u used some software or just by trial and error?

  13. arpit
    May 13th, 2015 at 04:01 | #14

    i would also like to know if the robot balances pretty well using arduino or it balances more precisely using mbed controller and arduino as u have mentioned on ur blog….thanks

  14. Bill Parker
    May 15th, 2015 at 22:47 | #15

    Hi Would it be practical to use this to control a full size self balance ridable 2 wheeled Segway type of transport? Or do you know of anything that might help me I have trouble walking and thinking this may help.
    Cheers
    Bill

  15. June 7th, 2015 at 15:06 | #16

    @arpit
    I tuned them manually. Start by setting all value to 0, then increase Kp until it starts oscillating, then turned it down a little. Then start increasing Ki until it starts oscillating, but this time the period should be longer. Finally you can increase Kd to dampen the system.

    The performance is the same between the two systems.

    @Bill Parker
    Please see the following blog post: http://blog.tkjelectronics.dk/2014/07/full-size-diy-balancing-robot/.

  16. Rodrigo
    June 17th, 2015 at 22:43 | #17

    Kristian,

    I am little puzzled by the way you implemented: (1) the control to reduce the target angle at high velocities and (2) the control to return to the stop position. A more intuitive approach would have been to use standard PID loops for each. For example in the “non-stop” condition a PID finds the target angle (restAngle) based on the velocity error (difference between the desire velocity and the actual velocity). In the “stop” condition a PID finds the target angle (restAngle) based on the distance away (encoder counts) from the stop position. Does this make sense? Did you try an approach like this instead? If yes, what was your experience? If not, why not? Any suggestions?

    Thank you,

    Rodrigo

  17. June 20th, 2015 at 15:21 | #18

    @Rodrigo
    You should check out this branch of the Balanduino repository: https://github.com/tkjelectronics/Balanduino/tree/pid where I have experimented with just that, but I never got it to work properly.

  18. Ryuoh
    June 28th, 2015 at 05:23 | #19

    Hi Lauszus
    I’m making balanced robot now but no matter how I tune PID parameter it can’t be balanced
    it swing like this
    https://www.youtube.com/watch?v=iS-EMOvAPAo

    I use pololu 50: gear motor with encoder
    robot weight is around 1.5 kg
    can you give me some advice

  19. June 30th, 2015 at 00:57 | #20

    @Ryuoh
    I have replied to your Facebook message :)

Comment pages
1 10 11 12 2196
  1. March 4th, 2012 at 21:03 | #1
  2. March 7th, 2012 at 21:22 | #2
  3. March 7th, 2012 at 21:29 | #3
  4. March 7th, 2012 at 23:33 | #4
  5. March 8th, 2012 at 02:49 | #5
  6. March 8th, 2012 at 05:03 | #6
  7. March 8th, 2012 at 08:31 | #7
  8. May 14th, 2012 at 15:14 | #8
  9. May 23rd, 2012 at 20:02 | #9
  10. February 17th, 2013 at 15:13 | #10
  11. February 17th, 2013 at 15:24 | #11
  12. March 18th, 2013 at 23:18 | #12
  13. March 24th, 2013 at 17:58 | #13