Shop OBEX P1 Docs P2 Docs Learn Events
The Boe-bot — Parallax Forums

The Boe-bot

zianaziana Posts: 5
edited 2008-04-22 14:17 in Robotics
Hi,

I use the book "Robotics with the Boe-Bot" by Andy Lindsay.

I have a question regarding the coding that Andy Lindsay use in the
book.

-->FOR counter = 1 to 64
--> PULSOUT 13, 650
--> PULSOUT 12, 850
--> PAUSE 20
-->NEXT

Andy Lindsay put a value of 20 for PAUSE command which means 20
millisecond pause for the motor servo for each rotation. So, my question is
why Andy Lindsay put 20 ms for pause? Why not for example 50ms?

Why do we have to put PAUSE command?

Thanks for helping.

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-04-21 12:40
    It has to do with how servos work. The signal they expect is a pulse of between 1 to 2 ms every 20ms.

    The two PULSOUT statements generate the pulse and the pause 20 statement does the wait for 20ms for each cycle.

    Hope this helps.
  • zianaziana Posts: 5
    edited 2008-04-21 13:34
    "The signal they expect is a pulse of between 1 to 2 ms every 20ms."

    Are you saying that the two PULSOUT statement generate a pulse of between 1 to 2 ms?

    So, what happens if the PAUSE statement increase from 20 ms to (let's say) 100 ms? Will it affect the RPM (Revolution Per Minute)?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-21 13:45
    Yes, each PULSOUT statement generates a pulse. As described in the Basic Stamp Manual, the units are 2us, so a "PULSOUT 13,650" produces a 1.3ms pulse on I/O pin 13. The width of the pulse roughly determines the direction and speed of the servo with pulses shorter than 1.5ms causing rotation in one direction and pulses greater than 1.5ms causing rotation in the other direction. The greater the pulse width differs from 1.5ms, the faster the speed although the speed : pulse width relationship varies from servo to servo and is not accurate.

    If the PAUSE is increased, the servo will turn itself off at some point and no longer hold position (until the next pulse comes along). This threshold varies from servo to servo, but I think it's around 50ms.
  • zianaziana Posts: 5
    edited 2008-04-21 14:11
    oh i see.

    Here's my other question.

    I'm using different frequencies to follow an object.
    ___________________________________________

    FOR freqSelect = 0 TO 4

    LOOKUP freqSelect, [noparse][[/noparse]37500, 38250, 39500, 40500, 41500], irFrequency

    _______________________________________________________-

    Since the zones are overlapping each other (I hope you all know what I mean), I've tried to use different frequencies based on the appendix in the book.

    But, I still can't get the suitable frequencies because the zones are overlapping. Is there other way (besides the appendix in the book), to get suitable frequencies?

    Thanks again.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-21 14:20
    That looks like the "detuned" FREQOUT frequencies, used in the clever "giving a range to an IR-Detector" method.

    Since 37500 works "the best" -- has the LONGEST range -- I'd tend to run the frequencies in the opposite direction you're running them.

    In other words, it should be 41500 FIRST, not last. Although, having said that, running the 37500 first means you'll detect an object at the longest possible range, then 'step' in the ranges until you don't detect it anymore -- which I guess is useful, so I withdraw my comment.

    One attribute of the IR-Detector method is that it is "fuzzy" -- you get 'approximate' results -- an object is "far" or "close". You're not going to get repeatable "It's 1", 3", 5" away" kinds of measures. Still, getting ANY kind of range indication from what was supposed to be ONLY a 'detect', 'can't detect' measurement is pretty good.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-21 14:29
    I'm not sure what you are trying to do with the IR detector.

    Remember that the IR distance sensing uses an anomaly of the IR detector in that the selectivity of the detector to the IR modulation frequency is imperfect and, by varying the frequency of the IR beam, the detector exhibits different sensitivities to the light and its effective threshold varies.

    You may have to calibrate your particular detector by writing a short program to step through a set of frequencies, changing when you press a pushbutton and turning on an LED when the detector responds. By graphing the curve of frequency vs. distance, you can determine your own "zones" and choose frequencies that don't overlap or overlap the way you want them. Since the amount of reflected IR depends on the materials, the angle of incidence of the light, etc., you will want to use your actual setup and the object you want to follow to do the calibration.
  • zianaziana Posts: 5
    edited 2008-04-21 15:16
    37500 has the longest range and 41500 has the shortest range.

    Let's say I use 3 frequencies, 37500, 39500 & 41500. and I arrange them like this:

    ___________________________________________

    FOR freqSelect = 0 TO 4

    LOOKUP freqSelect, [noparse][[/noparse]41500, 39500, 37500], irFrequency

    _______________________________________________________-

    Then, the zone 0 (when the object is near to the robot) is 41500, zone 1 is 39500, zone 2 is 37500 (when the object is far from the robot). Is it so?

    "By graphing the curve of frequency vs. distance, you can determine your own "zones" and choose frequencies that don't overlap or overlap the way you want them." quoted from Mike's comment.

    Why is it that for e.g. I use 37500 and it detects the object when the distance between the object and IR detector is 30 cm, but when I put the object near to the detector (somewhere between 0 to 30 cm), the detector doesn't detect the object?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-21 16:11
    Perhaps because your LOOKUP statement has 3 frequencies and the index (freqSelect) varies over 5 values?

    Truthfully, I don't know. Maybe the detector is getting overloaded at close range. That's another good reason for starting with the least sensitive "zone".

    The FREQOUT statement itself doesn't do what you probably think it is doing. On the BS2, it has a limit of 32767Hz (see the manual). The actual waveform is produced via PWM and the averaging to produce the waveform happens in the detector since the LED can respond rapidly to the PWM pulse stream. Above 32768Hz, the frequency of the harmonic is supposed to be 65536 - FREQOUT frequency according to the manual. I suspect this is an artifact of the algorithm used to produce the PWM signal.

    As allanlane5 suggested, this is a cheap technique for getting rough distance detection with simple parts that were not intended for this use.
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-21 17:19
    Well, as you've said, the zones "overlap".

    So, 37500 covers ALL zones. 41500 is a "closer" zone. If it's in 41500, it should also be in 37500. If it's in 37500 but NOT in 41500, you know it's "further away" than zone 41500. In other words, the detection distances are circles, not 'bands'.

    I don't know why something detected at 30 cm wouldn't also detect at zero cm -- all you're "detecting" is the reflection of IR light into the IR-Detector. Now probably 'position' matters -- if you're trying to detect a flat mirror that's turned 45 degrees (or a square robot corner-on to you) that might be very difficult to detect.
  • zianaziana Posts: 5
    edited 2008-04-22 08:49
    Is there any way I can check if my IR LED is malfunctioning? Or and also my IR detector?

    Mike Green, what do you mean by PWM?

    Here's the other question.

    FREQOUT 8, 1, 38500

    My question is why did Andy Lindsay put 1 ms to send 38500 to P8? What happen if it is more than 1 ms? What's the difference?

    Thanks.

    Post Edited (ziana) : 4/22/2008 8:56:35 AM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-04-22 14:09
    If you have a digital camera, you can aim it at your IR LED, and you should see it flashing in the LCD image on the Digital Camera. Digital Camera's can see Infrared light.

    The "Using an IR-LED with IR-Detector for collision detect" approach just needs enough IR modulated light (aka "Blinking at 38500 Hz) to trigger the Detector. 1 millisecond is enough for that. More than one millisecond would work, but takes more time.

    Actually the BS2 is using a very helpful attribute of the IR-Detector chip -- that it has some "latency". Namely, its output stays "LOW" for a little bit after the IR-LED has cut off. This gives the BS2 time to 'read' the state of the IR-Detector. But you MUST read the IR-Detector pin IMMEDIATELY after the FREQOUT statement for this to work.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-22 14:17
    PWM: Pulse Width Modulation

    See this Wikipedia article: en.wikipedia.org/wiki/Pulse-width_modulation
Sign In or Register to comment.