Home > ARM, News > Sneak Peak: Segway guide + code

Sneak Peak: Segway guide + code

Here is a short sneak peak of a project we are working on.
When the project is finished we are going to write a guide about it, publish the code and of course make a longer video explaining the different parts and showing the Segway in action!

I can briefly say that we are using 2x 12V motors + Motorcontroller from Pololu, a 6DOF board from Sparkfun, a FEZ Rhino and a 12V battery pack.

The data from the 6DOF board is run thru a Kalman filter, whose data is used in a PID filter to regulate the motors. More details and source code will come soon!

The code can be found below:
BalancingRobot.zip

Update
More information about the finished robot can be found here: http://blog.tkjelectronics.dk/2012/03/the-balancing-robot/

Categories: ARM, News Tags:
  1. batista1987
    January 5th, 2012 at 15:35 | #1

    Hi,
    i’m building a simple seegway that is very similar to your seegway. So my compents are:
    1) arduino 1
    2)IMU ITG3200/ADXL345 http://www.sparkfun.com/products/10121
    3)2 servo HSR-1425CR http://www.robot-italy.com/product_info.php?cPath=85_28&products_id=1826

    The algorithms I’m using to balance it is PID, LQR and pole assignment. I was thinking of integrating this project into a drive this http://blog.tkjelectronics.dk/2011/09/fez-panda-ps3-controller-via-bluetooth/. What do you think? do you think is feasible?

  2. January 5th, 2012 at 15:59 | #2

    @batista1987
    Hehe, we thought about doing the same.
    Though we have had some problems with the FEZ Panda not being fast enough because it doesn’t run/use Native code. This makes the wheel encoder routine a bit slow, and if it is going to do Bluetooth PS3 controller communication also it might not work.

    But as you are thinking about using the Arduino, I would recommend you to use the Arduino MEGA as it has a bit more RAM which makes it able to communicate with a PS3 controller via Bluetooth, by using a USB Host shield. We will soon publish an Arduino library for this.

    Best Regards
    Thomas Jespersen

  3. batista1987
    January 5th, 2012 at 16:30 | #3

    ok, thanks for your suggestions. what 6Dof you are using? you think that is necessary an encoder?

  4. Lauszus
    January 6th, 2012 at 17:12 | #4

    @batista1987
    I’m using this 6DOF IMU from Sparkfun: http://www.sparkfun.com/products/10010
    You should check out my other post for details: http://blog.tkjelectronics.dk/2011/06/guide-gyro-and-accelerometer-kalman-filtering-with-the-arduino/

    The problem is that the robot doesn’t if the wheels are actually turning, so it’s hard for it to stay at the same place the whole time. It might start drifting to one of the sides. The encoders aren’t necessary but if you haven’t bought your motors yet, I recommend you get some with build in encoders. I’m using these from Pololu: http://www.pololu.com/catalog/product/1443, there a okay, but with noticeable backlash.
    I will update the post soon with more details – i promise πŸ™‚

  5. batista1987
    January 7th, 2012 at 13:25 | #5

    @Lauszus
    unfortunately I have bought already them. According to you I can make it to work with my servant?

  6. Lauszus
    January 7th, 2012 at 19:26 | #6

    @batista1987
    Yes you can. The video above actually haven’t implemented the encoders. So you can definitely make it work without them or you could use external encoders πŸ™‚

  7. lezav
    October 5th, 2013 at 15:41 | #7

    Hi,
    Am trying to use an IMU6050 and arduino uno for a 2 wheel bot. Question: is it possible to use your balanduino code without encoders? If so, what lines-modules must be commented out?
    thanks

  8. October 8th, 2013 at 12:48 | #8

    @lezav
    Yes it is possible, but it won’t be stable enough for remote control, so I really recommend spending the extra money and buy some encoders, you won’t regret it πŸ™‚

    The source code can be found here: https://github.com/TKJElectronics/Balanduino/tree/master/Firmware/Balanduino. These are the parts that needs to be removed: https://github.com/TKJElectronics/Balanduino/blob/master/Firmware/Balanduino/Motor.ino#L145-L166. After that simply just remove all the parts that gives you an error.
    Also note that you can disable all the remote control stuff my commenting out these lines: https://github.com/TKJElectronics/Balanduino/blob/master/Firmware/Balanduino/Balanduino.ino#L13-L18.

  9. dhiraj
    October 12th, 2013 at 17:36 | #9

    Is it possible to balance the robot without using motor with encoder?

  10. October 16th, 2013 at 22:31 | #10

    @dhiraj
    Yes, but it will never be as good. See my comment just above your for more information: http://blog.tkjelectronics.dk/2011/12/sneak-peak-segway-guide-code/#comment-442987.
    Btw the video you see in this post is without encoders.

  11. mao007
    October 22nd, 2013 at 21:35 | #11

    hola @ Lauszus.
    yo estoy utilizando tus mismos motores : http://www.pololu.com/catalog/product/1443 y estoy usando el sensor imu 6dof (mpu 6050), me podrias ayudar con el codigo I2c del sensor. yo no estoy trabajando con arduino, estoy trabajando con una FPGA no se si has realizado algun codigo el lenguaje vhdl.

    gracias.

  12. October 22nd, 2013 at 22:02 | #12

    hello @ Lauszus.
    I am using your same engines:
    http://www.pololu.com/catalog/product/1443 and am using the imu 6DOF sensor (mpu 6050), Can you help me with the code I2c sensor. I’m not working with arduino, I’m working with an FPGA not if you did some code vhdl language.
    Thank you.
    Hi mao007.
    It it’s possible to implement the same controlling and stabilization algorithm (PID controller) inside an FPGA and VHDL code. You would also be able to implement the sensor reading thru I2C.
    All this would be doable without any microprocessor, so in only logic (not any softcore processor either).

    But if you plan to do any controlling of the robot such as ours with Bluetooth, Serial or similar, you are better of with a microcontroller.
    When it comes to controlling algorithms it is also more easy to implement, test and debug in a microcontroller than inside an FPGA!

    Regards Thomas

  1. February 17th, 2013 at 15:00 | #1