Printed from www.nzmeccano.com
A Meccano Segway
(Author: Andre Theberge)
This section covers the assembly and fine tuning of the Meccano Segway. The Arduino code is available in another subtitle. The meccano assembly instructions and parts are not covered, because it is a rather simple model and the photos reveal much of the details. Also, depending on the size of the battery used, the motors and the overall assembly to ensure balancing, the details of the construction may vary.
I hope you find here enough info to build your own version, should you have any questions, you can send me an e-mail at : firstname.lastname@example.org and I will try my best to help you. Please keep the questions pertaining to this project, if your question is more general in nature (How do I use an Arduino?.. How does a gyroscope works?), please consult the Arduino forum or the sources below:.
- Arduino Robotics Book, chapter 11: Construction of a Seg-bot
And check my videos on YouTube:
Parts list (non meccano items)
2 x 80RPM geared motors. I bought them locally for $13 CDN. There are plenty of vendors available on the internet, so pick your favourite.
1 x 9DOF accelerator/gyroscope combo stick. Bought at HobbyKing for $25 US. Adafruit has also a great selection of these parts, built on a 'breakboard'. I wrote the code to be compatible with the AXDL345 and IGT3200 chips, which are fairly common. I also support the L3GD20, which is a better gyroscope in my opinion.
1 x Arduino module. Bought at Adafruit for $30US.
1 x Motor driver shield, bought at Adafruit for $15US. Mine is the older version, which is now obsolete. They have a more recent model, which is compatible. You will have to assemble the board, as it comes in a kit.
1 x 1K potentiometer. You may also use any value between 1 and 10K.
1 x power switch and battery connector. The battery connector was purchased at HobbyKing.
1 x LiPo battery, 4S, 1600mAh (14.8V nominal), bought at HobbyKing for $17US. Or equivalent You will need to buy the charger if it is your 1st battery of this type.
Some wires to interconnect everything
Arduino to 9DOF
- Analog 5 (SCL) to SCL
- Analog 4 (SCA) to SCA
- GND to GND
- +5V to VCC (the 9DOF used has a voltage regulator taking it down to 3.3V). Be sure that if you use anothe model, it has also the 3.3V regulator)
Potentiometer to Arduino
- Left pin to GND
- Center pin to Analog 3
- Right pin to +3.3V
Motors to Adafruit motor shield
- The code is written to support M1 and M2 on the arduino shield. Wire them the same way (one will turn CW, the other CCW, that's OK, the software compensate for this and send reverse intructions to the motors to make then go in the same direction. If the Segway is unstable or goes in the opposite direction, reverse the wires.
Trips and tricks when building the Segway
- Use the #52 meccano base as a support, and bolt the motors firmly to it. See the photo, I was able to support my motors in 3 points.
- Try to lower the center of gravity of the Segway by putting the wheel/motor combo as high as possible.
- The unit must be balanced (front and back) at all times (during testing and in the final prototype). In other words, the X-Y center of gravity must be on the center of the #52 base. If you add weight in the back (like the LiPo battery, you must add an equivalent weight at the front, at about the same distance. One trick I used for temporary weight is a bunch of 11 holes strips bolted together, and held temporary to the chassis with strong magnets. Just FYI, a #2 strip weighs 10g.
- The accelerometer/gyroscope combo must be mounted at the X-Y center of gravity of the chassis. With my model, the X axis of the acceleometer and the Y axis of the gyro (Pitch) both tilt with the chassis. This is how my code is written. BEWARE: The proper axis and directions are crucial for the stability, I spent a lot of time trying to tune the accelerometer on the Y axis when I found it was the X axis that was in play. As well, the accelerometers I used had a terible offset when put flat on the table, that must be compensated. Read the next section below on how to do it.
- When building the top section, try to use plastic rather than metal plates, because of the weight and also because some of the plates may touch the electronics, causing a short-circuit. In doubt, use transparent tape (I have done this at a couple of places)
Depending on your choice of components, these adjustments will have to be performed. Do not take them lightly, they make the difference between a working Segway or a non-working project.
- You must find the offset of your accelerometer, on the X axis. Put is flat on a levelled table, and set the accel_offset constant to 0. Read and print the accel_raw variable (un-comment it in the serial_print_stuff() subroutine). The value read is the offset, make the accel_offset equal to it, and check if the accel_angle becomes 0. Note, with the Adafruit accelerometer, my offset was 0, with the 9DOF stick from HobbyKing, I had offsets of -160 and 98, which are huge (almost 60 degrees). You pay for quality!
- About the same thing as the accelerometer, except the variables are gyro_offset and gyro_raw. The gyro only gives a value when turned, it measure the spead of rotation instead of the position.
- If your gyro is super sensitive, you may want to play with the gyro_weight and accel_weight variables. Their sum must always equal 100. Try values for gyro_weight between 2 and 10.
- The code is written to support 2 types of Gyro, as-is it is for the ITG3200. If you want to use the more stable Adafruit Gyro, just un-comment the portions of code. Search for the pattern %%% to help you find them.
- The 1st parameter to adjust is m1_start_offset (and m2_start_offset), which is the minimum PWM value to make the motor turn. This parameter is motor dependant When the chassis is tilted slightly, the PMW value should be high enough to make the Segway move, but not too high to make it jerk. Adjust it by putting low values first; you will notice a 'dead-spot' (motors not moving) when you tilt the Segway from a level position back and forth. Then increase the value until the dead-spot dissapears. As you add weight to the Segway (by putting the top part on the chassis), you may have to fine-tune this parameter.
- The second parameter is the gain_val. It affects how the motors react when the Segway is tilted. Try different values to achieve stability when stationnary and reasonnable speeds when tilted.
- When testing the Segway for the 1st time, set the steer_val to zero, to discard the potentiomer reading. Once stability is achieved, comment the steer_val =0; statement and adjust the values of steer_range and the values in the map command (just after the AnalogRead, in the read_pots() function) to achieve proper steering. This is another 'trial and error' setting.
If you have any interesting information or comments about this page, please add them here: