Shop OBEX P1 Docs P2 Docs Learn Events
Line following/ proximity sensor rpoblem — Parallax Forums

Line following/ proximity sensor rpoblem

NamNam Posts: 6
edited 2005-03-23 05:14 in BASIC Stamp
Hello everyone! I am reposting a problem that I had.· To fill everyone in I:
I am having issues with my programming!
Project description:
·
I am designing and building a line following mail cart.· The mail cart is designed to follow a black line around an office environment and stop at pre marked areas for mail delivery.· At each stop an audible bell is sounded letting the secretary know to come get the mail from the cart.· At this point two things will happen. (1) If no one comes to get their mail after 30 seconds the cart will continue on.· (2) If someone gets the mail they can hit a stop button (to deactivate the timer and bell) and retrieve their mail at a leisurely pace.· Then they can hit the button again to reactivate the cart sending the cart on its way!yeah.gif f people or objects are in the path of the cart it will stop and wait until the object is cleared.
·
Hardware used:
·
Line following sensors : 4 QTI - 3 QTI used for line following - 4th qti is used for stop detection and crossing detection ( such as figure 8 pattern)
·
Proximity sensing - IR LED and Detector - used for object sensing
·
Bell - Piezerro
·
Push button
·
Boe-Bot - BS2 software
·
Problem description:
·
Now! With that said, I would like to discuss the problems that I have encountered.· The major problem is·the programming.· How can I possibly run the proximity sensing program·and the line following program simultaneously or near that.· I have tried to run the programs together but that does not run properly.· Does anyone have any ideas on how to organize my program in such a way it will execute all ·of the tasks I have listed in a systematic and simultaneously.·

~~~~~~~~~~~~~~~~~~~~~~~~~~~Update!~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ok so I have updated some of the code and adjusted it to my needs.·
Update since last posted problem:· Mr. Jon Williams has kindly helped me by reorganizing the structure of the program and adding blanks for me to fill in some code. The problem: The robot does not function properly.
Problem 1:
I added some debug statements in the program to help me view what was currently running.· When an object is placed in front of the IR the Print out is “ IR is active”.· As soon as the object is cleared the program continues with the line following subroutine.· BUT! The program prints out the statement at the CAS ELSE· - Bad command and does not perform the other cases.· WHY???? This is bothering me.· PLEASE HELP!!
Problem 2:
I am trying to Print the Bit value of the sensor.· AS I understand it the CASE ELSE statement is used when none of the cases fit the sensor output.· Is there a way to view what sensors are outputting 1’s and 0’s during the CASE ELSE statement?
·
Thanks~!freaked.gif <-- me as of right now
nam phan

' =========================================================================
'
' File....... Mailbot.BS2
' Purpose....
' Author.....
' E-mail.....
' Started....
' Updated....
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================


'
[noparse][[/noparse] Program Description ]


'
[noparse][[/noparse] Revision History ]


'
[noparse][[/noparse] I/O Definitions ]

ServoL PIN 13 ' left servo
ServoR PIN 12 ' right servo
Sensor PIN 3 ' input from QTI sensors


'
[noparse][[/noparse] Constants ]

Active CON 1
NotActive CON 0


'
[noparse][[/noparse] Variables ]

prox VAR Bit ' proximity flag
idx VAR Nib ' loop control
qti VAR Nib ' sensor array status
irDetect VAR Bit ' IR Prox (new)



'
[noparse][[/noparse] EEPROM Data ]


'
[noparse][[/noparse] Initialization ]

Reset:
LOW ServoL ' initialize servo pins
LOW ServoR


'
[noparse][[/noparse] Program Code ]

Main:
DO
GOSUB Check_Prox ' check proximity
IF (prox = Active) THEN
PULSOUT ServoL, 0
PULSOUT ServoR, 0
DEBUG " IR is active ", CR


' deal with proximity sensor

ELSE

GOSUB Scan_QTIs: ' scan line array

' move bot

SELECT qti
CASE %0010, %1010 ' Forward
PULSOUT ServoL, 850
PULSOUT ServoR, 650

CASE %1011, %0011 ' Pivot right
PULSOUT ServoL, 850
PULSOUT ServoR, 750

CASE %1001, %0001 ' Rotate right
PULSOUT ServoL, 850
PULSOUT ServoR, 850

CASE %1110, %0110 ' Pivot Left
PULSOUT ServoL, 750
PULSOUT ServoR, 650

CASE %1100, %0100 ' Rotate Left
PULSOUT ServoL, 650
PULSOUT ServoR, 650

CASE %1111 ' Cross Detection
PULSOUT ServoL, 850 ' -- Continue foward
PULSOUT ServoR, 650

CASE %0111 ' Stop when black tape covers 3 sensors
PULSOUT ServoL, 0 ' Bell sound alerts person to pick up mail
PULSOUT ServoR, 0
FREQOUT 15, 1000, 4000 ' from cart

CASE ELSE
DEBUG " Bad Command ", CR


ENDSELECT

PAUSE 20
ENDIF
LOOP


'
[noparse][[/noparse] Subroutines ]

Check_Prox: ' code to check proximity sensor


FREQOUT 0, 1, 38500
irDetect = IN9

IF (irDetect = 1) THEN
prox = NotActive
ELSEIF (irDetect= 0) THEN
prox = Active

ENDIF
RETURN



' Activates and reads QTI sensors on pins 5 - 8

Scan_QTIs:
FOR idx = 0 TO 3 ' loop through 4 bits
HIGH (5 + idx) ' activate sensor
PAUSE 1
qti.LOWBIT(idx) = Sensor ' record sensor output
NEXT
RETURN





Sign In or Register to comment.