Sei sulla pagina 1di 8

DifferentialDrive

AVRATmega8BasesLineFollower.

EasytomakePIDLFRRobot.

Differentialdriveisadrivesysteminwhichbothmotionandsteeringcanbedonebytwosetofpoweredwheels.In

differentialdrivetheirisaLEFTwheelandRIGHTwheels.Botharepowered.Itdoesnotrequiresturningoffront

wheelforthesteeringlikewesteercarorbikes.Toturnthevehicle(orrobo)theLEFTandRIGHTwheelsare

rotatedat"different"speeds.That'swhyitscalleddifferentialdrive.ForexampleIftheRIGHTwheelsrotatesfaster

thantheLEFTwheelsthentherobotwillturntowardsLEFT.

Forthisrobotwewillusethefollowingrotationofwheelforthesteeringandstraightmotion.

Motion

LEFTWheel

RIGHTWheel

Forward

CounterClockwise

Clockwise

Backward

Clockwise

CounterClockwise

RotateLEFT

Clockwise

Clockwise

RotateRIGHT

CounterClockwise

CounterClockwise

Thefollowingdiagramexplainsrobotsdifferentialdriveindetails

RoboticDifferentialDriveSystem

RoboticDifferentialDriveSystem

Fig.1­DifferentialDriveSystem

SomovingandsteeringtherobotisjustthematterofcontrollingtwoDCmotors.YoucaneasilyaccessDCmotors

fromxAPI.

OnceyougothroughthearticlesyouknowhowtostartaparticularmotoreitherinCWorCCWdirection.Here

MotorAwillbetherightmotorandtheMotorBwillbetheleftmotor.Sothefollowingcodesnippetsdoesthejob.

Move Robo Forward

MotorA(MOTOR_CW,255);

//Right Motor Moves Clockwise (CW) with Full Speed (255)

MotorB(MOTOR_CCW,255); //Left Motor Moves Counter Clockwise (CCW) with Full Speed (255)

Move Robo Backward

MotorA(MOTOR_CCW,255); //Right Motor Moves Counter Clockwise (CCW) with Full Speed (255) MotorB(MOTOR_CW,255); //Left Motor Moves Clockwise (CW) with Full Speed (255)

Rotate Robo Left

MotorA(MOTOR_CW,255);

MotorB(MOTOR_CW,255); //Left Motor Moves Clockwise (CW) with Full Speed (255)

//Right Motor Moves Clockwise (CW) with Full Speed (255)

Rotate Robo Right

MotorA(MOTOR_CCW,255); //Right Motor Moves Counter Clockwise (CCW) with Full Speed (255) MotorB(MOTOR_CCW,255); //Left Motor Moves Counter Clockwise (CCW) with Full Speed (255)

Ihaveexplainedthecodeheresoitdoesnotcreateconfusionwhenthewholeprogram(whichisreasonably

large)oftherobotispresentedtoyou.

ToknowmoreaboutthefunctionsMotorAandMotorBpleaseseetheirdocumentationhere.

SampleCode#1

Thiscodemovestherobotforwordforsometime(t)andthenmovestherobotbackwordsforsametime(t).

/*********************************************************************

LFR Board Sample Programs

‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

Description : Demonstrate forward and backward motion of robot.

Author

: Avinash Gupta 2012

Web

: www.eXtremeElectronics.co.in

**********************************************************************/

#include <avr/io.h> #include <util/delay.h>

#include "lib/motor/motor.h"

//Simple Delay Function void Wait();

void main()

{

//Initialize motor subsystem MotorInit();

while(1)

{

//Move Robot Forward

MotorA(MOTOR_CW,255);

MotorB(MOTOR_CCW,255);

//Wait

Wait();

//Move Robot Backward

MotorA(MOTOR_CCW,255);

MotorB(MOTOR_CW,255);

}

//Wait

Wait();

}

void Wait()

{

uint8_t i;

for(i=0;i<250;i++)

_delay_loop_2(0);

}

HEXFileReadytoBurn

ThehexfilereadytoburncanbefoundinthePrecompiledHEXFilesfolderintheSupportDVD.

PrecompiledHEXFiles folderintheSupportDVD. DiffDriveDemo1 SampleCode#2

DiffDriveDemo1

SampleCode#2

Turingdemo.Thiswillshowyouhowtomakeleftandrightturns.Therobotrotatesleftfromsometimethenrotates

rightforsometime.Thisprocessisrepeatedaslongastherobotissuppliedwithpower.

/*********************************************************************

LFR Board Sample Programs

‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

Description : Turing demo. This will show you how to make left and right turns. The robot rotates left from some time then rotates right for sometime. This process is repeated as long as the robot is supplied with power.

Author

: Avinash Gupta 2012

Web

: www.eXtremeElectronics.co.in

**********************************************************************/

#include <avr/io.h> #include <util/delay.h>

#include "lib/motor/motor.h"

//Simple Delay Function void Wait();

void main()

{

//Initialize motor subsystem MotorInit();

while(1)

{

//Turn Robot Right

MotorA(MOTOR_CW,255);

MotorB(MOTOR_CW,255);

//Wait

Wait();

//Turn Robot Left

MotorA(MOTOR_CCW,255);

MotorB(MOTOR_CCW,255);

}

//Wait

Wait();

}

void Wait()

{

uint8_t i;

for(i=0;i<250;i++)

_delay_loop_2(0);

}

HEXFileReadytoBurn

ThehexfilereadytoburncanbefoundinthePrecompiledHEXFilesfolderintheSupportDVD.

PrecompiledHEXFiles folderintheSupportDVD. DiffDriveDemo2 SampleCode#3

DiffDriveDemo2

SampleCode#3

Thiswillshowyouhowtomakeyourrobottaketurnwhilemovingforward.Thatmeanstherobotwillkeepmoving

forwardwhilealwaystakingaslowleftturn.Thiswillmakerobotgoroundinananti­clockwisecircle.

Thiseffectisachivedmyrunningtheleftwheelslowincomparisiontotherightwheel.

/*********************************************************************

LFR Board Sample Programs

‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

Description : Turing demo. This will show you how to make your robot take

turn while moving forward. That means the robot will keep moving forward while always taking a slow left turn. This will make robot go round in an anti‐clock wise circle.

Author

: Avinash Gupta 2012

Web

: www.eXtremeElectronics.co.in

**********************************************************************/

#include <avr/io.h> #include <util/delay.h>

#include "lib/motor/motor.h"

void main()

{

//Initialize motor subsystem MotorInit();

//Run the left motor (B) slow in comparison to right motor. //This will make the robot take left turn while moving forward.

MotorA(MOTOR_CW,255);

MotorB(MOTOR_CCW,128);

}

SampleCode#4

ZigZagmotiondemo.

/*********************************************************************

LFR Board Sample Programs

‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

Description : Zig‐Zag Motion demo

Author

: Avinash Gupta 2012

Web

: www.eXtremeElectronics.co.in

**********************************************************************/

#include <avr/io.h> #include <util/delay.h>

#include "lib/motor/motor.h" #include "lib/led/led.h"

void Wait();

void main()

{

//Initialize motor subsystem MotorInit();

//Initialize LED subsystem LEDInit();

LEDOn(1);

MotorA(MOTOR_CW,128);

MotorB(MOTOR_CCW,255);

Wait();

while(1)

{

LEDOn(5);

LEDOff(1);

MotorA(MOTOR_CW,255);

MotorB(MOTOR_CCW,128);

Wait();

Wait();

LEDOn(1);

LEDOff(5);

MotorA(MOTOR_CW,128);

MotorB(MOTOR_CCW,255);

Wait();

Wait();

}

}

void Wait()

{

uint8_t i;

for(i=0;i<60;i++)

{

_delay_loop_2(0);

}

}

HEXFileReadytoBurn

ThehexfilereadytoburncanbefoundinthePrecompiledHEXFilesfolderintheSupportDVD.

Thehexfilereadytoburncanbefoundinthe PrecompiledHEXFiles folderintheSupportDVD. DiffDriveDemo4 Returnto HelpIndex .

DiffDriveDemo4

ReturntoHelpIndex.

Copyright2008­2012AvinashGupta

DocumentVersion1.0(29June2012)