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.