Shop OBEX P1 Docs P2 Docs Learn Events
Parallel processing — Parallax Forums

Parallel processing

samalsamal Posts: 8
edited 2008-10-10 01:45 in BASIC Stamp
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 ~

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-08 22:45
    In order to get smooth movement, you're going to have to interleave the robot movement with further IR distance sensing. In your program, once you detect movement of the 'thing', you commit to a long pulse output which prevents any further IR sensing until the pulse is done. Better would be to break up the movement into 10 or 50 shorter movements (shorter pulses) and do IR detection between the shorter movements. You'd need to keep a count of the number of shorter movements so your program would know when to stop if nothing changes with the IR sensor.

    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.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-08 22:51
    Danger: Your pulsout is too large! To control a servo with the BS2, you need to give at a pulsout value of 500 to 1000, with 750 the middle/stopped. Anything outside these bound can permenently damage your servo. Believe me, I've done it and had to throw out a good servo.

    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.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-08 22:52
    Ha. I knew somebody would post while I was writting. So now, samal, you have more options. The more the merrier...
  • samalsamal Posts: 8
    edited 2008-10-09 06:03
    thx guys. I already played with the PAUSE thingy but still its having the same prob even though there was a little bit enhancement.

    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!
  • FranklinFranklin Posts: 4,747
    edited 2008-10-09 15:07
    It does not matter if you use IR or ultrasonic. On either you need to test for the distance and then do some reaction. With the same Pulseout to both servos isn't your bot going in circles?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • samalsamal Posts: 8
    edited 2008-10-09 16:01
    theoretically, it should but nope, it isn't going in circles (and i do not have the slightest idea why).

    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 ~
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-09 16:05
    There was a very clever technique to "detune" the FREQOUT frequency. Put out 28,000 HZ, and you only detect things within a few inches. 32,000, you get a few more inches, 38,000, you get the 'full range' (whatever that is).

    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.
  • Lab RatLab Rat Posts: 289
    edited 2008-10-09 16:10
    Apparently you have not learned the fine art of taking servos apart to try and fix them normally a few teeth break and cannibalism of another broken servo usually fixes the problem so i would keep around a bin of the broken servos i had to fix them because i too over pulsed them plus i have a limited budget. as for over pulsing i personally test the limits of my servos individually to see how far i can take them do to limited places and methods of attaching them normally i find that they can go about a 100 pulses over what they are rated. but when testing only exceed the previous test by 5 or 10 additional pulses

    SRLM said...
    Danger: Your pulsout is too large! To control a servo with the BS2, you need to give at a pulsout value of 500 to 1000, with 750 the middle/stopped. Anything outside these bound can permenently damage your servo. Believe me, I've done it and had to throw out a good servo.

    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.
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I`m not prejudice I hate everyone equally
  • samalsamal Posts: 8
    edited 2008-10-09 17:04
    i would try Allan's suggestions and get back soon. Ya, I agree with the idea of 'not throwing away the servos'. cuz if the servo is damaged (which probably means the circuitry is damaged), then the circuitry can be removed to make it a great dc gear motor and use an h-bridge to control it (saw that in many robotics websites).

    until then!
    ~ Sam ~
  • Lab RatLab Rat Posts: 289
    edited 2008-10-09 17:26
    i never thought of that i will have to try that some time. with me it was always the gears. but at school they burn out the control circuits (but they use them hard core because of a robotics competition )

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I`m not prejudice I hate everyone equally
  • samalsamal Posts: 8
    edited 2008-10-09 17:31
    here is the link for re using a damaged servo: http://www.solarbotics.com/assets/documentation/kit10.pdf
  • SRLMSRLM Posts: 5,045
    edited 2008-10-09 19:48
    Lab Rat:

    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.
  • Lab RatLab Rat Posts: 289
    edited 2008-10-10 00:45
    i have not worked on that project lately but i will be in a few months
    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
  • MovieMakerMovieMaker Posts: 502
    edited 2008-10-10 01:45
    If it is going around in circles, it seems that you either have power only to one motor or have the other motor reversed.

    ???
Sign In or Register to comment.