need help to solve the ir distance sensor

Thread Starter

hasnannordin

Joined Oct 9, 2009
1
HI.I'M WORKING FOR MY FINAL YEAR PROJECT WHICH IS I MAKE TO MAZE MAPPER ROBOT.FOR THIS PROJECT I USE 3 IR SENSORS (sharp GP2D120XJ00F),2 12VDC MOTOR WITH ENCODER (PD3046) AND 1 PIC18F4550 MICROCONTROLLER.I HAVE MAKE THE SENSORS CODING SEPARATELY BUT I CAN'T COMBINE THE 3 SENSORS CODING INTO 1 CODING.I'VE TRIED TO COMBINE THE SENSORS CODE BUT IT'S DOESN'T WORK AT ALL.HOW CAN I COMBINE THE 3 SENSORS?THERE'S ANYBODY CAN HELP ME TO SOLVE THE PROBLEM.FOR YOUR INFORMATION, I CONNECT THE 3 SENSORS AT THE PORTA0-A2.I ATTACH MY SENSORS CODE BELOW:

COMBINATION OF 3 SENSOR


define osc 8

defenition
DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
MRCW1 VAR PORTD.4
MRCCW1 VAR PORTD.5 'MOTOR RIGHT DRIVE
MRCW2 VAR PORTD.6
MRCCW2 VAR PORTD.7 'MOTOR LEFT DRIVE
TRISD.4=0
TRISD.5=0
TRISD.6=0
TRISD.7=0
TRISA=1
ADCON1=%00001110
SENSOR1 VAR BYTE
SENSOR2 VAR BYTE
SENSOR3 VAR BYTE

HPWM 1,150,1000

main program
MAIN:

GOSUB fwd
pause 1000
GOSUB IR1
PAUSE 1000
GOSUB IR3
PAUSE 1000
GOSUB IR2
PAUSE 1000
GOTO MAIN

FWD:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
HPWM 2,150,500
MRCCW2=1
MRCW2=0

RETURN

IR1:
ADCIN 0,SENSOR1

IF SENSOR1>46 THEN
GOSUB RIGHT
pause 1000

ELSE
if SENSOR1<46 THEN
GOSUB FWD
pause 1000
ENDIF
ENDIF
pause 1000

RETURN

IR2:
ADCIN 1,SENSOR2

IF SENSOR2>46 THEN
GOSUB BWD
pause 1000

ELSE
if SENSOR2<46 THEN
GOSUB fwd
pause 1000
ENDIF
ENDIF
pause 1000

RETURN

IR3:
ADCIN 2,SENSOR3

IF SENSOR3>46 THEN
GOSUB LEFT
pause 1000

ELSE
if SENSOR3<46 THEN
GOSUB FWD
pause 1000
ENDIF
ENDIF
pause 1000

RETURN

RIGHT:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
HPWM 2,150,500
MRCCW2=0
MRCW2=0
RETURN

LEFT:
HPWM 1,150,500
MRCCW1=0
MRCW1=0
HPWM 2,150,500
MRCCW2=1
MRCW2=0
pause 1000
RETURN

BWD:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
HPWM 2,150,500
MRCCW2=1
MRCW2=0
PAUSE 1000
GOSUB RIGHT

RETURN

FOR THE SEPARATE CODE OF SENSOR:

SENSOR 1

define osc 8

'defenition
DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
MRCW1 VAR PORTD.4
MRCCW1 VAR PORTD.5 'MOTOR RIGHT DRIVE
MRCW2 VAR PORTD.6
MRCCW2 VAR PORTD.7 'MOTOR LEFT DRIVE
TRISD.4=0
TRISD.5=0
TRISD.6=0
TRISD.7=0
TRISA.0=1
ADCON1=%00001110
SENSOR1 VAR BYTE

HPWM 1,150,1000

'main program
MAIN:

GOSUB fwd
pause 1000
GOSUB IR1

GOTO MAIN

FWD:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
RETURN

IR1:
ADCIN 0,SENSOR1

IF SENSOR1>46 THEN
GOSUB BREAK


ELSE
if SENSOR1<46 THEN
GOTO MAIN

ENDIF
ENDIF
pause 1000

GOTO IR1

BREAK:
HPWM 1,150,500
MRCCW1=0
MRCW1=0
RETURN


AND FOR SENSOR 2

define osc 8

'defenition
DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
MRCW1 VAR PORTD.4
MRCCW1 VAR PORTD.5 'MOTOR RIGHT DRIVE
MRCW2 VAR PORTD.6
MRCCW2 VAR PORTD.7 'MOTOR LEFT DRIVE
TRISD.4=0
TRISD.5=0
TRISD.6=0
TRISD.7=0
TRISA.1=1
ADCON1=%00001100
SENSOR2 VAR BYTE

HPWM 1,150,1000

MAIN1:

GOSUB FWD
pause 1000
GOSUB IR2
GOTO MAIN1

FWD:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
pause 1000
RETURN

IR1:

ADCIN 1,SENSOR2

IF SENSOR2>46 THEN
GOSUB BREAK

ELSE
if SENSOR2<46 THEN
GOTO MAIN1
ENDIF
ENDIF
goto IR2

BREAK:
HPWM 1,150,500
MRCCW1=0
MRCW1=0
RETURN


PLEASE HELP ME,I'M DESPERATELY NEED THE SOLUTION OF MY PROBLEM.THANK YOU.
 

beenthere

Joined Apr 20, 2004
15,808
Just convert the sensor inputs in sequence. Assign the results to separate variables and evaluate your navigation using those numbers.

Or do you have some other meaning in the phrase -
COMBINE THE 3 SENSORS CODING INTO 1 CODING
 
Top