Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
in
AVRATmega8BasesLineFollower.
EasytomakePIDLFRRobot.
Differentialdriveisadrivesysteminwhichbothmotionandsteeringcanbedonebytwosetofpoweredwheels.In
differentialdrivetheirisaLEFTwheelandRIGHTwheels.Botharepowered.Itdoesnotrequiresturningoffront
wheelforthesteeringlikewesteercarorbikes.Toturnthevehicle(orrobo)theLEFTandRIGHTwheelsare
rotatedat"different"speeds.That'swhyitscalleddifferentialdrive.ForexampleIftheRIGHTwheelsrotatesfaster
thantheLEFTwheelsthentherobotwillturntowardsLEFT.
Forthisrobotwewillusethefollowingrotationofwheelforthesteeringandstraightmotion.
Thefollowingdiagramexplainsrobotsdifferentialdriveindetails
RoboticDifferentialDriveSystem
Fig.1DifferentialDriveSystem
SomovingandsteeringtherobotisjustthematterofcontrollingtwoDCmotors.YoucaneasilyaccessDCmotors
fromxAPI.
OnceyougothroughthearticlesyouknowhowtostartaparticularmotoreitherinCWorCCWdirection.Here
MotorAwillbetherightmotorandtheMotorBwillbetheleftmotor.Sothefollowingcodesnippetsdoesthejob.
MoveRoboForward
MotorA(MOTOR_CW,255); //RightMotorMovesClockwise(CW)withFullSpeed(255)
MotorB(MOTOR_CCW,255);//LeftMotorMovesCounterClockwise(CCW)withFullSpeed(255)
MoveRoboBackward
MotorA(MOTOR_CCW,255); //RightMotorMovesCounterClockwise(CCW)withFullSpeed(255)
MotorB(MOTOR_CW,255);//LeftMotorMovesClockwise(CW)withFullSpeed(255)
RotateRoboLeft
MotorA(MOTOR_CW,255); //RightMotorMovesClockwise(CW)withFullSpeed(255)
MotorB(MOTOR_CW,255);//LeftMotorMovesClockwise(CW)withFullSpeed(255)
RotateRoboRight
MotorA(MOTOR_CCW,255); //RightMotorMovesCounterClockwise(CCW)withFullSpeed(255)
MotorB(MOTOR_CCW,255);//LeftMotorMovesCounterClockwise(CCW)withFullSpeed(255)
Ihaveexplainedthecodeheresoitdoesnotcreateconfusionwhenthewholeprogram(whichisreasonably
large)oftherobotispresentedtoyou.
ToknowmoreaboutthefunctionsMotorAandMotorBpleaseseetheirdocumentationhere.
SampleCode#1
Thiscodemovestherobotforwordforsometime(t)andthenmovestherobotbackwordsforsametime(t).
/*********************************************************************
LFRBoardSamplePrograms
Description:Demonstrateforwardandbackwardmotionofrobot.
Author:AvinashGupta2012
Web:www.eXtremeElectronics.co.in
**********************************************************************/
#include<avr/io.h>
#include<util/delay.h>
#include"lib/motor/motor.h"
//SimpleDelayFunction
voidWait();
voidmain()
{
//Initializemotorsubsystem
MotorInit();
while(1)
{
//MoveRobotForward
MotorA(MOTOR_CW,255);
MotorB(MOTOR_CCW,255);
//Wait
Wait();
//MoveRobotBackward
MotorA(MOTOR_CCW,255);
MotorB(MOTOR_CW,255);
//Wait
Wait();
voidWait()
{
uint8_ti;
for(i=0;i<250;i++)
_delay_loop_2(0);
HEXFileReadytoBurn
ThehexfilereadytoburncanbefoundinthePrecompiledHEXFilesfolderintheSupportDVD.
DiffDriveDemo1
SampleCode#2
Turingdemo.Thiswillshowyouhowtomakeleftandrightturns.Therobotrotatesleftfromsometimethenrotates
rightforsometime.Thisprocessisrepeatedaslongastherobotissuppliedwithpower.
/*********************************************************************
LFRBoardSamplePrograms
Description:Turingdemo.Thiswillshowyouhowtomakeleftandrightturns.
Therobotrotatesleftfromsometimethenrotatesrightforsometime.
Thisprocessisrepeatedaslongastherobotissuppliedwithpower.
Author:AvinashGupta2012
Web:www.eXtremeElectronics.co.in
**********************************************************************/
#include<avr/io.h>
#include<util/delay.h>
#include"lib/motor/motor.h"
//SimpleDelayFunction
voidWait();
voidmain()
{
//Initializemotorsubsystem
MotorInit();
while(1)
{
//TurnRobotRight
MotorA(MOTOR_CW,255);
MotorB(MOTOR_CW,255);
//Wait
Wait();
//TurnRobotLeft
MotorA(MOTOR_CCW,255);
MotorB(MOTOR_CCW,255);
//Wait
Wait();
voidWait()
{
uint8_ti;
for(i=0;i<250;i++)
_delay_loop_2(0);
HEXFileReadytoBurn
ThehexfilereadytoburncanbefoundinthePrecompiledHEXFilesfolderintheSupportDVD.
DiffDriveDemo2
SampleCode#3
Thiswillshowyouhowtomakeyourrobottaketurnwhilemovingforward.Thatmeanstherobotwillkeepmoving
forwardwhilealwaystakingaslowleftturn.Thiswillmakerobotgoroundinananticlockwisecircle.
Thiseffectisachivedmyrunningtheleftwheelslowincomparisiontotherightwheel.
/*********************************************************************
LFRBoardSamplePrograms
Description:Turingdemo.Thiswillshowyouhowtomakeyourrobottake
turnwhilemovingforward.Thatmeanstherobotwillkeep
movingforwardwhilealwaystakingaslowleftturn.This
willmakerobotgoroundinananticlockwisecircle.
Author:AvinashGupta2012
Web:www.eXtremeElectronics.co.in
**********************************************************************/
#include<avr/io.h>
#include<util/delay.h>
#include"lib/motor/motor.h"
voidmain()
{
//Initializemotorsubsystem
MotorInit();
//Runtheleftmotor(B)slowincomparisontorightmotor.
//Thiswillmaketherobottakeleftturnwhilemovingforward.
MotorA(MOTOR_CW,255);
MotorB(MOTOR_CCW,128);
SampleCode#4
ZigZagmotiondemo.
/*********************************************************************
LFRBoardSamplePrograms
Description:ZigZagMotiondemo
Author:AvinashGupta2012
Web:www.eXtremeElectronics.co.in
**********************************************************************/
#include<avr/io.h>
#include<util/delay.h>
#include"lib/motor/motor.h"
#include"lib/led/led.h"
voidWait();
voidmain()
{
//Initializemotorsubsystem
MotorInit();
//InitializeLEDsubsystem
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();
}
voidWait()
{
uint8_ti;
for(i=0;i<60;i++)
{
_delay_loop_2(0);
}
HEXFileReadytoBurn
ThehexfilereadytoburncanbefoundinthePrecompiledHEXFilesfolderintheSupportDVD.
DiffDriveDemo4
ReturntoHelpIndex.
Copyright20082012AvinashGupta
www.eXtremeElectronics.co.in
DocumentVersion1.0(29June2012)
TermsofService|Warranty|Support|ContactUs