www.eXtremeElectronics.co.in

Differential Drive

AVR ATmega8 Bases Line Follower.

Easy to make PID LFR Robot.

Differential drive is a drive system in which both motion and steering can be done by two set of powered wheels. In differential drive their is a LEFT wheel and RIGHT wheels. Both are powered. It does not requires turning of front wheel for the steering like we steer car or bikes. To turn the vehicle (or robo) the LEFT and RIGHT wheels are rotated at "different" speeds. That's why its called differential drive. For example If the RIGHT wheels rotates faster than the LEFT wheels then the robot will turn towards LEFT.

For this robot we will use the following rotation of wheel for the steering and straight motion.


Motion LEFT Wheel RIGHT Wheel
Forward Counter Clockwise Clockwise
Backward Clockwise Counter Clockwise
Rotate LEFT Clockwise Clockwise
Rotate RIGHT Counter Clockwise Counter Clockwise

The following diagram explains robots differential drive in details

Robotic Differential Drive System

Fig. 1 - Differential Drive System

So moving and steering the robot is just the matter of controlling two DC motors. You can easily access DC motors from xAPI.

Once you go through the articles you know how to start a particular motor either in CW or CCW direction. Here MotorA will be the right motor and the MotorB will be the left motor. So the following code snippets does the job.

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);	//Right Motor Moves Clockwise (CW) with Full Speed (255)
MotorB(MOTOR_CW,255); //Left 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)

I have explained the code here so it does not create confusion when the whole program (which is reasonably large)of the robot is presented to you.

To know more about the functions MotorA and MotorB please see their documentation here.

Sample Code #1

This code moves the robot forword for some time (t) and then moves the robot backwords for same time (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);

}

HEX File Ready to Burn

The hex file ready to burn can be found in the Precompiled HEX Files folder in the Support DVD.

Sample Code #2

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.


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

                 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);

}

HEX File Ready to Burn

The hex file ready to burn can be found in the Precompiled HEX Files folder in the Support DVD.

Sample Code #3

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.

This effect is achived my running the left wheel slow in comparision to the right wheel.


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

                 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);

}

Sample Code #4

Zig Zag motion demo.


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

                 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);
   }

}

HEX File Ready to Burn

The hex file ready to burn can be found in the Precompiled HEX Files folder in the Support DVD.

 

Return to Help Index.