Parallel processing
samal
Posts: 8
Hi,
I am trying to achieve the following:
step 1:
I hold some'thing' like a box or an orange in front of my robot.
step 2:
the robot 'sees' it with its IR 'eyes'.
step 3:
IF (i move the 'thing' towards the robot) THEN
my robot should move away
ELSEIF (the 'thing' stays in place) THEN nothing happens
ELSEIF (the 'thing' moves away) THEN
my robot should move towards the 'thing'.
ENDIF
Now, the problem i am facing is like this (you can refer my attached code):
the robot is getting 'glitches' the movement is not smooth. I guess if it were possible to read the distance as the robot moves, it should behave more smoothly but dunno cuz i tried and it didnt work.
the IR 'eye' works perfectly fine, when i make the robot move in autonomous mode.
~ Sam ~
I am trying to achieve the following:
step 1:
I hold some'thing' like a box or an orange in front of my robot.
step 2:
the robot 'sees' it with its IR 'eyes'.
step 3:
IF (i move the 'thing' towards the robot) THEN
my robot should move away
ELSEIF (the 'thing' stays in place) THEN nothing happens
ELSEIF (the 'thing' moves away) THEN
my robot should move towards the 'thing'.
ENDIF
Now, the problem i am facing is like this (you can refer my attached code):
the robot is getting 'glitches' the movement is not smooth. I guess if it were possible to read the distance as the robot moves, it should behave more smoothly but dunno cuz i tried and it didnt work.
the IR 'eye' works perfectly fine, when i make the robot move in autonomous mode.
~ Sam ~
bs2
1K
Comments
Basically, you replace the "nothing happens" choice with "if count > 0 then decrement count; move forward or backward depending on saved status".
You should be able to figure out the other choices.
Anyway, amout the glitch. To get a smooth movement of the servo, you need to refresh the servos every 20 ms. Take a look at your code: you're refreshing them at ~100ms. Also, the servos would do a little bit better in a loop with ramping, especially in a following situation. So, here a couple of suggestions:
a) change the pause 100 to pause 20. Not perfect, but ~okay.
or
b) get the distance measurements in a for loop, then calculate what you want to do, then put the servo pulsout in a loop of it's own. If you give that loop about 100 ms, you should see enough response time while saving your servos.
Also, you should ramp your servos. Take a look at Robotics with the Boe-Bot (available for download free) and you can see how to do this.
And don't worry about the servo timing cuz i modified the servo myself for continuous rotation and while doing so, i mistakenly fixed its middle/stop at 500 instead of 750.
Look guys, the pause within the main loop is commented
DO
prevDistance = currDistance
currDistance = 0
' the following is taken from basic stamp tutorial presentations
FOR freqselect = 0 TO 4
LOOKUP freqselect,[noparse][[/noparse]37500,38250,39500,40500,41500],irFrequency
FREQOUT 6,1,irFrequency
irDetect = IN7
currDistance = currDistance + irDetect
'PAUSE 80
NEXT
' the following is very simple logic
IF (currDistance < prevDistance) THEN 'robot moves away from the object which comes towards it
GOSUB Go_Reverse
ELSEIF (currDistance = prevDistance) THEN 'robot stays inplace when the object stays in place
GOSUB Pause_Here
ELSE 'if the object moves away, robot should follow it
GOSUB Go_Forward
ENDIF
LOOP
and the pauses in the forward and reverse logic is also commented
' Subroutine for going reverse
Go_Reverse:
'FOR freqselect = 0 TO 8
PULSOUT 0, 250
PULSOUT 1, 250
' PAUSE 20
'NEXT
RETURN
' Subroutine for going forward
Go_Forward:
'FOR freqselect = 0 TO 8
PULSOUT 0, 750
PULSOUT 1, 750
'PAUSE 20
'NEXT
RETURN
' Subroutine for going forward
Pause_Here:
LOW 0
LOW 1
RETURN
i believe the main loop is giving enough delay for the servo (something close to or more than 20 ms). still the same prob. + additional prob is now the robot kind of jitters in forward/backward movement with the 'thing' moving towards it or going away from it.
anyway a better, cleaner and smoother way would be to use the ultrasonic sensor for this purpose but i dont want to spend on that if my IR could solve the purpose.
Ah! i wish the basic stamp homework kit had a ADC on it!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
and I think (not sure) it does make a difference if we use IR or ultrasonic cuz IR gives a bland 1 or 0 only to basic stamp 2 and the ultrasonic can give close range values. And I dont have a ADC to measure IR input to calculate range. if there is any way that IR can do the same thing as ultrasonic then please let me know cuz i need not buy an ultrasonic then and that saves me lot of funds.
thanks,
~ sam ~
You might try an experiment with this in mind, to find out what the various "ranges" of IR-Reflection and Detection you could get with this method.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I`m not prejudice I hate everyone equally
until then!
~ Sam ~
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I`m not prejudice I hate everyone equally
Even if it is safe to send a pulse or 400-1100, a pulse 250x the maximum is sure to break something... Try it and see what happens.
i have others on the list that have to get done
one of them being my graduation project
i am builin an LED sign
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I`m not prejudice I hate everyone equally
???