Shop OBEX P1 Docs P2 Docs Learn Events
help with sending bluetooth for color detecting-line following boebot — Parallax Forums

help with sending bluetooth for color detecting-line following boebot

AUseniordesignAUseniordesign Posts: 2
edited 2009-04-26 22:26 in BASIC Stamp
We are in the last week of our senior design project. We have designed a line following boebot that will detect a ball when it pass it, then detect the color using the TSC230-DB, and then will send this information via the eb500 to another robot. Then that robot will navigate not following the lines to pickup the balls and drop them off at the specified spot for it's color.

I am having a problem where the eb500 continually sends info over bluetooth while detecting the color. Here is my code. Can anyone tell me why it is constantly send info? And the info is just garbage...nothing readable.

'Main Program
Main:
OUTPUT TcSLeds ' allow direct control
TcsLeds = IsOn

DO
IF (pos<9)THEN 'stop after 9 balls found
DEBUG ? pos
GOSUB Detect_Line
GOSUB Drive_Motors
GOSUB Detect_Object

IF(rawColor > 20)THEN
PAUSE 500
GOSUB Ave_RGB
GOSUB Match_Color
PAUSE 1000
FOR counter = 1 TO 25
GOSUB Detect_Line
GOSUB Drive_Motors
NEXT
ENDIF

DEBUG DEC rawColor, CR
rawColor = 0
LOW 10
LOW 9
ELSE
GOSUB Ending
ENDIF
LOOP

END


' Subroutines

' Sends wave of frequency "LedFreq" to front LEDs. Reflected
' wave is detected by L

Detect_Line:
FREQOUT LedFreq, FreqTime, FreqRate
l_sensor = LSensor
FREQOUT LedFreq, FreqTime, FreqRate
r_sensor = RSensor
RETURN

' Rotates servomotors based on states of "l_sensor" and "r_sensor"
' Left motor turns if no line is visible on left
' Right motor turns if no line is visible on right

Drive_Motors:
IF ((l_sensor = NoLine)AND(r_sensor = NoLine)) THEN
PULSOUT 13, 850
PULSOUT 12, 697
ELSEIF((l_sensor = NoLine)AND(r_sensor = Line)) THEN
PULSOUT 13, 850
PULSOUT 12, 755
ELSEIF((l_sensor = Line)AND(r_sensor = NoLine)) THEN
PULSOUT 13, 750
PULSOUT 12, 697
ENDIF

RETURN

' Detects object by reading through a single filter for any
' intensity.

Detect_Object:
filter = Red
GOSUB Read_Color

RETURN

' Finds average RGB intensities for sample

Ave_RGB:
FOR counter = 1 TO 100
GOSUB Read_RGB ' color balance sensor
redBal = ((counter-1)*redBal + redVal)/counter
grnBal = ((counter-1)*grnBal + grnVal)/counter
bluBal = ((counter-1)*bluBal + bluVal)/counter
NEXT

RETURN

' Reads RGB values

Read_RGB:
filter = Red
GOSUB Read_Color
redVal = rawColor */ $0148 MAX ScaleMax
filter = Green
GOSUB Read_Color
grnVal = rawColor */ $01EE MAX ScaleMax
filter = Blue
GOSUB Read_Color
bluVal = rawColor */ $010B MAX ScaleMax
RETURN


' Reads selected color from TCS230
' -- takes "filter" as input
' -- returns "rawColor" as output (unscaled color value)

Read_Color:
SELECT filter
CASE Red
HIGH TcsS2
LOW TcsS3

CASE Green
HIGH TcsS2
HIGH TcsS3

CASE Blue
LOW TcsS2
HIGH TcsS3

CASE ELSE ' clear -- no filter
LOW TcsS2
LOW TcsS3

ENDSELECT

COUNT TcsFreq, ScanTime, rawColor ' return unscaled value
RETURN


' Match_Color finds the ratio between Green/Blue intensities and
' then checks to see if the intensities fall within the expected
' tolerance for a color.

Match_Color:
RGRat = (redBal*100)/grnBal 'Finds ratio of red to green

IF(RGRat>300)THEN
colpos(pos)= 1
DEBUG "The color is Magenta.", CR
HIGH 9
LOW 10
ELSE
colpos(pos)= 2
DEBUG "The color is Blue.", CR
HIGH 10
LOW 9
ENDIF
pos=pos+1
DEBUG ? colpos(0),? colpos(1),? colpos(2),? colpos(3),? colpos(4),? colpos(5),? colpos(6),? colpos(7),? colpos(8), CR 'displays each element of the array
RETURN

'Ending is the subroutine that is called after all 9 balls have been found.
'The boe-bot rotates 45 degrees clockwise then goes forward
Ending:

FOR counter = 1 TO 18 'rotate 45 degrees right
PULSOUT 12, 800
PULSOUT 13, 850
NEXT
FOR counter = 1 TO 20 'go forward off track
PULSOUT 12, 697
PULSOUT 13, 850
NEXT
SEROUT 1, 84, [noparse][[/noparse]CR, ? colpos(1),? colpos(2),? colpos(3),? colpos(4),? colpos(5),? colpos(6),? colpos(7),? colpos(8),? colpos(9)]
END

^^^^(serout not correct yet...haven't figured out how to output an array yet.)^^^^^

Post Edited (AUseniordesign) : 4/25/2009 8:54:26 PM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2009-04-26 01:21
    While running what value is pos? What are the actual values, not what you expect them to be.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • AUseniordesignAUseniordesign Posts: 2
    edited 2009-04-26 16:24
    pos is the position of the balls. We have 9 balls so it counts from 0 to 8. It does that correctly. My problem isn't with that. It is with the bluetooth spitting out garbage while the TSC230 is detecting color.
  • FranklinFranklin Posts: 4,747
    edited 2009-04-26 20:09
    Is the serout in the ending routine the only place you want to send bluetooth data. If so you probably have noise on the circuit. If not where are you sending the bluetooth data (I don't use bluetooth)
    Also it would help if you used the attachment manager to attach the actual .bs? file you are trying to get help with. What you posted is not a complete program and will not compile.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen

    Post Edited (Franklin) : 4/26/2009 8:17:18 PM GMT
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-04-26 22:26
    Check END statement description. It actually keeps the processor alive.

    With that - I am suspicious of the END statement in your Ending subroutine.

    It is not a good practice anyway to enter subroutine and not use RETUN statement.



    Minor suggestion - you should not send serial data without checking if the receiving end is ready to accept it ( hardware handshake).



    Post Edited (vaclav_sal) : 4/26/2009 10:35:24 PM GMT
Sign In or Register to comment.