Top Topics

74*245 Motor Driver

H-Bridge Driver

Simple PWM Gen.

Handy Method Measuring RPM

Measuring RPM via Photo reflector

Introduction to Robotic

DC, Stepper,and Servo Motor

Related Link

Microcontroller Tutorial

Computer Interface
Tutorial

.............more links

 

 

 

BACK

Once this was accomplished, the sensors were introduced (Figure 1). Two pair of visible light emitter detector pairs were positioned at the front of the robot. The light emitters are high intensity red LEDs with a low viewing angle. The low viewing angle makes the light more unidirectional, like a laser and reduces interference between the two sensors. The detectors are photo resistors with black plastic surrounding them so that only a small circular region directly below the sensor will effect the detection of the paper color. The sensor pair work very well with a variety of imperfect paper surfaces. The photo resistors are set up in a voltage divider circuit to so that the output voltage varies about 1 volt under standard ambient lighting conditions and so that the trip point (1.4v) of the digital input to the microprocessor is in the center of this swing.

When one diode detects a black area, the PIC’s program decides which way to steer the robot such that the detectors will both see white paper. For instance if the left sensor sees black, it tell the processor to turn left. However if both resistors detect a black area, the motor stops until this condition changes. A “light shield” was added at the front of the robot to minimize interference from the lighting of the room (see the attached program flow, and assembly code).

Analysis and results:

The robot successfully navigated along a solid black line and came to rest when it reached an all-black area. The “light shield” was added as a result of sensitivity problems when the room’s lighting interfered with the sensing of the black line.

There are a few things that could be done differently to increase the accuracy and ability of the robot. A differential drive robot would increase the ability of the robot to navigate around sharper turns. As it is currently, the turning radius is quite large. If a standard steering scheme were used then a servo motor would be better suited for steering the robot so that gentle turns could be implemented instead of full left and full right being the only options.

At least two more sensors placed directly in front of the original two in order to create a 2D image of the work space would allow for greater accuracy, the ability to turn at 90 degrees (with differential steering), and higher speeds.

Conclusion

While the idea of a robot that steers itself to follow a solid line may at first seem like a difficult project, it can be accomplished with relative ease by using a PIC microcontroller to run the motor and control the steering of the robot based on the status of the two sensors.

Asembly Code:

; LINE FOLOWING ROBOT
;Written by James J. Cronmiller 11/09/02
;Processor: PIC16F873 running internal RC at 4MHz (1 uS per cycle)
;LIST P=16f873 ;list directive to define processor
include <P16F873.inc> ;PIC12C674 standard header file
ERRORLEVEL -302 ;suppress message 302 from list
_CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFFFF & 
_LVP_OFF & _CPD_OFF
;************* VARIABLE DEFINITIONS ********************
CBLOCK 0x20
COUNTER1
COUNTER2
COUNTER3
TOTAL_DUTY
ON_TIME_COUNT
ON_TIME
CYCLES
ENDC
;********************* Port b Bits *********************
CBLOCK 0x000
STEER_1 ; bit 0,
SENSOR_R ; bit 1,
STEER_3 ; bit 2,
STEER_4 ; bit 3,PNP
MOTOR ; bit 4,
SENSOR_L ; bit 5,
na ; bit 6,
STEER_2 ; bit 7, PNP
ENDC
;********************* Port C Bits *********************
CBLOCK 0x000
fREEC0 ; bit 0,
FREEC1 ; bit 1,
FREEC2 ; bit 2,
FREEC3 ; bit 3,
FREEC4 ; bit 4,
FREEC5 ; bit 5,
LED_L ; bit 6,
LED_R ; bit 7,
ENDC
;************* INTERNAL RC CALIBRATION ******************
ORG h'0000'
BSF STATUS,RP0
;***********************************************
;NOTE: ALL MAIN PROGRAM DATA IS IN THE SECOND HALF OF THE "PAGE"          
;****************** INITIALIZE *********************
INITIALIZE:
 BCF STATUS,RP1
 BSF STATUS,RP0
 MOVLW B'01100010' ;Set GPIO data direction register,
 MOVWF TRISB
 MOVLW B'00000000' ;Set GPIO data direction register,
 MOVWF TRISC
 MOVLW B'10011111' ;watchdog timer assigned to prescaler,
 MOVWF OPTION_REG ;prescaler set to max (2.3 sec)
 BCF STATUS,RP0 ;set file register bank to ZERO
 BCF PORTB,STEER_1 ;STER MOTOR OFF
 BSF PORTB,STEER_2
 BCF PORTB,STEER_3
 BSF PORTB,STEER_4
 BCF PORTB,MOTOR
 CLRF PORTC
HOLD:
 BSF PORTC,LED_L
 BSF PORTC,LED_R
 MOVLW .255 ;0.119mS DELAY SEQUENCE
 CALL DELAY21uS
 BCF PORTC,LED_L
 BCF PORTC,LED_R
START:
 MOVLW .5 ;0.119mS DELAY SEQUENCE
 CALL DELAY21uS
 BTFSC PORTB,SENSOR_L
 CALL T_L_T
 BTFSC PORTB,SENSOR_R
 CALL T_R_T
 MOVLW .12
 MOVWF ON_TIME
 MOVLW .1
 CALL MOTOR_FOWARD
 GOTO START
T_L_T:
 BTFSC PORTB,SENSOR_R
 GOTO HOLD
 CALL TURN_LEFT
 RETURN
T_R_T:
 BTFSC PORTB,SENSOR_L
 GOTO HOLD
 CALL TURN_RIGHT
 RETURN
TURN_LEFT:
 BSF PORTC,LED_L
 BCF PORTB,STEER_1 ;MOTOR LEFT
 BCF PORTB,STEER_2
 BSF PORTB,STEER_3
 BSF PORTB,STEER_4
 MOVLW .14
 MOVWF ON_TIME
 MOVLW .4
 CALL MOTOR_FOWARD
 BCF PORTB,STEER_1 ;MOTOR OFF
 BSF PORTB,STEER_2
 BCF PORTB,STEER_3
 BSF PORTB,STEER_4
 BCF PORTC,LED_L
 RETURN
TURN_RIGHT:
 BSF PORTC,LED_R
 BSF PORTB,STEER_1 ;MOTOR LEFT
 BSF PORTB,STEER_2 ;PNP
 BCF PORTB,STEER_3
 BCF PORTB,STEER_4 ;PNP
 MOVLW .14
 MOVWF ON_TIME
 MOVLW .4
 CALL MOTOR_FOWARD
 BCF PORTB,STEER_1 ;MOTOR OFF
 BSF PORTB,STEER_2
 BCF PORTB,STEER_3
 BSF PORTB,STEER_4
 BCF PORTC,LED_R
 RETURN
;******************************************************
;DUTY CYCLE CREATION OF MOTOR (W*2.4mS = CALL) ***
; SET DUTY CYCLE BY MODIFYING "ON_TIME" *********
;********************* PASS ON TIME THOUGH "W" REGISTER *
;******************************************************
MOTOR_FOWARD:
 MOVWF CYCLES
 DECF ON_TIME,F ;0 COUNTS AS A LOOP
LOOP_DELAYS:
 MOVF ON_TIME,W 
 ;SAVE INPUT W REGISTER DATA AS ON TIME (ON_TIME/20 = DC)
 MOVWF ON_TIME_COUNT
 MOVLW .19 ;20 IS TOTAL LOOPES USED (20*.119mS=2.4mS)
 MOVWF TOTAL_DUTY ;THUS TOTAL DUTY IS 20 
ON_TIME_LOOP:
 BSF PORTB,MOTOR ;TURN ON OUTPUT LOAD
 MOVLW .1 ;0.119mS DELAY SEQUENCE
 CALL DELAY6uSA 
 BCF PORTB,MOTOR ;TURN OFF OUTPUT LOAD (inverted)
 DECF TOTAL_DUTY,F ;WE HAVE X = X-1 TOTAL LOOPS LEFT
 DECFSZ ON_TIME_COUNT,F ;WE HAVE Y = Y-1 ON LOOPS LEFT
 GOTO ON_TIME_LOOP
OFF_TIME_LOOP:
 BCF PORTB,MOTOR ;TURN OFF OUTPUT LOAD (inverted)
 MOVLW .1 ;0.119mS DELAY SEQUENCE
 CALL DELAY6uSA
 DECFSZ TOTAL_DUTY,F ;WE HAVE X = X-1 TOTAL LOOPS LEFT
 GOTO OFF_TIME_LOOP
 DECFSZ CYCLES,F ;WE HAVE X = X-1 TOTAL LOOPS LEFT
 GOTO LOOP_DELAYS
 RETLW .0
;********************************************************
;***** 21 uS DELAY SUBROUTINE *
;*********************************************************
DELAY21uS:
 MOVWF COUNTER3 ;1uS
WAIT3D:
 MOVLW .1 ;1uS
 MOVWF COUNTER2 ;1uS
WAIT2D:
 MOVLW .7 ;1uS
 MOVWF COUNTER1 ;1uS
WAIT1D:
 DECFSZ COUNTER1,1 ;1 or 2uS
 GOTO WAIT1D ;2uS
 DECFSZ COUNTER2,1 ;1 or 2uS
 GOTO WAIT2D ;2uS
 DECFSZ COUNTER3,1 ;1 or 2uS
 GOTO WAIT3D ;2uS
 CLRWDT ;1uS
 RETLW .0 
;***********************************************
;************************ 6.0uS DELAY SUBROUTINE 
;***********************************************
DELAY6uSA:
 NOP
 NOP
 NOP
 NOP
 NOP
 NOP
 NOP
 NOP ;2uS 
 RETURN
 END

BACK