Shop OBEX P1 Docs P2 Docs Learn Events
PBasic Program ? response of servo to Sonar Distance — Parallax Forums

PBasic Program ? response of servo to Sonar Distance

ArchiverArchiver Posts: 46,084
edited 2002-06-30 19:26 in General Discussion
I have managed to write simple pbasic code for BS2 stamp that
allows a servo to respond to distances produced by my sonar...
Problem seems to be in my code... Below is not the exact code
just then basic concept:

Sonarsweeep:
'Distance found by sonar'
if distance< 60 or distance > 80 then Sonarsweep
if distance > 60 or distance<80 then B1

B1:
'rotate servo 180'
'pause for servo full turn'
goto Sonarsweep

Problem:
If distance consistently registers <60 or > 80 the servo will pulse
or shake at every given reading until this statement is not true... I
would like the servo to make the full turn on first true statement
and if the statement is between <60 and >80 again I would like
to ignore it and return to sonar sweep until it is not true. This is a
first step to having many responses to differing distance
readings with a few servos. If you have any advice it would be
much appreciated.

Thanks
MLD

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-06-30 19:26
    You may want to do some experimenting first to determine the PULSOUT values
    that will give you a sweep in the incremental degrees you desire. Then you
    can create a LOOKUP table of these values to control the position.

    Your program can that set the sonar to a given sweep angle, take a
    measurement, then decide to proceed to the next value or not.

    Note: You may not have used it in your actual code ... be careful of the use
    of "B1" as an address label as this is an internal variable name used by the
    Stamp compiler.

    -- Jon Williams
    -- Applications Engineer, Parallax


    In a message dated 6/30/02 12:14:31 PM Central Daylight Time,
    mldunleavy@y... writes:


    > I have managed to write simple pbasic code for BS2 stamp that
    > allows a servo to respond to distances produced by my sonar...
    > Problem seems to be in my code... Below is not the exact code
    > just then basic concept:
    >
    > Sonarsweeep:
    > 'Distance found by sonar'
    > if distance< 60 or distance > 80 then Sonarsweep
    > if distance > 60 or distance<80 then B1
    >
    > B1:
    > 'rotate servo 180'
    > 'pause for servo full turn'
    > goto Sonarsweep
    >
    > Problem:
    > If distance consistently registers <60 or > 80 the servo will pulse
    > or shake at every given reading until this statement is not true... I
    > would like the servo to make the full turn on first true statement
    > and if the statement is between <60 and >80 again I would like
    > to ignore it and return to sonar sweep until it is not true. This is a
    > first step to having many responses to differing distance
    > readings with a few servos. If you have any advice it would be
    > much appreciated.
    >
    > Thanks
    > MLD
    >




    [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.