Servomotor-based mobile robot control


Project description:
 Mobile robots are used in many industrial, commercial, research, and hobby applications. This project is about the control of a mobile robot using servomotors. The robot used in this project is the base of a popular mobile robot known as Boe Bot, developed by Parallax (www.parallax.com and www.stampinclass.com). The basic robot is controlled from a Basic Stamp controller (Trademark of Parallax Inc.). The robot base and electronic circuit have been modified by the author so that the robot can be used with PIC microcontrollers
( Figure 1). The robot consists of two side drive wheels and a caster wheel at the back. The drive wheels are connected to servomotors. A breadboard is placed on the robot base for the electronic control circuit. The robot is driven from a 9V battery, and a 78L05-type voltage regulator is used to obtain _5V to supply power to the microcontroller circuit. In this project programs are developed to move the robot forward, backward, and to turn left and right.

Figure 1 Robot used in the project

Hardware:
The circuit diagram of the project is shown in Figure 2. In this project a PIC16F84 microcontroller is used and the microcontroller is operated with a 4 MHz crystal. Operating the servomotor As described in Section 4.7 the servomotors used in robotic applications are modified servos where the motor can rotate in either direction continuously by applying pulses to the servomotor. In a modified servomotor typically a pulse with a width of 1.3 ms rotates the motor clockwise at full speed. A pulse with a width of 1.7 ms rotates the motor anti-clockwise, and a pulse with a width of 1.5 ms stops the motor. Figure 3 shows typical pulses used to drive modified servomotors. The pulse required to operate a servomotor can very easily be obtained using the PULSOUT statement of the PicBasic and PicBasic Pro compilers. When a 4 MHz crystal is used, the time interval of PULSOUT is in units of 10_s. For example, the following PicBasic statement generates a pulse with a width of 1.3 ms from bit 0 of PortB (1.3 ms _ 1300_s and 1300/10 _ 130):
PULSOUT 0, 130


Figure 2 Circuit diagram

Servomotors are used to drive the left wheel and the right wheel. A servomotor has three leads: power supply, ground, and the signal pin. Left servomotor is connected to bit 0 of PORTB (RB0), and right servomotor is connected to bit 1 of PORTB (RB1). Although some servomotors can operate with _5V supply, most servomotors require 6–9V to operate. Similarly, the following PicBasic statement generates a pulse with a width of 1.7 ms from bit 1 of PORTB:
PULSOUT 1, 170
   A single pulse rotates the servomotor by a small amount. For a continuous rotation we have to
apply the pulses continuously. In most applications a loop is formed in software and pulses are
sent to the servomotor continuously. A delay is inserted between each pulse. The duration of this
delay determines the speed of the motor and about 20 ms is most commonly used value. The following PicBasic (or PicBasic Pro) code shows how a servomotor connected to port RB0
can be rotated clockwise continuously:

Loop: PULSOUT 0, 130                                             ‘ Send a pulse
PAUSE 20                                                                  ‘ Wait 20 ms
GOTO Loop                                                                ‘ Repeat

Similarly, the following PicBasic (or PicBasic Pro) code shows how a servomotor connected to
port RB1 can be rotated anti-clockwise continuously:

Loop: PULSOUT 1, 170                                                ‘ Send a pulse
PAUSE 20                                                                      ‘ Wait 20 ms
GOTO Loop                                                                    ‘ Repeat


Figure 5.147 Pulses used to drive modified servomotors

You can experiment by varying the pulse width and the delay to see how the speed of the motor
changes.

Forward movement
Assuming that two side wheels are connected to servomotors, the robot moves forward when
·         Left wheel rotates anti-clockwise
·         Right wheel rotates clockwise
In this project, the left servomotor is connected to port pin RB0 and right servomotor is connected to port pin RB1. The following PicBasic (or PicBasic Pro) code can then be used to move the robot forward:

Forward:           
 PULSOUT 0, 170                                    ‘ Left wheel anti-clockwise
PULSOUT 1, 130                                     ‘ Right wheel clockwise
PAUSE 20                                                 ‘ Wait 20 ms
GOTO Forward                                           ‘ Repeat
Backward movement
Assuming that the two side wheels are connected to servomotors, the robot moves backward when
·         Left wheel rotates clockwise
·         Right wheel rotates anti-clockwise
In this project, the left servomotor is connected to port pin RB0 and right servomotor is connected to port pin RB1. The following PicBasic (or PicBasic Pro) code can then be used to move the robot backward:

Backward:
 PULSOUT 0, 130                                          ‘ Left wheel clockwise
PULSOUT 1, 170                                          ‘ Right wheel anti-clockwise
PAUSE 20                                                      ‘ Wait 20 ms
GOTO Backward                                           ‘ Repeat

Moving the robot for required amount of time

                               The code given above moves the robot forward or backward continuously. There are applications where we may want to mode the robot only required amount of time. For example, we may want to move the robot forward for 5 s, then stop for 3 s, and then move backward for 2 s.

We can adjust the movement time by using a FOR loop. The following code shows how we can
move the robot forward using a FOR loop:

FOR J _ 1 TO M
PULSOUT 0, 170
PULSOUT 1, 130
PULSOUT 20
NEXT J

In this code variable M determines the number of times the loop is executed. Ignoring the small time taken by the FOR and the NEXT statements, the time taken to execute only one iteration of the FOR loop can be determined approximately as

FOR J _ 1 TO M                                                            
PULSOUT 0, 170
PULSOUT 1, 130
PULSOUT 20
NEXT J
Thus, if the robot is required to move for T seconds (1000 x T ms) forward or backward, the value of M to be used in the FOR loop can be calculated as follows:
M  x 1000 x T/23
An example is given below.

Example 1
A mobile robot is controlled with two servomotors as shown in Figure 2. Write a PicBasic
program which will perform the following operations:
·         Move the robot forward for 4 s
·         Wait for 5 s
·         Move the robot backward for 3 s
·         Stop

Solution 1
The first action is to move the robot forward for 4 s. Thus, the value of M is M  x 4000/23 x 174
Then the robot is required to stop for 5 s and then move backward for 3 s. The value of M for this
movement is M x 3000/23 x 130 The program is very simple and consists of only a few lines.
PicBasic program for this example is given in Figure 4.

 ‘*************************************************************************
 ‘ ROBOT CONTROL
‘ ===============
 ‘ In this project a mobile robot is controlled. The robot has two side wheels and
‘ a back caster wheel. Side wheels are connected to servomotors as follows:
§  Left wheel RB0
§  Right wheel RB1
 ‘ In this project the robot moves as follows:
·          Move the robot forward for 4 seconds
·          Wait for 5 seconds
·          Move the robot backward for 3 seconds
·          Stop
 ‘ A PIC16F84 type microcontroller is used with a 4 MHz crystal
‘*************************************************************************

Figure 4(Continued)

 ‘ Symbols
Symbol PORTB = $06 ‘ PORTB address
Symbol TRISB = $86 ‘ TRISB address
Symbol J = B0
POKE TRISB, 0 ‘ PORTB is output
‘ Move the robot forward for 4 seconds
FOR J = 1 TO 174
PULSOUT 0, 170
PULSOUT 1, 130
PAUSE 20
NEXT
‘ Wait for 5 seconds
PAUSE 5000
‘ Move the robot backward for 3 seconds
FOR J = 1 TO 130
PULSOUT 0, 130
PULSOUT 1, 170
PAUSE 20
NEXT J
END ‘ End of program
Figure 4 PicBasic program for Example 1

Measuring the speed of the robot
The speed of the robot can easily be measured by moving it for a known amount of time and measuring the distance moved during this time. The speed is then given by Speed  x distance/time In this project the robot moved forward for 10 s and the distance moved was 210 cm. Thus, the speed of the robot is 210/10 x 21 cm/s.

Once we know the speed, we can move the robot forward or backward by any required amount. For example, to move the robot forward by 85 cm, the required time is approximately given by Time x distance/speed x 85/21 x 4 Thus, the servomotors should be operated for 4 s. The value of loop-count M is then approximately given by M  x 4000/23 x 174.
The required PicBasic code is
FOR J _ 1 TO 174
PULSOUT 0, 170
PULSOUT 1, 130
PULSOUT 20
NEXT J

Turning left and right
Several techniques can be used to turn the robot left or right. One technique is to stop the servomotor on the side where we wish to turn. For example, we can turn right by stopping the right servo and turning the left servo anti-clockwise. Another technique of turning a robot smoothly involves rotating both servos in the same direction and this is the technique we shall be using here. For example,
To turn RIGHT:
·         Rotate left wheel anti-clockwise
·         Rotate right wheel anti-clockwise
To turn LEFT:
·         Rotate left wheel clockwise
·         Rotate right wheel clockwise
The problem here is how many pulses to send to the servomotors so that the robot turns a complete 90° angle. This is something which can be found by trial and error. The following PicBasic code rotates the robot right where the angle of rotation depends on
variable R:

Turn_right:
    
FOR J _ 1 TO R
PULSOUT 0, 170                                           ‘ Left wheel anti-clockwise
PULSOUT 1, 170                                           ‘ Right wheel anti-clockwise
PAUSE 20                                                      ‘ Wait 20 ms
NEXT J
Similarly, the following code rotates the robot left where the angle of rotation depends on variable R:

Turn_left:

FOR J _ 1 TO R
PULSOUT 0, 130                                                            ‘ Left wheel clockwise
PULSOUT 1, 130                                                            ‘ Right wheel clockwise
PAUSE 20                                                                       ‘ Wait 20 ms
NEXT J
It was found by experimentation that when R [r5] is equal to 13 the robot turns by about 90°. An
example is given below.

Example 2
A mobile robot is controlled with two servomotors as shown in Figure 2, and a pen is attached to the front of the robot with the tip of the pen touching the floor. Write a PicBasic program which will move the robot as follows: Move the robot forward for 5 s
·         Wait for 2 s
·         Turn right
·         Move the robot forward for 3 s
·         Stop

Solution 2
The first action is to move the robot forward for 5 s. Thus, the value of M is
M  x  5000/23 x 217. Then the robot is required to stop for 2 s and then turn right and move backward for 3 s. The value of M for this movement is M x 3000/23 x 130
PicBasic program for this example is given in Figure 5.
 ‘**************************************************************************
 ‘ ROBOT CONTROL
‘ ===============
 ‘ In this project a mobile robot is controlled. The robot has two side wheels and
‘ a back caster wheel. Side wheels are connected to servomotors as follows:
§  Left wheel RB0
§  Right wheel RB1
 ‘ In this project the robot moves as follows:
§  Move the robot forward for 4 seconds
§   Wait for 2 seconds
§   Turn right
§   Move the robot forward for 3 seconds
§   Stop
‘ A PIC16F84 type microcontroller is used with a 4 MHz crystal
 ‘***********************************************************************
 ‘ Symbols
Symbol PORTB = $06                                             ‘ PORTB address
Symbol TRISB = $86                                               ‘ TRISB address
Symbol J = B0
POKE TRISB, 0                                                       ‘ PORTB is output
Figure 5 (Continued)
 ‘ Move the robot forward for 4 seconds
FOR J = 1 TO 217
PULSOUT 0, 170
PULSOUT 1, 130
PAUSE 20
NEXT J
 ‘ Wait for 2 seconds
PAUSE 2000
 ‘ Turn right
FOR J = 1 TO 13
PULSOUT 0, 170
PULSOUT 1, 170
PAUSE 20
NEXT J
 ‘ Move the robot forward for 3 seconds
FOR J = 1 TO 130
PULSOUT 0, 170
PULSOUT 1, 130
PAUSE 20
NEXT J
END ‘ End of program
Figure 5 PicBasic program for Example 2

0 comments:

Post a Comment

 
Copyright Electronics Projects And Details All Rights Reserved
ProSense theme created by Dosh Dosh and The Wrong Advices.
Blogerized by Alat Recording Studio Rekaman.