The MAV - Mono Axial Vehicle is a project aimed at building a 2 wheeled balancing vehicle that can function as a human transporter as well as autonomously.

 

Background

Two wheeled inverted pendulum vehicles have become practical for amateurs to build in the last decade thanks to miniature gyroscopes and accelerometers in standard IC packaging.  Also the availability of open source programming tools on the internet has made it easier to get started working with microcontrollers than it has ever been before.  Electronics has also become more open to amateurs with the valuable resources of electronics newsgroups for asking detailed technical or beginner questions, as well as online groups dedicated to open source electronics designs, such as motor controllers.  The MAV – mono axial vehicle project has only been possible to create because of the resources mentioned above.

 

The MAV is a two wheel balancing vehicle similar to the Segway™ human transporter vehicle.  Inertial sensors are used to balance the vehicle and keep it upright when the rider drives forwards and backwards by leaning.  A two wheel vehicle can remain horizontal while driving up and down steep hills, which is a major advantage over a vehicle that has passive stability with another axle, which will tip the vehicle backwards when climbing a steep hill.  Another major benefit of having only two wheels is the active stability required for balance also allows for better dynamic performance as the center of gravity of the vehicle can be shifted forwards and backwards allowing for much faster acceleration and braking times.  The MAV can also be used as a two wheeled robot, with either R/C control or autonomous operation.  To switch from riding the MAV to operating it as a robot, simply unbolt the handlebar, turn the chassis 180degrees, and bolt on the robots torso.  The accelerometer detects when the platform is flipped upside down, and the robot will start balancing as soon as the key-switch is turned on.  The design is modular so that future robot torso’s can be developed which may include sensors for robot-vision, robotic-limbs for opening doors, and also increased computing power.  It is possible that a robotic torso could be developed that would be able to provide assistance with chores around the house.

 

Notable Features

 


 

The MAV – mono axial vehicle

intro1-left_smallintro1-right_small


Hardware Design – Overview

 

The MAV is designed using homebrew modular electronic boards which are assembled together into a stack.  The assembly consists of the MAV control board, shown as the yellow box in figure1, two MAV motor control boards, shown as the two green boxes in figure1, the MAV inertial sensor board, shown as the red box in figure1, and the MAV power supply board, shown as the light blue box in figure1.  There are also two rotary encoder boards mounted on the MAV wheel shafts, shown as the two blue boxes in figure1.  There are a total of five Atmel AVR microprocessors in the MAV, shown as MCU1 through MCU5 in figure1.  Despite being fairly complex this hardware bundle is very compact and all fits into one corner of the MAV chassis.  The hardware bundle can be seen in figure 2.

 mav poster1-small

 
 

 

Figure 1: MAV Overview

 electronics stack1-small

Figure 2: The Complete MAV hardware bundle shown with its custom case

 

 

Hardware Design – MAV Control Board

 

The MAV Control Board uses an ATMega32 to gather all of the information from the inertial sensors and the wheel encoders and uses this sensor data to calculate how much torque is necessary to send to the motors.  The large code space, fast single clock instruction execution, good peripheral selection and readily available open-source programming tools made the ATMega32 a good choice, since this is where the MAV’s primary control code is located.  The MAV control board also monitors the system’s supply voltage, and uses its onboard A/D module to determine the joystick position on the handlebar.  This board is capable of logging data for debugging and performance analysis with 2 onboard 16Mbit Atmel DataFlash chips.  This board also supplies a filtered voltage supply for the IMU board where several precision A/D measurements are taken. Figure 3 shows the Eagle layout of this board.  Figure 4 shows a photograph of the constructed board, and figure 5 shows the block diagram of the board.


 mav control board-both-small

Figure 3 Eagle Layout of the MAV control Board

 

mav control board2-small

Figure 4 Picture of Constructed MAV control Board


 

 

 mav control board block diagram-small 

Figure 5 MAV control board block diagram

 

 

 

Hardware Design – MAV 6DOF IMU Board

The MAV Inertial Measurement Unit (IMU) Board contains three ADXRS150 gyroscopes and two dual-axis ADXL202e accelerometers as well as an 8 channel 16bit ADC and a precision 5Volt reference and supply.  The gyroscope sensors measure the rate of rotation around their vertical axis at a maximum rate of 150degrees per second.  The accelerometer sensors measure the force of acceleration at a maximum of 2 G’s (1G being the force of gravity).  There are two small daughter-boards each containing one gyroscope and one dual axis accelerometer soldered to the IMU board perpendicular so that three axis's of rotation can be measured by the sensors. Figure 6 shows the block diagram of the IMU.  Each gyroscope has an internal temperature sensor which is sampled by the MAV control board.  We have calibrated the gyroscopes over a wide temperature range to correct their rotation rate outputs.  Figure 7 shows the IMU stacked under the MAV control board. 

 

 mav imu board block diagram-small

 Figure 6: MAV 6DOF IMU Board


 mav imu board1-small

 

Figure 7 6DOF IMU board (below MAV control board)

Hardware Design – MAV Motor Control Board

There are two identical modular motor controller boards in the MAV, one for each wheel.  These boards were designed with flexibility and robustness in mind and they are able to operate with both brushed DC motors, surplus brushed wheelchair motors in the case of the MAV, and also with brushless DC motors.  There is an AVR ATMega168 on each of the motor controller boards and it handles command packets sent to it over the SPI bus or the UART and controls the motor by applying the requested duty cycle to the motor.  The PWM (pulse width modulation) frequency is programmable in a range from 300Hz to 30 kHz, and there is also programmable heat sink temperature limits and shunt current limits.  The bridge drivers used (IR21844’s) are high voltage devices so the motor controller can operate at a voltage range from 10Volts up to 600Volts.  The mosfets and filter capacitors must be rated to the voltage used, which sets the maximum operating voltage of the motor controllers to 63Volts which is the voltage rating of the filter capacitors used.  Although the surplus wheelchair motors used in the MAV are only rated to 24Volts.  For operation with brushed DC motors, two of the three mosfet half-bridges are used to power the motor, hooked up in an H-bridge or full-bridge configuration.  The mosfets used are IRFP2907 75Volt devices with a maximum on-state resistance of 4.5mOhm’s and a continuous current rating of 209Amps, although to maintain this large current level requires more heat sinking than currently used.  The board also supports brushless DC (BLDC) electric motors in hall sensor, encoder and also sensorless 6-state phase commutation modes.  The BLDC feature was added in anticipation of the next version of the MAV which will have homebrew BLDC motors integrated into the wheels.

mav motor control board block diagram-small

Figure 8: MAV Motor Control Board block diagram

 

 mav motor control board CAD-small

Figure 9: Eagle Layout of the motor control board


The MAV motor controller board has 3 half bridges made using high power mosfets.  For the MAV we use only 2 of the half bridges since we are controlling 1 DC brushed motor.  This board was designed with several possible applications in mind:

 

Figure 10 shows the MAV motor control board during assembly.

mav motor control board1-small

Figure 10 MAV Motor Control Board


Hardware Design – Rotary Encoder board

The Rotary Encoder board uses an ATMega168 to decode the Quadrature signal from the optical rotary encoder. The signal from the rotary encoder is decoded into a wheel position, and the wheel position is sent via the TWI Bus to the MAV control board. Figure 11 shows the block diagram of the Rotary Encoder board.

 

Figure 12 shows the 4 possible Quadrature or gray code states of the optical encoder.  The 2 channels of the quadrature encoder trigger external interrupts on the ATMega168.  The current state of the encoder is compared with the last state to determine the rotation direction.  The number of interrupts determines the total amount of rotation of the wheels.  This information is stored in a signed long int to give a large rotation range forwards or backwards.  This information is transmitted via the two wire interface to the MAV control board.  The MAV control board requests the current state of the long int rotation variable every 10ms for each of the wheel encoders.

 

 mav rotary encoder board block diagram-small

Figure 11: Rotary Encoder Board block diagram

 

quadrature state diagram-small

Figure 12: Quadrature States

 

Hardware Design – Power Supply

The MAV’s power supply is an efficient step down buck switching circuit with an input range from 12 to 80 Volts and a 10V output.  It powers everything in the MAV except for the motors.  Efficiency is a consideration since it powers 5 MCU circuits off of 24Volt battery power.

 mav power supply board CAD-small

Figure 13: Eagle layout of the MAV power supply

 

 mav power supply board block diagram-small

Figure 14: Power Supply Board block diagram

 

Software Design - Overview

The MAV’s software is organized in a simple task loop, with each task running sequentially.  The frequency of each tasks execution is set by programmable task timer variables so that a task can be set to run at the desired frequency.  The task timer variable value sets the task period directly in milliseconds, so a task timer variable of 50 will cause that task to run once every 50 milliseconds.  A task can also be disabled by setting its timer variable to zero.  For the MAV control board, there are several tasks that are running sequentially; these are shown below in flowchart 1.  It is straight forward to add more functionality by adding new tasks, this has many advantages to a single thread of code for this reason as well as the ability to turn on/off each task as well as change the frequency of each task independently.

 

The main tasks that the MAV runs on the main control board during its balancing operation are:

 

Figure 15 shows the software flowchart including a breakdown of the above 4 tasks.

 

In addition to this, the other 4 boards that have Atmel microcontrollers on them also run software.  Each has an ATMega168 MCU:

Proportional-integral-derivative (PID)

 

A PID feedback loop is a commonly used method used to control unstable systems.  It consists of 3 mathematical terms that are added as feedback to the output of the system.  The proportional value is the current error of the system, in this case the amount of deviation of the platform angle from level.  The integral term is the sampled error integrated over time.  The derivative term looks at rate of changes in the system to project the future correction factor needed to help stabilize the system.  A PD loop using only the P and D terms was found to be sufficient to balance the MAV well enough for both robotic use as well as human riding modes.

 

            torque = (platform_pitch_degrees * K1) + (platform_pitch_degrees_per_second * K2);

 

The MAV control loop has three parts:

 

1.       Measurement by the sensors (gyroscopes, accelerometers, temperature, rotation)

2.       Calculations by the MAV control board on the sensor readings.

3.       Output to the motors to correct the instability

 

In the human riding mode the proportional term is the angle of the platform relative to the direction of gravity.  This value is computed by integrating the gyroscope readings and using periodic corrections from the accelerometers to prevent the integrated gyroscope angle from drifting over time.  The derivative term is the platform rate of tilt which is the calibrated and filtered output of the gyroscope.

 

In the autonomous mode the calculations are executed in the same way, except that the proportional term has a position correction factor on each execution.  This term is the distance away from a user or AI controlled point.  If the MAV’s current position is different than this point, then it moves towards it.  The P, I and D terms for position holding in autonomous mode are shown here:

 

            torque = torque + (platform_position_meters * K3);            //position proportional

           

            torque = torque + (platform_meters_per_second * K4);      //position derivative

 

            torque = torque + (platform_position_meterSeconds * K5); //position integral

 

 

The C code for sending a dutycycle update from the MAV Control board to the motor controller 1 over the SPI Bus is shown here:

 

MOTOR1_CS_active;                 //enable the motor1 chip select line

 

printf("$i%05u&i%05u\r", motor1_dutycycle_int, motor1_dutycycle_int);

 

            MOTOR1_CS_inactive;   //disable the motor1 chip select line

 

 

First the motor1 chip select line is enabled, then the updated dutycycle is sent in packet form using the printf function, which looks like this: “$iVALUE&iVALUE\r”.  This sends the same 16bit dutycycle twice as VALUE with ‘$’, ‘I’, and ‘&’ being packet protocol identifiers.  The dutycycle value is sent twice each update to prevent dutycycle value errors that we thought may result from motor noise on the SPI bus.  Luckily the SPI bus seems to be very robust and motor noise has not been an issue.

mav system overview flowchart-small

Figure 15 – System Overview (MCU1 ATMega32) Flowchart

 

 

Conclusion

The MAV project successfully reached its goals of making a working mono-axial 2 wheel balancing vehicle that can function robotically and is also human useable.  Electronically it is a compact design that uses 5 AVR Atmel microprocessors to process analog sensor data and perform rapid feedback control calculations.  The MAV is also a robust design that performs many self checks to ensure the various components are working as intended.  The MAV electronic and software design can also be used as a starting point for enthusiasts to enter the hugely popular realm of robotics.

 

References

 

ATMega32 “8-bit AVR Microcontroller with 32KBytes In-System Programmable Flash”

ATMega168 “8-bit AVR Microcontroller with 16KBytes In-System Programmable Flash”

http://www.atmel.com/

 

WinAVR - open source development tools for Atmel AVR microprocessors for Microsoft

Windows platforms, including GNU GCC compiler and UNIX-like utilities

http://sourceforge.net/projects/winavr/

 

Eagle Cad - EAGLE Layout Editor http://www.cadsoft.de/

 

Olimex - Fast PCB Prototypes http://www.olimex.com

 

Digi-Key Corporation, on-line electronics part distributor http://www.digikey.com/