Before starting to build a human sized Segway, I started off by building a small prototype to try out the balancing algorithm and also the electronic circuit.
I decided to use the arduino Duemilanove as the microcontroller because it is pretty easy to use especially for hobbyist. Arduino has its own library and you just need to understand basic c++ to program it. Even if you do not have any programming background, don't worry, arduino ide came with many example program and you also can seek help from the the arduino forum.
Arduino Duemilanove is an 8 bit microcontroller with a speed of 16Mhz. For an application like the segway, the program will be running at 100Hz, thus Arduino is fast enough to do all the job. There are 6 analog inputs, 13 digital outputs, and 4 pwm. You may want to consider the arduino mega if you need more input and output.
Next, we need a motor controller. The picture on the left is ardumoto, it is capable of driving two different motors. As for the motor, I just used the tamiya motor that came together with the double gearbox.
Last but the most important is the Inertial Measurement Unit(IMU). We need the IMU which is a combo board of a 2-axis accelerometer and a single axis gyroscope to calculate the tilted angle. Depending on the tilted angle the algorithm will compensate it by driving the motor towards the direction where the robot was tilted. The greater the tilted angle the faster the motor has to move to balance back the platform. This application is the same as the inverted pendulum problem.
I chose the adxl203/adxrs614 IMU a 3 axis acclerometer and 1 axis 50degree/s gyroscope. All the component mentioned can be order easily at www.sparkfun.com
Ok, enough of the hardware, now let us look at the algorithm. To balance a two wheeled platform like segway, we need a balancing algorithm to control the motor. The control is pretty simple. If the platform was tilted forward, the motor will move forward, the speed was determined by the tilted angle measured by the IMU. The faster the rate of change and the greater the tilted angle, the faster the motor has to move to keep its upright position. Same thing goes to backward, the motor will always move according to the direction the device was tilted.
For turning is easy, all you have to is move one side of the motor faster while the other side of the motor slower.
Next, I will post the code very soon.
c'mon man, we need updates!! I'm gathering up my parts now to do the exact same thing that you're doing. keep up the good work.
ReplyDeleteHi sorry, was too busy so didn't update the blog for so long, nearly forgot it until so an email of somebody comment, yeap i uploaded the code already
ReplyDeletecan i use same code to little robot at human size robot ?
ReplyDeleteor have new code and were ?
i have now arduino,adxl 345,gyro lpr550,lcd screen dfrobot i2c module 508040,motor shield dfrduino L298p,
what more need ? code same different motor shield and lcd ?
sorry im newbie arduino user, make elektronic project before many year but arduino new.picaxe some project wery simple,and work plc programming,
but i have dream i make own segway too,now i looking net many sites last 2 year and no found better segway than you :)i love sittingway idea :D
if you can send more information send finall code to me too if you can.best regard
matti v from Finland
Hi, the code will work for the human sized robot too, just need to tune the pid value. However for human size robot, you may want to add more safety features
DeleteBIG project i think dead men switch have good safety if drop out of seg,same than water scooter have or railway,other,and speed max controll borden,and same than elektric microcar have,sliding stop safety,mean not slide if power turn max,=if power 255 then power go high only step +5/step and no all full sametime.
ReplyDeleteLITTLE project, and now looking how drive (learn) dfrobot 2A dc motor board :)pll or pwm ? i no know who have better. i think pwm better ? sabertooth use same ?, not have important now,first need make working version at little project.no found code example how move left and right, i understand now forwar and backwar(have examples)but no L and R yet :)
thanks you answer and information.
i think little robot i use whit cable and potentiometer(easy test),1pot=F&B and 2pot=L&R or if found ready arduino joustic controller.
were have shematic,i have now all parts but no know connect at IMU and uno pin numbers. code no have information what pin use. i have DFrobot 2A motorcontoroller,IMU adxl335 and reserve have mpu-6050 too.2 motor and gear.,thump joystick,lipo accu,
ReplyDeletemust test but no have shematic how connect thats.