Use of Motors

Project Goals

Familiarize user with the robot motor control functions

Using the motors and their functions to maneuver the robot and perform specific tasks.

Equipment needed

PC or Laptop Computer equipped with MPLAB IDE

PIC32 Starter kit

Robot Platform

Lab Prerequisite:

User need to be familiar with the concept of functions in C programming language.

Pre Lab Activities:

Study the tutorial for this lab and do the sample project

Safety concerns

There are no safety concerns

Tips:

Make sure the following line is included in program before main () routine.

#include "System.h"

Make sure following line is included in first line of code in the main() routine

InitRobot();

Required Tasks and Exercises:

First task: Make the robot go forward for 3 seconds, then turn right for 1 second, then stop and turn left for 1 second, and then stop completely.

Second task: Make the robot turn left in place slowly and increase the speed of turning every 2 seconds by 10 units until it reach the maximum allowable speed. Then slow down the turn speed every 2 second by 10 units until the speed reach zero speed.

Third task: Add necessary code to the code developed for task two so the speed or the left and right robot is displayed on the LCD screens as follows:

Line 1: MOTOR CONTROL DEMO

Line2: Empty line

Line3: Left: <speed> Right :< speed>

Tutorial:

To grant the mobile robot its mobility we need wheels and with that we need some kind of mechanism to drive them. There are several different actuators that could undertake this task such as stepper motors, brushless DC motors, Servo Motors, AC induction motors. For this robot however we chose brushed DC motors (BDC) since they are the most economical and prevalent in market. The DC stands for direct current which is provided by the battery.

Robot maneuver technique

Going straight forward:

To go straight forward both right and left motor should have the same positive speed. In this case robot’s overall speed could be controlled by the speed set for right and left motors.

Going straight backward:

This is the same as going straight forward except that the speed should be negative.

Turn Right:

To turn right the left motor speed should be greater than right motor speed. The higher the differences between left and right motor speed, the sharper the turn would be (smaller turn radius). For example to achieve the zero turn radius (turning in place) one could set the left speed to a positive number and the right speed to the same speed but negative. To turn faster the speed could be increased.

TurnLeft:

Turning left could be achieved by setting the right motor speed higher than left motor speed.

Here is the description of the functions responsible for controlling the right and left motors.

Motor.SetRightSpeed

Description: This function set the speed of right motor. The range of speed could vary between -100 to 100. Negative numbers signify backward direction and positive numbers forward direction. Zero stops the motor.

Prototype: void SetRightSpeed (signed short int Speed)

Arguments: Speed: Desired speed for the right motor (Range -100 to 100)

Return Value: None

Motor.SetLeftSpeed

Description: This function set the speed of left motor. The range of speed could vary between -100 to 100. Negative numbers signify backward direction and positive numbers forward direction. Zero stops the motor.

Prototype: void SetLeftSpeed (signed short int Speed)

Arguments: Speed: Desired speed for the left motor (Range -100 to 100)

Return Value: None

Motor.GetRightSpeed

Description: This function returns the current speed of right motor.

Prototype: signed short int GetRightSpeed (void)

Arguments: None

Return Value: Current speed of the right motor (Range -100 to 100)

Motor.GetLeftSpeed

Description: This function returns the current speed of left motor.

Prototype: signed short int GetLeftSpeed (void)

Arguments: None

Return Value: Current speed of the left motor (Range -100 to 100)

Example:

To set left motor to go forward with 50% of power

Motor.SetLeftSpeed(50);

To set right motor to go backward with 80% of power

Motor.SeRightSpeed(-80);

Example: In this example the robot will turn counter clock wise for 0.5 second then it will stop and start spinning clockwise for 0.5 seconds and then stop completely.

/* This line should always be included in the code /*

#include “System.h"

int main( void)

{

/* This line should be the first line in main/*

InitRobot();

/* Turning counter clock wise in spot */

Motor.SetRigtSpeed(60);

Motor.SetLeftSpeed(-60);

/* wait for 0.5 second */

Delay.MilliSecond(500);

/* Stop turning */

Motor.SetRigtSpeed(60);

Motor.SetLeftSpeed(-60);

/* Turning clock wise in spot */

Motor.SetRigtSpeed(-60);

Motor.SetLeftSpeed(60);

/* wait for 0.5 second */

Delay.MilliSecond(500);

/* Stop turning */

Motor.SetRigtSpeed(60);

Motor.SetLeftSpeed(-60);

}

Robot Training Manual – Lesson 4Page 1