Shop OBEX P1 Docs P2 Docs Learn Events
Heat seaking help — Parallax Forums

Heat seaking help

wings153wings153 Posts: 4
edited 2009-12-10 02:09 in BASIC Stamp
I am inquiring about some help for why the robot will not work if we have sub routines applied in the display temperature command.
The robot tends to just stop working and not actually do anything.

thank you.


' {$STAMP BS2}
' {$PBASIC 2.5}

'This is a test program to see if the boebot "sees" something

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

Reset CON 10
ALR CON 11
Sensor CON 12

'
[noparse][[/noparse] Constants ]

baud CON 84
xslave CON $35 'slave address

'
[noparse][[/noparse] Variables ]

temperature VAR Word
tempL VAR temperature.LOWBYTE
tempH VAR temperature.HIGHBYTE
pec VAR Byte
alarm VAR Byte
foundo VAR Byte
temperatureLevel VAR Byte


irDetectLeft VAR Byte
leftTrigger VAR Byte
rightTrigger VAR Byte
irDetectRight VAR Byte

Kelvin VAR Word
KelvinDec VAR Word
Celsius VAR Word
CelsiusDec VAR Word
w VAR Byte
x VAR Byte
y VAR Byte
z VAR Byte

seen VAR Byte
timetillquit VAR Byte
'
[noparse][[/noparse] EEPROM Data ]

PEC0 DATA $00,$07,$0E,$09,$1C,$1B,$12,$15,$38,$3F,$36,$31,$24,$23,$2A,$2D
PEC1 DATA $70,$77,$7E,$79,$6C,$6B,$62,$65,$48,$4F,$46,$41,$54,$53,$5A,$5D
PEC2 DATA $E0,$E7,$EE,$E9,$FC,$FB,$F2,$F5,$D8,$DF,$D6,$D1,$C4,$C3,$CA,$CD
PEC3 DATA $90,$97,$9E,$99,$8C,$8B,$82,$85,$A8,$AF,$A6,$A1,$B4,$B3,$BA,$BD
PEC4 DATA $C7,$C0,$C9,$CE,$DB,$DC,$D5,$D2,$FF,$F8,$F1,$F6,$E3,$E4,$ED,$EA
PEC5 DATA $B7,$B0,$B9,$BE,$AB,$AC,$A5,$A2,$8F,$88,$81,$86,$93,$94,$9D,$9A
PEC6 DATA $27,$20,$29,$2E,$3B,$3C,$35,$32,$1F,$18,$11,$16,$03,$04,$0D,$0A
PEC7 DATA $57,$50,$59,$5E,$4B,$4C,$45,$42,$6F,$68,$61,$66,$73,$74,$7D,$7A
PEC8 DATA $89,$8E,$87,$80,$95,$92,$9B,$9C,$B1,$B6,$BF,$B8,$AD,$AA,$A3,$A4
PEC9 DATA $F9,$FE,$F7,$F0,$E5,$E2,$EB,$EC,$C1,$C6,$CF,$C8,$DD,$DA,$D3,$D4
PEC10 DATA $69,$6E,$67,$60,$75,$72,$7B,$7C,$51,$56,$5F,$58,$4D,$4A,$43,$44
PEC11 DATA $19,$1E,$17,$10,$05,$02,$0B,$0C,$21,$26,$2F,$28,$3D,$3A,$33,$34
PEC12 DATA $4E,$49,$40,$47,$52,$55,$5C,$5B,$76,$71,$78,$7F,$6A,$6D,$64,$63
PEC13 DATA $3E,$39,$30,$37,$22,$25,$2C,$2B,$06,$01,$08,$0F,$1A,$1D,$14,$13
PEC14 DATA $AE,$A9,$A0,$A7,$B2,$B5,$BC,$BB,$96,$91,$98,$9F,$8A,$8D,$84,$83
PEC15 DATA $DE,$D9,$D0,$D7,$C2,$C5,$CC,$CB,$E6,$E1,$E8,$EF,$FA,$FD,$F4,$F3


'
[noparse][[/noparse]initalization]

seen = 0
leftTrigger = 0
rightTrigger = 0
timetillquit = 0
foundo = 0
Init:
LOW Reset
INPUT Reset
Alarm = 15157
FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.
FREQOUT 2, 1, 38500
irDetectRight = IN0

DEBUG CLS, ' setup report screen
"MLX90614 Infra Red Thermometer", CR,
"=============================", CR,CR ' setup report screen

'
[noparse][[/noparse]main code]


getTemperature: ' gets the temperature
SEROUT Sensor,baud,[noparse][[/noparse]0,"!TEMR",xslave,$07]
SERIN Sensor,baud,[noparse][[/noparse]tempL,tempH,pec]

checkPEC:
z=0
y = xslave<<1+0
GOSUB calculateCRC
y = $07
GOSUB calculateCRC
y = xslave<<1+1
GOSUB calculateCRC
y = tempL
GOSUB calculateCRC
y = tempH
GOSUB calculateCRC
IF z<>pec THEN PECfail
GOTO displayTemperatures

calculateCRC:
w=z^y
READ w,z
RETURN


displayTemperatures: ' Looks to see if there is an object infront
IF (temperature > 15150) THEN
foundo = 1
DEBUG CRSRXY, 23, 6, "found", CLREOL
seen = 1
GOTO getTemperature 'sets alarmOff depending if object is there
ELSEIF (seen = 1 AND temperature < 15150 AND timetillquit < 10) THEN
timetillquit = timetillquit + 1
DEBUG CRSRXY, 23, 6, "had seen it", CLREOL
foundo = 0
PAUSE 1000
ELSEIF (timetillquit > 9) THEN
DEBUG CRSRXY, 23, 6, "not found", CLREOL
seen = 0
timetillquit = 0
PAUSE 1000
GOTO didItMove
ENDIF

didItMove:
GOSUB whichTrigger
IF(seen = 1) THEN
IF (leftTrigger = 0 AND rightTrigger = 1) THEN

DEBUG CRSRXY, 23, 6, "to the Right", CLREOL
PAUSE 1000
ELSEIF (leftTrigger = 1 AND rightTrigger = 0) THEN
DEBUG CRSRXY, 23, 6, "to the Left", CLREOL
PAUSE 1000
ENDIF
ENDIF
RETURN
GOTO getTemperature


PECfail:
DEBUG CRSRXY, 23, 3,CLREOL,CR
DEBUG CRSRXY, 23, 4,CLREOL,CR
DEBUG CRSRXY, 23, 5,"Fail",CLREOL,CR
PAUSE 500
GOTO getTemperature


whichTrigger:
FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.
FREQOUT 2, 1, 38500
irDetectRight = IN0

IF (irDetectLeft = 1 AND irDetectRight = 0) THEN ' Right IR pair detects
rightTrigger = 1
leftTrigger = 0
RETURN
ELSEIF (irDetectRight = 1 AND irDetectLeft = 0) THEN ' Left IR pair detects
leftTrigger = 1
rightTrigger = 0
RETURN
ELSEIF (irDetectRight = 1 AND irDetectLeft = 1) THEN ' Both IR pairs 0, detects large obstacle
rightTrigger = 0
leftTrigger = 0
RETURN
ENDIF
PAUSE 20
RETURN

Forward_Pulse: 'Go Forward
PULSOUT 12,850
PULSOUT 13,650
PAUSE 20
RETURN
'Left Turn
Turn_Left:
FOR pulse_counter = 0 TO 10
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN

Turn_Right: 'Right turn
FOR pulse_counter = 0 TO 10 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN

Back_Up: 'Back up
FOR pulse_counter = 0 TO 10
PULSOUT 12, 650
PULSOUT 13, 850
PAUSE 20
NEXT
RETURN

Comments

  • wings153wings153 Posts: 4
    edited 2009-12-09 21:35
    also, i forgot, there is a pulse_counter var byte at the top. just realized



    edit: it looks like the pulsout command lines are causing errors. Forsome reason when i use a subroutine call to the forward_pulse and so, i'm getting the debug terminal to stop

    second edit: well i've done some tests. I can use the subroutines as long as there is no pulsout command in it. because otherwise, there will be a freeze in the loop for some reason. I'm not sure why.

    Post Edited (wings153) : 12/9/2009 10:07:52 PM GMT
  • SRLMSRLM Posts: 5,045
    edited 2009-12-09 22:05
    Hi Wings,

    Can you edit your first post (by clicking the pencil icon) to not include the code embedded in the post but instead attach the code? Also, we need more information. What do you want it to do? What is it doing? What do you think is wrong?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Powered by enthusiasm
  • wings153wings153 Posts: 4
    edited 2009-12-09 22:10
    ok i was able to attach it

    my group and I want the robot to go forward if it "sees" you, or turn right or left if one of the infrared detectors picks up a body on the left or right side of the boe bot. when trying to use subroutines, there are freezes in the system that cause it not to work because the subroutines contain pulsout commands, which the boebot doesn't seem to like. We were using the debug terminal to see where the robot was working, and we have come to conclude that the pulsout commands are causing some fault in this.

    Thank you
  • Brad_HBrad_H Posts: 35
    edited 2009-12-09 22:18
    Looks like you have " Sensor CON 12 " and " PULSOUT 12,·xxx ", I think your Sensor con is wrong.

    Brad
  • FranklinFranklin Posts: 4,747
    edited 2009-12-09 22:19
    Simplify your code to help find the failure. Which subroutine fails? What works and what doesn't?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • wings153wings153 Posts: 4
    edited 2009-12-09 22:26
    Brad, you have helped alot, its closer now. I've tried to just write the code for going forward only, and no complex stuff..and it is going forward!, but now we are trying to combine it..yet for some reason it still won't work..hmm..closer


    edit:attached a new set of test code.
    ok this is weird. This program works...except after about 24 pulses, it stops and the debug terminal freezes. btw, i'm using the mlx90614 which i only have one of.

    Post Edited (wings153) : 12/9/2009 10:36:15 PM GMT
  • FranklinFranklin Posts: 4,747
    edited 2009-12-10 02:09
    One thing you should do is put a timeout into your serin statement so if it does not get input it will not lock up your program. Might be your problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.