Shop OBEX P1 Docs P2 Docs Learn Events
Servo and Sonar — Parallax Forums

Servo and Sonar

ZactlyZactly Posts: 7
edited 2006-12-29 19:14 in Robotics
Question

I am writing a code to have two sonar mounted back to back on a pole extending from a servo. The servo rotates 180 degress while the sonar pulse.
Right now I am running 5 variables interpersed in the loop for the servo to run the sonar which takes up a lot of code room.

When the servo turns and the sonar pulses, is it better to use a dynamic array, static array, a·preset servo position to trigger sonar·or simply run a half dozen variables to capture data?

·

Comments

  • AImanAIman Posts: 531
    edited 2006-12-26 15:39
    So you are wanting to know which is best?

    My opinion is to use an array and increase by the loops.

    Example

    num = 0
    For counter = 1 to 150 step 5
    Trigger sonar
    capture results
    results = results(num)
    num=num+1
    next

    Then compare the results to figure out which one is smallest.

    num = 0
    if resutls(num) <= results(num)+1 then
    if results(num) <= results(num)+2 then
    etc...

    Course by the time your done it would be as short to simply run multipule variables like you are doing.
  • PARPAR Posts: 285
    edited 2006-12-26 20:15
    Zactly said...
    Question

    I am writing a code to have two sonar mounted back to back on a pole extending from a servo. The servo rotates 180 degress while the sonar pulse.
    Right now I am running 5 variables interpersed in the loop for the servo to run the sonar which takes up a lot of code room.

    When the servo turns and the sonar pulses, is it better to use a dynamic array, static array, a·preset servo position to trigger sonar·or simply run a half dozen variables to capture data?

    You haven't really stated what you want to measure (distance(s), yes; but why? under what conditions? why two (quasi-simultaneous?) measures at 180degs?·what decisions/actions will you take based on your data collecting?)

    How many measurements per rotation? How fast (rpm)?

    Show your current code so folks can see why it "takes up a lot of code room".

    Without knowing this kind of information, it's kind of difficult to speculate what problem you wish to solve or how best to go about inventing a solution.

    PAR
  • ZactlyZactly Posts: 7
    edited 2006-12-27 18:01
    I don't think its that hard to figure out. Its a simple data collection question not·a research·project.
  • PARPAR Posts: 285
    edited 2006-12-27 20:05
    Zactly said...

    I don't think its that hard to figure out. Its a simple data collection question not·a research·project.

    OK.
  • AImanAIman Posts: 531
    edited 2006-12-28 17:22
    Ya know, Something else occured to me.

    Why not set up a single variable in your servo loop so it triggers an outside equation once the peramiters get tripped?

    For example

    For counter = 1 to 150 step 5
    Servo stuff
    Sonar stuff with return pulse saved under distance
    Next

    If Distance >= saftey area then do something


    Follow me?
  • ZactlyZactly Posts: 7
    edited 2006-12-29 19:14
    I think I will go with the suggestion of a single variable inside the loop for the servo. It seems to be the best option with the least amount of problems. I can run the variable and slow down the servo loops or run a While statment to handle the servo.

    Thanks AIMan
Sign In or Register to comment.