Code Help
Andrei
Posts: 15
Hi, I did my program with line follower and compass but I have a little trouble.
DO ' Main loop
GOSUB check_qtis
SELECT qtis
CASE %1000
PULSOUT 13, 670
PULSOUT 12, 670
CASE %1100
PULSOUT 13, 750
PULSOUT 12, 670
CASE %0100
PULSOUT 13, 790
PULSOUT 12, 670
CASE %0110
PULSOUT 13, 800
PULSOUT 12, 700
CASE %0010
PULSOUT 13, 830
PULSOUT 12, 710
CASE %0011
PULSOUT 13, 830
PULSOUT 12, 750
CASE %0001
PULSOUT 13, 830
PULSOUT 12, 830
CASE %0111
Init_state = 0 'setez starea initiala
DO
GOSUB Compass_Get_Axes ' Get x, and y values
IF init_state = 0 THEN
init_angle = x ATN -y
init_angle = init_angle */ 361 ' salvez unghiul initial!
init_state = 1
ELSEIF init_state = 1 THEN
angle = x ATN -y ' Convert x and y to brads
angle = angle */ 361 ' Convert brads to degrees
IF angle < (init_angle + 95) THEN 'GOSUB comanda_motoare
PULSOUT 13, 770
PULSOUT 12, 770
PAUSE 20
ELSE
GOSUB Fata_spate
ENDIF
' cat timp unghiul curent este mai mic decat cel
' initial - 90, comand motoarele
DEBUG HOME, "x-axis N(-S) = ",SDEC x, ' Display axes and degrees
CLREOL, CR, "y-axis W(-E) = ",
SDEC y, CLREOL, CR, CR, "angle = ",
DEC angle, " degrees", CLREOL
PAUSE 150
ENDIF ' Debug delay for slower PCs
LOOP ' Repeat main loop
CASE ELSE
PAUSE 3
ENDSELECT
LOOP
Fata_spate:
FOR counter = 1 TO 58
PULSOUT 13, 750 + counter '820
PULSOUT 12, 750 - counter '680
PAUSE 20
NEXT
FOR counter = 58 TO 1
PULSOUT 13, 750 + counter
PULSOUT 12, 750 - counter
PAUSE 20
NEXT
FREQOUT 3, 2000, 3000
FOR counter = 1 TO 60
PULSOUT 13, 750 - counter '680
PULSOUT 12, 750 + counter '820
PAUSE 20
NEXT
FOR counter = 60 TO 1
PULSOUT 13, 750 - counter
PULSOUT 12, 750 + counter
PAUSE 20
NEXT
RETURN
when it get's to case %0111 it's the problem. it turns with 90 degrees to the right(there is 95 but this is not important), runs GOSUB Fata_spate and I don't now how to get out from here to continue wiht following of the line. It dosen't stop, it comes back and then start turning a little more to the right(30 degres) and runs again Fata_spate.
Where is the problem?
I would like to check the QTI's again and start following the line or do nothing, depends on the QTI's setup.
Thank you.
DO ' Main loop
GOSUB check_qtis
SELECT qtis
CASE %1000
PULSOUT 13, 670
PULSOUT 12, 670
CASE %1100
PULSOUT 13, 750
PULSOUT 12, 670
CASE %0100
PULSOUT 13, 790
PULSOUT 12, 670
CASE %0110
PULSOUT 13, 800
PULSOUT 12, 700
CASE %0010
PULSOUT 13, 830
PULSOUT 12, 710
CASE %0011
PULSOUT 13, 830
PULSOUT 12, 750
CASE %0001
PULSOUT 13, 830
PULSOUT 12, 830
CASE %0111
Init_state = 0 'setez starea initiala
DO
GOSUB Compass_Get_Axes ' Get x, and y values
IF init_state = 0 THEN
init_angle = x ATN -y
init_angle = init_angle */ 361 ' salvez unghiul initial!
init_state = 1
ELSEIF init_state = 1 THEN
angle = x ATN -y ' Convert x and y to brads
angle = angle */ 361 ' Convert brads to degrees
IF angle < (init_angle + 95) THEN 'GOSUB comanda_motoare
PULSOUT 13, 770
PULSOUT 12, 770
PAUSE 20
ELSE
GOSUB Fata_spate
ENDIF
' cat timp unghiul curent este mai mic decat cel
' initial - 90, comand motoarele
DEBUG HOME, "x-axis N(-S) = ",SDEC x, ' Display axes and degrees
CLREOL, CR, "y-axis W(-E) = ",
SDEC y, CLREOL, CR, CR, "angle = ",
DEC angle, " degrees", CLREOL
PAUSE 150
ENDIF ' Debug delay for slower PCs
LOOP ' Repeat main loop
CASE ELSE
PAUSE 3
ENDSELECT
LOOP
Fata_spate:
FOR counter = 1 TO 58
PULSOUT 13, 750 + counter '820
PULSOUT 12, 750 - counter '680
PAUSE 20
NEXT
FOR counter = 58 TO 1
PULSOUT 13, 750 + counter
PULSOUT 12, 750 - counter
PAUSE 20
NEXT
FREQOUT 3, 2000, 3000
FOR counter = 1 TO 60
PULSOUT 13, 750 - counter '680
PULSOUT 12, 750 + counter '820
PAUSE 20
NEXT
FOR counter = 60 TO 1
PULSOUT 13, 750 - counter
PULSOUT 12, 750 + counter
PAUSE 20
NEXT
RETURN
when it get's to case %0111 it's the problem. it turns with 90 degrees to the right(there is 95 but this is not important), runs GOSUB Fata_spate and I don't now how to get out from here to continue wiht following of the line. It dosen't stop, it comes back and then start turning a little more to the right(30 degres) and runs again Fata_spate.
Where is the problem?
I would like to check the QTI's again and start following the line or do nothing, depends on the QTI's setup.
Thank you.
Comments
Rich H
This_case:
init_state = 0
DO
GOSUB Compass_Get_Axes
' Get x, and y values
IF init_state = 0 THEN
init_angle = x ATN -y
init_angle = init_angle */ 361 ' salvez unghiul initial!
init_state = 1
ELSE
init_state = 1
angle = x ATN -y ' Convert x and y to brads
angle = angle */ 361 ' Convert brads to degrees
IF angle < (init_angle + 90) THEN 'GOSUB comanda_motoare
PULSOUT 13, 770
PULSOUT 12, 770
PAUSE 20
ELSE
GOSUB Fata_spate
GOSUB Main
ENDIF
ENDIF
LOOP
Thank you again.