Im running four qtis on my boe bot and is it possible to make a counter where when it make certain amount of turns the qtis will stop and the robot will do another task?
ok.. i still dont get it.. at case %0000 i got it to pulsout 850 and 850 which is turning around... i need it to count how many 850 850 it's going to do.. or how many times it go to %0000 and then when it is the 3rd time it goes to 0000 i need it to turn around, back up, and pulsout to another servo.. can you please help??
I'm sorry, I don't quite get your question. "Case %0000"? What does that refer to? Are you trying to count *how much* you have turned, or how many times you have "turned", or ???
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
OK, how many times, you mean how many revolutions for that instance of "turning around" or do you mean "how many times did I try to escape or re-find the line (or whatever)?
If the former, you will need to send a known count of pulses to the 'bot and see how much turn you get for a given number of pulses, then you will have some real values that you can use to control the amount of turn.
For example:
pulses VAR Byte
FOR pulses = 0 TO 25
PULSOUT pinL, 850
PULSOUT pinR, 850
PAUSE 18
NEXT
DO : LOOP
Run the code, and measure how far your 'bot turns. Too much? Not enough? change the number till you get the desired turn amount.
Now lets say when you're done that 25 pulses gives you 1/4 turn, 55 pulses gives you a 180 degree turn, etc -- you can plug that number in for a desired turn amount:
IF going_straight THEN
' do some stuff
ELSEIF lost_QTI_line THEN
pulses = 55
motoL = 850
motoR = 850
DO
PULSOUT pinL, motoL
PULSOUT pinR, motoR
pulses = pulses - 1
PAUSE 18
LOOP WHILE pulses > 0
ENDIF
There are more elegant ways to approach this, primarily by establishing some known pulse counts that correspond to units of useful measurement. Also my simple loop example much less ideal than a good state machine that sets final values for pulses and motor speeds, then allows execution of a single "set motor speed" routine.
See Andy Lindsay's writeup on "go to and find closest object" in the Stamps in Class forum. His experiments have you establish known pulse counts for turns by brads -- so you can feed an angled (in brads, not degrees) to the motor subroutines, which convert the brad turn amount to a pulsecount, then do that many pulses. So you can set your 'bot to turn 32 brads (45 degrees), 64 brads (90 degrees), etc., with some reliability.
And don't hesitate to post your own code
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
' {$STAMP BS2}
' {$PBASIC 2.5}
qtis VAR Nib ' qti black/white states
counter VAR Byte
EOLcounter VAR Word
counter2 VAR Byte
counter = 0
EOLcounter = 0
OUTB = %1111 ' Set OUTB bits to 1
DO
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
GOSUB Check_Qtis
LOOP UNTIL (qtis = %1111)
DO
GOSUB Check_Qtis ' Get QTI states
SELECT qtis ' Control servo speeds/directions
CASE %1000 ' Rotate right
PULSOUT 13, 650
PULSOUT 12, 650
CASE %1100 ' Pivot right
PULSOUT 13, 750
PULSOUT 12, 650
CASE %0100 ' Curve right
PULSOUT 13, 800
PULSOUT 12, 650
CASE %0110 ' Straight ahead
PULSOUT 13, 850
PULSOUT 12, 650
CASE %0010 ' Curve left
PULSOUT 13, 850
PULSOUT 12, 700
CASE %1111 ' Special case when 4 sensors detects
PULSOUT 13, 850
PULSOUT 12, 850
CASE %1110 ' special case 2
PULSOUT 13, 850
PULSOUT 12, 650
CASE %0111 ' special case 3
PULSOUT 12, 650
PULSOUT 13, 850
CASE %0011 ' Pivot left
PULSOUT 13, 850
PULSOUT 12, 750
CASE %0001 ' Rotate left
PULSOUT 13, 850
PULSOUT 12, 850
CASE %0000 ' Turn Around
EOLcounter = EOLcounter + 1
IF EOLcounter >= 3 THEN
FOR counter = 1 TO 50 ' turn around after 3rd turn
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
FOR counter = 1 TO 50 'back up after the above turn
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
FOR counter = 1 TO 100
PULSOUT 14, 850
PAUSE 20
NEXT
END
ELSE
DO
GOSUB Check_Qtis
PULSOUT 13, 850
PULSOUT 12, 850
LOOP UNTIL qtis >= 1
ENDIF
CASE ELSE ' Do nothing
PAUSE 3
ENDSELECT
LOOP
Check_Qtis:
' Result -> qtis variable. 0 means white surface, 1 means black surface.
DIRB = %1111 ' P7..P4 -> output
PAUSE 0 ' Delay = 230 us
DIRB = %0000 ' P7..P4 -> input
PAUSE 0 ' Delay = 230 us
' PULSOUT UnusedPin, 0 ' Delays = 208 + (Duration*2) us
qtis = INB ' Store QTI outputs in INB
RETURN
that's the whole code that im using.
notice at case %0000 i try to make it where if it turned more than 2 times, at the third turn, it will turn around, back up, and activate another servo. This code right now does that at the very 1st turn, i try to change value but it does not work at all.
thank you so much for trying to help, i know im not the best person when it comes to describing the problem
The code basically looks OK. I would try replacing "END" with "DO : LOOP", but that shouldn't make a difference, really.
Given the behavior you are describing, is it possible that what you think is the EOL state (qtis = %0000) is actually another state? In other words, have double checked that the QTI readings you are getting are what you expect from your lines and that you entering the correct state in your SELECT/CASE choices?
Lastly, and this is probably unrelated, but you never know, you need to have some kind of pause in the main select/case loop so you don't overdrive the servos -- right now you only pause your 20ms in the for:next loops for the start and the eol case, e.g.:
ENDIF
CASE ELSE ' Do nothing
PAUSE 3 ' you can probably take this one out
ENDSELECT
PAUSE 18 ' insert this pause to cover all the states except EOL.
LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
ok.. if i install the speaker how can i change it to where it counts for how many times it beeps (it will beep when it turns) then at .. say the 3rd beep it'll do what i want?
You mean for a kind of debug tool? Something like:
EOLcounter = EOLcounter + 1 ' after this line in your code, insert the following:
FOR tmp = 1 TO EOLcounter ' either reuse some other var for tmp, or create a new one
FREQOUT Speaker, 50, 3000
PAUSE 100
NEXT
If you get no beeps, you are not hitting that state. You may need to increase/decrease freqout time and freq, and subsequent pause, to get the sound you want.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
case %0000 is refering to when the qti sensors are not detecting any line
If the former, you will need to send a known count of pulses to the 'bot and see how much turn you get for a given number of pulses, then you will have some real values that you can use to control the amount of turn.
For example:
Run the code, and measure how far your 'bot turns. Too much? Not enough? change the number till you get the desired turn amount.
Now lets say when you're done that 25 pulses gives you 1/4 turn, 55 pulses gives you a 180 degree turn, etc -- you can plug that number in for a desired turn amount:
There are more elegant ways to approach this, primarily by establishing some known pulse counts that correspond to units of useful measurement. Also my simple loop example much less ideal than a good state machine that sets final values for pulses and motor speeds, then allows execution of a single "set motor speed" routine.
See Andy Lindsay's writeup on "go to and find closest object" in the Stamps in Class forum. His experiments have you establish known pulse counts for turns by brads -- so you can feed an angled (in brads, not degrees) to the motor subroutines, which convert the brad turn amount to a pulsecount, then do that many pulses. So you can set your 'bot to turn 32 brads (45 degrees), 64 brads (90 degrees), etc., with some reliability.
And don't hesitate to post your own code
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
that's the whole code that im using.
notice at case %0000 i try to make it where if it turned more than 2 times, at the third turn, it will turn around, back up, and activate another servo. This code right now does that at the very 1st turn, i try to change value but it does not work at all.
thank you so much for trying to help, i know im not the best person when it comes to describing the problem
Given the behavior you are describing, is it possible that what you think is the EOL state (qtis = %0000) is actually another state? In other words, have double checked that the QTI readings you are getting are what you expect from your lines and that you entering the correct state in your SELECT/CASE choices?
Lastly, and this is probably unrelated, but you never know, you need to have some kind of pause in the main select/case loop so you don't overdrive the servos -- right now you only pause your 20ms in the for:next loops for the start and the eol case, e.g.:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
If you get no beeps, you are not hitting that state. You may need to increase/decrease freqout time and freq, and subsequent pause, to get the sound you want.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST