Sie sind auf Seite 1von 12

Project Features: ATMega16 Microcontroller The ATMega16 monitors all robot sensors and controls motor drive functions.

. In system programming is available. Microcode was developed using the MCS Bascom AVR compiler. Obstacle avoidance The robot maneuvers around obstacles while seeking for a black line to track. Obstacles cause direction reversal when the robot is in line tracking mode. The obstacle sensor is a Sharp GP2D15 sensor connected to INT0 of the ATMega16. Line tracking The robot is designed to search for a black line on the terrain. Once the line is found, the robot tracks the line from end to end and reverses direction when it encounters an obstacle in the path of the line. Three infrared sensors mounted under the robot and connected to port D of the Mega16 do line sensing. Differential Drive Two DC motors provide mechanical propulsion through friction drive of the drive wheels. The motors are electrically driven by two Allegro 3953 full bridge motor drivers connected to port A of the ATMega16. Drive Wheel Synchronization Infrared wheel encoders and a microcode routine provide wheel synchronization. This allows for straight-line travel without guidance. Rechargeable Battery Pack Power is provided by a rechargeable 9.6 Volt NiCad battery pack. There is a 5 Volt on-board regulator for logic power.

Project Number A3743 Autonomous Robot


With obstacle avoidance, drive wheel synchronization and line tracking capability

Documentation

Figure 1 - AUTONOMOUS ROBOT

2004 AVR DESIGN CONTEST PROJECT NUMBER A3743 / AUTONOMOUS ROBOT BRIEF DESCRIPTION This project is an autonomous robot that is capable of obstacle avoidance, drive wheel synchronization and line tracking. The robot initializes in seek mode, where it avoids obstacles and searches for a black line to track. Wheel synchronization, during seek mode, allows the robot to travel in a straight line without guidance. Once a black line is found, the robot tracks the line and reverses direction when an obstacle is encountered on the line. The electronic control assembly consists of an Atmel ATMega16 MCU operating at 8Mhz with an internal clock. Two Allegro 3953 full-bridge motor drivers are used for motor control. Microcode for the project was written using the MCS Basic-AVR compiler. Microcode can be updated using the on-board ISP connector. The Mechanical assembly uses a differential drive system made from two small DC motors, a friction drive system and two 78mm wheels. There are six on-board sensors that allow the robot to avoid obstacles, synchronize wheel rotation and track lines. Power is provided by a rechargeable 9.6V NiCad battery pack.

Figure 2 - ROBOT IN LINE TRACKING MODE

2004 AVR DESIGN CONTEST PROJECT NUMBER A3743 / AUTONOMOUS ROBOT BLOCK DIAGRAM

PORT D

INT0 PORT A

2004 AVR DESIGN CONTEST PROJECT NUMBER A3743 / AUTONOMOUS ROBOT CIRCUIT DESCRIPTION The Atmel ATMega16 MCU performs all sensor monitoring and motor control functions. The clock is sourced to internal with a setting of 8Mhz. External Interrupt 0 is connected to the obstacle sensor. Port A interfaces to the motor drivers and Port D connects to the remaining sensors. MOSI, MISO, SCK and Reset are connected to the ISP connector so that microcode modifications can be made in circuit. Allegro A3953SB Full Bridge Motor Drivers are capable of continuous drive voltage of 50V and current of 1.3 A. Our requirements are 9.6V and 500ma. Current limiting and pulse width modulation are built in to the device. We have these features disabled because of the low current needs of our motors and the desire to control motor speed programmatically. Connecting the Sense pin to ground and leaving RC and Ref disconnected disabled the features. The Mode pin is tied high, thus allowing us to control motor functions with three bits for each motor. We use Brake, Enable and Phase connected to Port A of the ATMega16 for all motor drive functions.

Allegro A3953SB Truth Table


Brake H H H H H H L L Enable H H L L L L X X Phase X X H H L L X X Mode H L H L H L H L OutA Off Off H H L L L L OutB Off Off L L H H L L Description Sleep Mode Standby Forward, fast current decay Forward, slow current decay Reverse, fast current decay Reverse, slow current decay Brake, fast current decay Brake, no current

The Sharp GP2D15 obstacle sensor is connected to External Interrupt 0 and is services by the Int0 service routine. The sensor can interrupt the MCU at any time and has priority over all other functions. An obstacle is detected if it is within 15 inches of the sensor. The line sensor is comprised of three Fairchild QRD1113 IR reflective sensors, mounted on the front underside of the robot. The sensors are biased to provide logic 1 levels to Port D when they are over a black line and logic 0 when they are over a lighter area. Altering either the emitter output or the detector current can change sensor sensitivity. The wheel encoders are very simple. An IR LED is mounted on one side of each wheel and an IR phototransistor on the other. The wheels have spokes that interrupt the IR light being passed through the wheel. There are 13 spokes, thus we get 13 pulses per wheel rotation. This is useful for synchronizing wheel rotation, a must for traveling in a controlled direction without guidance. A 9.6V NiCad rechargeable battery pack and the LM7805 voltage regulator provide power. The motor drivers operate from 9.6V while all Vcc is 5.0V. The battery is disconnected from the robot during charging from a battery charger.

2004 AVR DESIGN CONTEST PROJECT NUMBER A3743 / AUTONOMOUS ROBOT MECHANICAL DESCRIPTION The robot mechanical assembly is made from common materials. The base plate is aluminum that measures 4 X 6.5 X .125. A hollow brass tube is attached to the plate, at a position 1/3 from the front, with small screws to form the axle. The axle is hollow to allow wires to pass to the wheel encoder LEDs without having to route them around the wheels. A thin wooden block is positioned in front of the axle and mounted with epoxy. The wooden block and base plate form a cradle for the drive motors, which are held in position, under tension, with rubber bands. The motor shafts come in friction contact with the 78mm wheels and drive them thusly. The wheels are in-line skate wheels with standard ball bearings. This makes for a very smooth mechanism that is easily assembled. A small roller or caster is mounted to the rear chassis underside, it can be seen in figure 4 and 5.

Figure 3 - The Bare Chassis

Figure 4 - With Motors and Sensors Mounted

The following figures should give you a pretty good idea of how the rest is assembled. An important detail on motor position can be seen in figure 5. The cradle must be such that the motors are hanging slightly over the front of the chassis and are slightly higher than the cradle block. This is necessary so that the rubber bands can keep the motors under tension. The battery is positioned to balance the robot so that the majority of its mass is on the drive wheels.

Figure 5 - Side View

Figure 6 - Completed Project

2004 AVR DESIGN CONTEST PROJECT NUMBER A3743 / AUTONOMOUS ROBOT FLOW CHART

Initialize Variables and Constants Enable Interrupt 0 and Global Interrupt Enter Seek Mode

Yes Obstacle Detected? No No Black Line Detected? Yes Line Tracking Mode Backup and spin right 90 degrees No Obstacle Detected? Yes

Yes Obstacle Detected? No No Adjust Motor Drive Left or Right Is the Black Line Centered? Yes Reverse Direction

2004 AVR DESIGN CONTEST PROJECT NUMBER A3743 / AUTONOMOUS ROBOT SOURCE CODE LISTING Microcode for this project was written with the MCS Basic-AVR compiler.
'2004 AVR DESIGN PROJECT 'PROJECT # A3743 'AUTONOMOUS ROBOT 'With obstacle avoidance, wheel synchronization and line 'tracking capability '-------------------------------------------------------------$regfile = "m16def.dat" $crystal = 8000000

'We are using the 8Mhz internal clock

Dim Gp0 As Byte , Gp1 As Byte , Gp2 As Byte 'General Purpose registers Dim Leftc As Integer , Rightc As Integer 'Wheel pulse counters Dim Left_flag As Bit , Right_flag As Bit 'Wheel flip flop flags Dim Op_mode As String * 5 'Operating mode, i.e. seek or track 'Motor drive constants Const Forth = &H66 'Forward Const Rev = &H44 'Reverse Const Spinr = &H64 'Spin right Const Spinl = &H46 'Spin left Const Turnl = &H16 'Turn left Const Turnr = &H61 'Turn right Const Brake = &H11 'Stop Const Pause = &H55 'No drive or brake Const Pulse_width = &H0A 'Pulse width constant, controls motor speed in track mode. Motor Alias Porta Lsense Alias Pind.0 Rsense Alias Pind.1 Csense Alias Pind.3 Osense Alias Pind.2 Lwheel Alias Pind.4 Rwheel Alias Pind.5 'Motor driver output port 'Left line sensor ,0 = on line 'Right line sensor , 0 = on line 'Center line sensor, 0 = on line 'Obstacle sensor, 1 = obstacle sense 'Left wheel encoder 'Right wheel encoder

Config Int0 = Rising 'Obstacle sensor on INT0, Trigger on rising edge Config Pind.2 = Input 'Used as Int0 for obstacle sensor Config Porta = Output 'Use port A for output 'PA.0 = /enable PA.1 = Phase PA.2 = /Brake Right Motor 'PA.4 = /enable PA.5 = Phase PA.6 = /Brake Left Motor 'PD.0 = left line sensor PD.1 = right line sensor PD.2 = Center line sensor On Int0 Int0_isr Enable Int0 Enable Interrupts Wait 3 Main: '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Seek_line: 'Roam around, avoid obstacles, seek the black line Leftc = 0 'Initialize wheel counters 'Point to the Interrupt 0 Service routine

'Delay after power on

Rightc = 0 Motor = Forth 'Go forward Seek_line1: Op_mode = "seek" Gosub Poll_wheels If Csense = 1 Then 'Center line sensor found black line Motor = Brake 'Stop Waitms 300 'pause Goto Track 'Goto track mode End If Motor = Forth 'Give both motors a forward pulse Gp2 = Rightc + 2 'General Purpose reg = right counter + 2 If Leftc > Gp2 Then 'Is the left wheel 2 pulses ahead of the right wheel? Motor = Turnl 'Adjust End If Gp2 = Leftc + 2 'General Purpose reg = left counter + 2 If Rightc > Gp2 Then 'Is the right wheel 2 pulses ahead of the left wheel? Motor = Turnr 'Adjust End If If Leftc > 130 Then 'Clear the wheel counters after 10 wheel revolutions Rightc = 0 Leftc = 0 End If Goto Seek_line1 '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Track: 'Line Track Mode Op_mode = "track" Motor = Forth 'Go forward Track1: Gp1 = Pind And 3 'Gp1 = mask portd input, read right and left line sensors On Gp1 Gosub Null_sub , Turn_left , Turn_right , About_face 'Take appropriate action. Goto Track1 '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Turn_left: Motor = Brake Motor = Turnl Waitms Pulse_width 'This pause adjusts the motor pulse width Return '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Turn_right: Motor = Brake Motor = Turnr Waitms Pulse_width 'This pause adjusts the motor pulse width Return '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Null_sub: Motor = Brake Motor = Forth Waitms Pulse_width 'This pause adjusts the motor pulse width Return '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * About_face: 'This routine will make the bot turn around if the track has a T at the end Motor = Brake 'This routine is called if left and right sensors see the line simultaniously Waitms 500 Reverse: Motor = Rev 'Reverse

Waitms 200 'Clear the cross-line area Gp1 = Pind And 3 'Gp1 = mask portd input If Gp1 = 3 Then Goto Reverse 'If left and right line sensors both see black Motor = Brake 'Turn on the brake Wait 1 Right_spin: Motor = Spinr 'Spin right to clear the main -line Waitms 200 Right_spin_cont: Motor = Brake Motor = Spinr Waitms Pulse_width 'This pause adjusts the motor pulse width If Csense = 0 Then Goto Right_spin_cont 'Sp in until the center line sensor detects the line Motor = Brake 'Turn on the brake Wait 1 Return '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 'Returns (Leftc) the left wheel encoder count and (Rightc) the Right wheel encoder count. Poll_wheels: 'Polls the wheel encoder sensors and counts pulses. If Lwheel = 0 Then 'If left wheel encoder is uncovered If Left_flag = 1 Then 'Do this once each encoder sensor transition Incr Leftc 'Increment the wheel counter Reset Left_flag End If End If If Lwheel = 1 Then Set Left_flag 'Set the flag when the sensor is covered If Rwheel = 0 Then 'If right wheel encoder is uncovered If Right_flag = 1 Then 'Do this once each encoder sensor transition Incr Rightc 'Increment the wheel counter Reset Right_flag End If End If If Rwheel = 1 Then Set Right_flag 'Set the flag when the sensor is covered Return '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Int0_isr: 'Obstacle Sensor Interrupt 0 routine. Disable Int0 'No interrupt allowed during ISR Waitms 10 'Pause and re-check the obstacle sensor If Osense = 0 Then Goto False_obs 'Eliminate false obstacle detection If Op_mode = "seek" Then 'Do this if there is an obstacle sensed in seek mode Seek_obs: Motor = Brake Waitms 300 Motor = Rev Waitms 300 If Osense = 1 Then Goto Seek_obs 'Is the obstacle still there? Motor = Brake Waitms 300 Motor = Spinr 'Turn away from obstacle Waitms 500 End If If Op_mode = "track" Then Track_obs: Motor = Brake Waitms 300 Motor = Rev Waitms 300 'Do this if there is an obstacle sensed in track mode

If Osense = 1 Then Goto Track_obs 'Is the obstacle still there? Motor = Brake Waitms 300 Motor = Spinr 'Spin part way to clear the line sensors Waitms 200 Track_obs1: Motor = Brake Motor = Spinr Waitms Pulse_width 'This pause adjusts the motor pulse width If Csense = 0 Then Goto Track_obs1 'Spin until the center line sensor detects the line End If Motor = Brake Wait 1 False_obs: Enable Int0 'Enable interrupt0 Return End

Das könnte Ihnen auch gefallen