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

Sonar

AImanAIman Posts: 531
edited 2006-08-01 20:03 in Robotics
First the basics:
Stamp = BS2
Robot = about 12 inches wide in a circular shape
Speed = half of walking

I am working on a robot that goes down the hallway and have most of the stuff down. Instead of using whiskers and bump switches I am using an SRF05 sonar unit that is virtually idenitcal to PING))).
My question is this - what sort of programing would I use to get results from the Sonar?
I know I am close but keep getting stumped. In Psudeo code the sub reads like this.

Check distance left
Check distance right
if left is greater then right stear left
if left is out of range then stay 12 inches away from wall
if right is greater then left stear right
if right is out of range then stay 12 inches away from wall
if left and right are equal do nothing

I can get everything working but am having difficulty understanding and doing the programing terminalogy for using a Sonar with the BS2.

The other part of this scenario is if its better to go with IR, a camera, a laser set up or somthing else.

Thoughts?

Comments

  • AImanAIman Posts: 531
    edited 2006-07-24 03:19
    Anyone?
  • SSteveSSteve Posts: 808
    edited 2006-07-24 04:42
    Just a guess, but it might help if you posted the SRF datasheet and your existing code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • aridaiosaridaios Posts: 57
    edited 2006-07-24 05:30
    There is sample code for SRF05 module at http://www.robot-electronics.co.uk/shop/Examples.htm

    Michael
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-24 07:21
    AIman -

    The attached Parallax PDF for the SRF-04 should answer all of your questions.

    Regards,

    Bruce Bates
  • AImanAIman Posts: 531
    edited 2006-07-25 21:46
    I can't find my disk with the most recent code, but here is an early version. Basicly·if the sonar on the right trips indicating something within 5·in of the robots body it will steer left until it is at a distance greater then 5·in and then shuts off the servo.

    if IN1 <= 20·and·IN2>IN1 goto Z····
    ' if the·right·sonar picks something up and the·left sonar doesn't find anything go straight

    If IN1=IN2 then·goto Z
    ' if both sonar show equal distances go straight

    if IN1<N2····
    ···· Do
    ·····' Keeps turning until the distances are equal

    ···· SEROUT net,baud,[noparse][[/noparse]"!1R1FF"]
    ···· SERIN net,baud,[noparse][[/noparse]char]
    ···· 'Makes the servo turn to steer away from the object

    ···· Loop until IN1 = IN2 or IN1 >=20
    ···· ' Makes the robot turn away but ignores things out of range on the·other side

    End if

    Z:

    Jargon about steering straight
    ·
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-25 22:04
    AIman -

    At the possible risk of impinging on your "handle" of "AIman", please take a look at what you're saying here, even before your eventual questions. Before you do so, however. picture YOURSELF approaching a 90 degree corner:

    "... if the sonar on the right trips indicating something within 5 in of the robots body it will steer left until it is at a distance greater then 5 in and then shuts off the servo."

    If you don't see a problem with that logic, I do!

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Matt WhiteMatt White Posts: 60
    edited 2006-07-25 22:16
    AIman,

    Okay try this... take a look at the video for the PING sensor. Observe the robots "logic" in selecting an appropreate heading. I would suggest modifying the example code to use your SRF05 instead of the PING sensor (strip out the IR proximity detection stuff too for simplicity - you can always add it back in later if that's in your design).

    Video and PING example code found here:
    http://www.parallax.com/detail.asp?product_id=28015

    I think this would be a better starting point for what you're trying to do.... imho.

    Thanks,
    Matt
  • AImanAIman Posts: 531
    edited 2006-07-26 03:06
    Thanks for the replies.

    A few comments:

    Bruce Bates - Please note the first line of code designed specificly so that if something is out of range it is accounted for and dealt with.

    if IN1 <= 20 and IN2>IN1 goto Z
    ' if the right sonar picks something up and the left sonar doesn't find anything go straight

    This line of code has proven to be rather effective so far, it needs to be drilled down more to isolate distances and account for additional sonar units.

    Also there is a sub I am working on for directional control for doing things like going down a hallway and a door is half open. It runs along the thought of wait a second and see if the object moves. If it moves and gets closer steer clear, if it doesn't move and is outside of danger zone keep going straight. If danger zone is invaded then avoid object.



    Matt White - I have looked at the link you refer to and right now my robot runs with a single SRF05 and two bump sensors. The biggest problems I am having are how to use multipule sensors together without creating false readings on the other sonar and how to use the sonar for all sides to get maximum sensory perception. I considered IR but the issue of bright sunlight coming through a window concerns me. On the final project the sonar will ring the body with something like sonar or IR for clearance and drop off detection.

    Thanks again for the feed back.
  • FranklinFranklin Posts: 4,747
    edited 2006-07-29 21:14
    I used the code for the ping on a boebot and it worked with one basic change. The SRF05 uses two pins by default and I rewrote the code because it was easier than changing the jumper.

    I attached the code I used, hope it helps. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen

    Post Edited (Franklin) : 7/29/2006 9:30:25 PM GMT
  • AImanAIman Posts: 531
    edited 2006-08-01 19:40
    Thanks very much for the SRF05 code.
    My plans right now are to use 4 sonar arrays around the body of the robot (one on each side) with one on top in front for clearance and one on bottom in front for edge detection. I might be able to use only two upfront instead of three but haven't gotten to the point of working on that yet. (That would be one for going forward, one for clearance and one for edge detection.) Eventually, I hope to have my robot be able to take stairs...
    The suggestion of using IR for clearance and edge detection was made, however I am tending to shy away from that because of bright light issues. Originally I was seriously considering it, but if the lights are on in the hallway and a curtain on a window is pulled back the light on the floor is enough to cause problems.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-01 20:03
    AIMan -

    I'm doing this from memory, and I don't have a handy reference or link for you, but as I remember others who have tried edge detection with SRF-0X units (and similar units) have been very unhappy with their performance. That is really not an appropriate application for this type of sensor. They're intended for measuring distance, and not absense or presence of a drop-off.

    As always, YMMV!

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
Sign In or Register to comment.