how to do 2 subroutines at the same time?
Boe
Posts: 4
Hello,
I'm working with the Boe-Bot, with Basic Stamp Editor v2.4. and and programing with Basic Stamp BS2, PBASIC 2.5
I've learned a lot of thing through the " Robotics with the Boe-
Bot" book and I have to write a little program that I have created for my end year exams.
Here was the idea of the project:
The Boe-Bot advance on a black line on a white sheet. While it's
advancing, it has to count every intersection between the black line
and some perpendiculars green lines, so it know where it is and can
return to its starting point whenever we want.
But the problem is that I don't know how to do two thing at the same
time, two subroutines. ( we want it to count and to navigate at the
same time ). Now, it doesn't want to do these two things at the same
time,
for the moment, it navigates 20 pulses, then stores its results, and then
navigates again...
Can you please tell me the way to do that, if it is possible, or
redirect me to another person who can help me?
( Because if this is not possible, we have to rapidly change our idea,
to have something to present to our exam )
Thank in advance for your support,
( sorry for my english )
p.s. Here is the program:
' {$STAMP BS2}
' {$PBASIC 2.5}
xCounter VAR Word
yCounter VAR Word
x2Counter VAR Word
timeleft VAR Word
timeright VAR Word
epsilon CON 20
timerightprev VAR Word
delta VAR Word
DEBUG "COUNTER VALUES", CR,
" Epsilon ",DEC5 EPSILON ,CR
xCounter = 0
yCounter = 0
timerightprev = 0
delta = 0
DO
GOSUB compte
GOSUB forward
LOOP
END
compte:
HIGH 3
PAUSE 2
RCTIME 3,1, timeright
DEBUG CRSRXY, 0, 3,
"Timeright " ,DEC5 timeright, " Timerightprev " ,DEC5
timerightprev," xCounter ",DEC5 xCounter,
" delta ", DEC5 delta," x2Counter ", DEC5 x2Counter,
" "
PAUSE 10
IF ( timerightprev = 0 ) THEN
timerightprev = timeright
ELSEIF (( timerightprev > timeright + epsilon + delta) ) THEN
xCounter = xCounter + 1
delta = 0
FREQOUT 4, 200, 3000
ELSEIF (( timerightprev < timeright - epsilon - delta) ) THEN
delta = ABS( timerightprev - timeright )
PAUSE 20
ENDIF
timerightprev = timeright
RETURN
forward:
DO
PULSOUT 13, 780
PULSOUT 12, 720
PAUSE 20
LOOP
RETURN
I'm working with the Boe-Bot, with Basic Stamp Editor v2.4. and and programing with Basic Stamp BS2, PBASIC 2.5
I've learned a lot of thing through the " Robotics with the Boe-
Bot" book and I have to write a little program that I have created for my end year exams.
Here was the idea of the project:
The Boe-Bot advance on a black line on a white sheet. While it's
advancing, it has to count every intersection between the black line
and some perpendiculars green lines, so it know where it is and can
return to its starting point whenever we want.
But the problem is that I don't know how to do two thing at the same
time, two subroutines. ( we want it to count and to navigate at the
same time ). Now, it doesn't want to do these two things at the same
time,
for the moment, it navigates 20 pulses, then stores its results, and then
navigates again...
Can you please tell me the way to do that, if it is possible, or
redirect me to another person who can help me?
( Because if this is not possible, we have to rapidly change our idea,
to have something to present to our exam )
Thank in advance for your support,
( sorry for my english )
p.s. Here is the program:
' {$STAMP BS2}
' {$PBASIC 2.5}
xCounter VAR Word
yCounter VAR Word
x2Counter VAR Word
timeleft VAR Word
timeright VAR Word
epsilon CON 20
timerightprev VAR Word
delta VAR Word
DEBUG "COUNTER VALUES", CR,
" Epsilon ",DEC5 EPSILON ,CR
xCounter = 0
yCounter = 0
timerightprev = 0
delta = 0
DO
GOSUB compte
GOSUB forward
LOOP
END
compte:
HIGH 3
PAUSE 2
RCTIME 3,1, timeright
DEBUG CRSRXY, 0, 3,
"Timeright " ,DEC5 timeright, " Timerightprev " ,DEC5
timerightprev," xCounter ",DEC5 xCounter,
" delta ", DEC5 delta," x2Counter ", DEC5 x2Counter,
" "
PAUSE 10
IF ( timerightprev = 0 ) THEN
timerightprev = timeright
ELSEIF (( timerightprev > timeright + epsilon + delta) ) THEN
xCounter = xCounter + 1
delta = 0
FREQOUT 4, 200, 3000
ELSEIF (( timerightprev < timeright - epsilon - delta) ) THEN
delta = ABS( timerightprev - timeright )
PAUSE 20
ENDIF
timerightprev = timeright
RETURN
forward:
DO
PULSOUT 13, 780
PULSOUT 12, 720
PAUSE 20
LOOP
RETURN
Comments
thePulsout:
PULSOUT for the servo
GOSUB to the "other" function
PAUSE for whatever is left of the 20ms interval
GOTO thePulsout
There are some good examples of this in the Robotics with the BoeBot tutorial and the Roaming with the PING))) example where the BoeBot does some sensing and decision making as part of this 20ms main loop.
thank for replying!
So I'm not sure that I've understood what you just said.
I could put my subroutine ( which takes a few milliseconds ) in another subroutine which is "navigate"?
And the Boe-Bot will stop the few milliseconds to do my subroutine?
I will Edit my post to show you the idea of my project to see if there isn't another way to get it
Thank you
The servo motors each require a control pulse up to maybe 2.5ms in width once every 20ms or so. Two servos would require up to 5ms for the control pulses leaving 15ms. Commonly, this time is taken up with a PAUSE statement. You can shorten (or eliminate) this pause time and substitute some other action, like triggering a PING and waiting for the response, then doing some simple calculations with the resulting information. The BoeBot doesn't "stop". It just does something "useful" instead of a PAUSE.
sorry, but I don't understand vers well.
I already read the book you mensioned ( robotics with the Boe Bot ) and I didn't see anywhere the solution you talked about.
if you have a link or something like that to show me, I would be grateful to you.
Sorry again for my incomprehension :sad:
Now I think I've understood the problem.
I changed my program after reading the examples ( the program is in attachement and also a screenshot from the debug terminal ).
I wonder if it is the more precise solution to get what I want.. Have you got a better idea?
Thanks in advance