Need help in basic coding!
V360
Posts: 10
So, i have been reading through examples of line follower codes. There's something i don't get.
' QtiLineFollow.bs2
' Boe-Bot follows electrical tape with 3 QTI modules.
'{$STAMP BS2}
'{$PBASIC 2.5}
qti VAR Nib
DO
Right: HIGH 5: PAUSE 1: qti.BIT0 = IN3: INPUT 5
Center: HIGH 6: PAUSE 1: qti.BIT1 = IN3: INPUT 6
Left: HIGH 7: PAUSE 1: qti.BIT2 = IN3: INPUT 7
SELECT qti
CASE %010 ' Forward
PULSOUT 13, 850
PULSOUT 12, 650
CASE %011 ' Pivot right
PULSOUT 13, 850
PULSOUT 12, 750
CASE %001 ' Rotate right
PULSOUT 13, 850
PULSOUT 12, 850
CASE %110 ' Pivot Left
PULSOUT 13, 750
PULSOUT 12, 650
CASE %100 ' Rotate Left
PULSOUT 13, 650
PULSOUT 12, 650
ENDSELECT
PAUSE 20
LOOP
WHat does the bolded part means?
1. Why do i have to set the·3 input pins to high initially?
2. qti.BIT0 = IN3 :· Why do all of the 3 bits of variable qti = IN3?·
3. What does the INPUT 5,6,7 behind indicates?
thanks in advance
' QtiLineFollow.bs2
' Boe-Bot follows electrical tape with 3 QTI modules.
'{$STAMP BS2}
'{$PBASIC 2.5}
qti VAR Nib
DO
Right: HIGH 5: PAUSE 1: qti.BIT0 = IN3: INPUT 5
Center: HIGH 6: PAUSE 1: qti.BIT1 = IN3: INPUT 6
Left: HIGH 7: PAUSE 1: qti.BIT2 = IN3: INPUT 7
SELECT qti
CASE %010 ' Forward
PULSOUT 13, 850
PULSOUT 12, 650
CASE %011 ' Pivot right
PULSOUT 13, 850
PULSOUT 12, 750
CASE %001 ' Rotate right
PULSOUT 13, 850
PULSOUT 12, 850
CASE %110 ' Pivot Left
PULSOUT 13, 750
PULSOUT 12, 650
CASE %100 ' Rotate Left
PULSOUT 13, 650
PULSOUT 12, 650
ENDSELECT
PAUSE 20
LOOP
WHat does the bolded part means?
1. Why do i have to set the·3 input pins to high initially?
2. qti.BIT0 = IN3 :· Why do all of the 3 bits of variable qti = IN3?·
3. What does the INPUT 5,6,7 behind indicates?
thanks in advance
Comments
Examples would be much appreciated.
The easiest way to do ramping is to use a FOR loop and to do something like:
In your case, you've got a more complicated situation. How would you do the same
thing in your case? Remember, each time through your loop, you want to have the
servos go a little faster until they reach the desired speed.
As my boebot jerks when it turns, so i have to use ramping to smoothen the turn. Well that's what i mean.
I pretty much understand your example, but i have no idea how to apply it in my program so that my boebot would turn smoothly.
Sorry to trouble you again, but can you give a detailed example of ramping when the boebot is turning?
Lets say when only the right and middle LEDs detect the black line,
CASE %011 ' Pivot right
PULSOUT 13, 850
PULSOUT 12, 750
How do i modify the code above to smoothen the turning?
Thanks in advance.
Add two variables, oldQti as a nibble and goal as a byte. Initialize oldQti to 15 and goal to 0.
Before the SELECT, do something like:
Before the PAUSE, do something like:
Then, anywhere in your SELECT statement where you have 850, put 750+goal. Anywhere you have 650, put 750-goal.
What this does is to set a goal anytime the QTI value changes. If QTI doesn't change, the program moves closer to its goal every 20ms. Once the program reaches its goal, it stays there until QTI changes again. The goal is used to set the speed of the servos. It takes about 200ms for the goal to be reached.
·From my understanding, the modification you taught me allows the boebot to move from 750 to max speed, which means increase in speed.
Do i have to include so that the boebot reduce its speed whenever it changes direction?
I mean, moving from 750 to maximum speed is enough to prevent jerking?
Post Edited (V360) : 4/15/2008 4:31:13 PM GMT
I tried the modification for ramping, and the boebot aint working at all. Can you please look through my code
I have tried it over and over again in the past few days, and i am making no progress at all.
First of all, the boebot cant follow the line if there's a sharp turn less than 90 degrees.
Secondly, my boebot is still jerking. Can you teach me to slow the boebot down before each turn?
Thank you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
'{$PBASIC 2.5}
'left->5
'right->7
'0 -> detect
'1 -> no detect
store5 VAR Bit
store7 VAR Bit
'==========================================================
DO
' Forward
IF (IN5=1) AND (IN6=0) AND (IN7=1) THEN
GOSUB Forward
'==========================================================
' Right Turn
ELSEIF (IN5=1) AND (IN6=0) AND (IN7=0) THEN
GOSUB Pivot_right
GOSUB Store
ELSEIF (IN5=1) AND (IN6=1) AND (IN7=0) THEN
GOSUB Rotate_right
'==========================================================
' Left Turn
ELSEIF (IN5=0) AND (IN6=0) AND (IN7=1) THEN
GOSUB Pivot_left
GOSUB Store
ELSEIF (IN5=0) AND (IN6=1) AND (IN7=1) THEN
GOSUB Rotate_left
'==========================================================
ELSE
IF (store5=1) AND (store7=1)
'stop
ELSEIF(store7=0)AND (store5=1)THEN
GOSUB Rotate_right
ELSEIF(store7=1)AND(store5=0)THEN
GOSUB Rotate_left
ENDIF
ENDIF
'PAUSE 20
LOOP
Forward:
PULSOUT 13, 800
PULSOUT 12, 700
RETURN
Pivot_right:
PULSOUT 13, 800
PULSOUT 12, 750
RETURN
Rotate_right:
PULSOUT 13, 800
PULSOUT 12, 800
RETURN
Pivot_left:
PULSOUT 13, 750
PULSOUT 12, 600
RETURN
Rotate_left:
PULSOUT 13, 700
PULSOUT 12, 700
RETURN
Store:
store7=IN7
store5=IN5
RETURN
By the way the boebot is still jerking pretty badly. But the priority is to solve the sharp turns first.
Anyway thanks.