Thursday, October 6, 2011

Microcontroller-driven Lego Vehicle (MLV).

,

                         Microcontroller-driven Lego Vehicle (MLV).


Introduction
For the final project, we designed a Microcontroller-driven Lego Vehicle (MLV). This project makes use of the ATMEL AT90S8535 8-bit RISC microcontroller unit. The microcontroller basically functions to determine the user input through button pushes, drive the DC and stepper motors to provide motion to the MLV as well as to set the speed of the vehicle through the use of the onboard Analog-to-Digital converter.
Our project involves a combination of hardware and software design. The hardware part includes building the mechanical model for the MLV and circuitry to drive the DC and stepper motors by providing the necessary power and voltage level, as well as providing electrical protection for the microcontroller unit. The software part involves designing the state machine for the steering and motion control of the MLV, providing the stepping sequence for the stepper motor and controlling the LED signals.
Features
  • 6-button Input System
    Steer Left, Steer Right, Forward, Reverse, Stop, Raise and Lower Tray.
  • 2 Stepper Motors and a DC Motor
    DC motor provides the forward and reverse movements while the 2 stepper motors are used to provide steering and raising/lowering camera mount rack respectively.
  • Speed control
    Increase or decrease the speed of the vehicle by adjusting the trim-pot knob.
  • Light Indicator for different movements of the vehicle
    Left and right blinking signal, forward and reverse and park light.
  • Planetary Gear System
    Planetary gear system for forward and reverse movement for higher torque.
  • Differential Wheel System 


  • High Level Design
The Microcontroller-driven Lego Vehicle (MLV) begins in a 'parking' condition where all of the motors sit idle and the stop lights turn on. It then wait for a user input through a button push. If the Forward button is pushed, the MLV moves forward and the forward headlights turn on. If the Reverse button is pushed, the MLV moves backward and the reverse lights turn on. Note however if the MLV is moving forward and the Reverse button is pushed, nothing will happen. The same goes when the MLV is going in reverse and the Forward button is pushed. This is done as a safety measure to protect the mechanical part of the vehicle. Pushing the left or right steering button makes the front wheel of the vehicle turn in the appropriate direction. Pushing the Raise and Lower button raises and lowers the camera mount. Steer Left or Right and Raise or Lower buttons produce motion when the vehicle is moving forward, backward or in a parking condition.



Figure 1. State Diagram



  Software Design



            We started our design by first figuring out the state transition diagram for the MLV. There are three states: stop, forward and reverse. We used a branch table to implement the state machine. In each state, the microcontroller sends different signals to the ports. At the same time, it also checks for 'steering' (for turning the front wheel right and left) and 'hand' (for moving the camera mounting up and down) button press if any by calling the appropriate subroutines.
(1) State: Stop
In this state, the MLV is not moving. The microcontroller turns off both the forward and the reverse switch, and lights up two LEDs to indicate this state. It then calls the 'steering' and 'hand' button press. If any of the four buttons (right and left for 'steering', and up and down for 'hand') is pressed, it executes the appropriate subroutine. After that it checks for 'forward' and 'reverse' button press. If any of these two buttons is pressed, it loads the new state before jumping back to the branch table.


(2) State: Forward In this state, the mictrocontroller first gets the ADC reading to determine the speed. Then it turns on the forward switches and lights up two LEDs to indicate that the MLV is in the forward state. Then, it calls the 'steering' and 'hand' subroutines and checks for stop button press. If there is no button press, it jumps in a loop and continously checks the speed specified by the ADC every one second. If the stop button is pressed, it loads the 'stop' state and jumps back to the branch table.

(3) State: Reverse
In this state, the microcontroller does the same thing as in state forward except that it turns on the reverse switch and lights up the reverse LEDs.

Timers We practically used all the timers/counters available on 8535 chip. More specifically we used Timer2 and Timer0 Overflows, Timer2 and Timer1 Compare Match. The following discusses in more details what each timer does:
Timer2 Overflow and Compare Match
Timer2 is used to vary the speed of the DC motor via PWM. First Timer2 is set to prescaler 2 (clk/8) corresponds to an interrupt of every 512msec. Then the OCR2 register is loaded with the 8 MSB of the 10-bit ADC. When Timer2 Compare Match interrupts, the interrupt subroutine turns off the forward or the reverse switches depending on the state which the MLV is in. However, it does not reset TCNT2, and thus Timer2 will keep counting. When Timer2 Overflow interrupts, it turns the forward or the reverse switches back on. So, both Timer2 Compate Match and Timer2 Overflow are combined to pulse-width-modulate the voltage/current to the DC motor.

Timer1 Compare Match
Timer1 Compare Match is used to sample the ADC every 1 sec. Timer1 is set to prescaler 3 (clk/64) and the Match A register is set 62500. This corresponds to an interrupt every one second (62500*16microsec=1sec). The interrupt subroutine starts the ADC conversion and resets Timer1 counter to zero.

Timer0
Timer0 is used to send the four steps required by the stepper motors ('steering' and 'hand'). For both 'steering' and 'hand', Timer0 is set to prescaler 5. This is to produce very low step frequency so that the stepper motors will turn very slowly. The step sequence for both stepper motors are defined in tables in flash memory. A counter is used to read the step value from the tables.

Debounce
The button press is debounced for 5msec using two counters. This is to avoid spikes from being considered as a button press.

Subroutines Steering
This subroutine will enable Timer0 and initialize the step counter to 0. It first checks the direction of the steering depending on which button (right or left) is pressed. If it is a right button, it lights up the right LED and loads 'right' to the register 'turn' and vice versa. When Timer0 interrupts, it will check the content of this register and assign the appropriate address of the step sequence table defined in flash.

Hand
This subroutine does exactly the same thing as the 'steering ' subroutine except that it loads the 'turn' register with 'up' or 'down' depending on which button is pressed. There is no LED indicator for 'up' and 'down' however. Timer0 will also check for this buttton and load the appropriate step sequence.

OffSignal
This subroutine simply turns off the turn 'right' or 'left' indicator. It is called when the any of the steering button is released.

Ports
  1. PortA is only used for the ADC. ADMUX is set to 7 to sample from channel 7.
  2. PortB:
    PortB0 and Port1: Switches for the ADC motor
    PortB3-to-PortB7: LEDs for 'stop', 'forward', 'reverse', 'right' and 'left' indicator.
  3. PortC:
    PortC0-to-PortC3: To control the 'steering' stepper motor
    PortC4-to-PortC7: To control the 'hand' stepper motor 
 Vehicle Chasis
We begin the hardware design part of this project by trying to figure out the best way to efficiently mount the motors. Multiple mechanical models were created and torn apart until an acceptable model was found. At the end, we decided to create the mechanical model using components from Lego Technic™ 'Turbo Command' package. It basically consists of 472 Lego pieces which include the components to build a differential wheel system. Epoxy is used to fix the Lego gear pieces to the drive shafts of two motors. Wires and polystrene is used to provide support and strengthen the mechanical model. Click here to see final mechanical model for the vehicle.
 Transistor Switches
Transistor switches are used to provide the proper stepping sequence for the stepper motor. Since the output from the Atmel board is only 5V, transistor switches are used to provide 12V signal which is needed by the stepper motor to operate. Also, A H-bridge transistor switch network is used to enable forward and reverse movement of the DC motor
 The transistor switches also provide electrical protection for the ATMEL microcontroller unit from the voltage spikes produced by the motors. The transistor used is TIP102 (npn).

Stepper Motor
The stepper motor we use has four coils which, when energized in the correct sequence, cause the permanent magnet attached to the shaft to rotate. Reversing the order of the steps in a sequence will reverse the direction of rotation. In our project we used the stepper motor to provide steering and also to move the camera mount rack. Since the mechanical design requires the stepper motor to have a big torque, we used the 'two-coil excitation' stepping sequence. In this stepping sequence, each successive pair of adjacent coils is energized in turn

  This stepping sequence however doesn't provide smooth movements and uses more power compared to the normal stepping sequence but produces greater torque.
DC Motor
We use a 3V DC motor to provide forward and reverse movement for the MLV. We found that this DC motor consumes a lot of power, thus very inefficient.

Planetary Gear System
A planetary gear train is a mechanism consisting of an assembly of meshed gears: the sun gear, the planet carrier, and the ring gear. A planetary gearset is used to reduce the 'weight' of the vehicle seen by the DC motor and increase its efficiency
 Differential Wheel System
Differential wheel system is widely used in modern vehicle due to its safety features. We used the differential wheel system simply because it is included in the Lego package and it looks really cool! 


Results The design goals were successfully met. The microcontroller unit appropriately scans for user input and drives the DC and stepper motors to provide motion to the vehicle. It successfully sets the speed of the vehicle from the value obtained from the onboard ADC and controls the signal lights.
The mechanical parts however proves to be quite a big challenge to us. With little mechanical experience, designing the model took a lot of our time. Mounting the motors on the vehicles produces inefficiencies that we didn't anticipated. However, after much tweaking we finally got a working model of the vehicle :)
Measurements
DC Motor
Voltage 4.5V
Current 500 - 800 mA
depending on the load
   
Stepper Motors
Voltage 12V
Current 200 - 500 mA
depending on the load

Future Improvements Given more time and resources, we would like to implement the following improvements:
  • A more robust mechanical model
    The mechanical model of the vehicles seems a little bit flimsy since it was made out of Lego pieces. We would also want a higher efficiency gear/lever systems implemented.
  • Feedback control systems
    The steering and camera mount would have a feedback control system that would give feedback if the maximum steering/height is reached. The feedback control system would turn the motor off to avoid damage to the mechanical parts.
  • LCD to display the current speed or condition of the vehicle.
   

0 comments to “Microcontroller-driven Lego Vehicle (MLV).”

Post a Comment

 

Engineering Projects Copyright © 2011 -- Template created by O Pregador -- Powered by Blogger