sonar


Closed Thread
Results 1 to 8 of 8

Thread: sonar

  1. #1
    Join Date
    Apr 2007
    Posts
    12

    Default sonar

    i'm using an ultrasonic SRF05 range finder sensor along with pic16f876 and a couple of LDR sensors.

    i'm using the sonar module to detect objects above my robot.

    if distance >= 4 then

    m_detection = 0
    'stop

    else

    m_detection = 1
    'move forward

    end if


    The problem is as follows:

    if an object is at a distance of more than 4inches then it stops, if the object is < 4inches away then it moves forward, this is working as it should. The problem happens when there is no object at all - the motors just shudder :S

    now also if i comment out the LDR code the sonar appears to work...

    Sonar Ping :

    Code:
    Code:
    sonar:
    
    '---------PING----------------------------------------
    sonarcontrol = 1 				 'module on
    trigger = 0
    pulsout trigger, 1  
    
    pulsin echo, 1, range 			 'measure high state
    
    if range <> 0 then	  			 'if pulsin times-out it returns 0
       distance = range /  15 		 'convert: 15=inches at 4MHz
    end if
    
    sonarcontrol = 0 	  			 'module off
    '-----------------------------------------------------
    
    return
    Reading the LDRs

    Code:
    Code:
    
    check_LDR:
    
      HIGH portb.4 'Right_LDR               	  'Make right CDS pin high
      PAUSE 3                      	 	  		  ' Let cap charge
      RCTIME portb.4, 1, LDR_Right_RCdata 		  ' Time & record discharge time 
    
    
      HIGH portb.5 'Left_LDR                	  'Make left CDS pin high
      PAUSE 3                      				  ' Let cap charge
      RCTIME portb.5, 1, LDR_Left_RCdata   		  ' Time & record discharge time
    
    LDR_Right_Val =  NCD LDR_right_RCdata
    LDR_Left_Val =   NCD LDR_left_RCdata
    return
    i've been struggling with this for some time now and i'm fairly confused.. any pointers would be very helpfull

    thanks

    jim

  2. #2
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default Did you ever get the SRF05 to work?

    Jim,

    I have been struggling with PULSOUT and PULSIN with a SRF05. The PULSIN command is writing zero into the range register even though my oscilloscope shows a perfectly good response coming from the proximity sensor.

    Did you resolve your problem almost three years ago?

    Ken Jones

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kenjones1935 View Post
    Jim,

    I have been struggling with PULSOUT and PULSIN with a SRF05. The PULSIN command is writing zero into the range register even though my oscilloscope shows a perfectly good response coming from the proximity sensor.

    Did you resolve your problem almost three years ago?

    Ken Jones
    I did a bunch of sonar stuff on a little robot years ago so was intrigued by your post. I haven't used the SRF05 but found a little info about it at http://www.robot-electronics.co.uk/htm/srf05tech.htm.

    I'd ask a couple of questions based on what you're seeing:

    When using PULSIN what is STATE set to? It looks like the response from the SRF05 is a high pulse so STATE has to be set to a "1". The manual says "If the pulse edge never happens or the width of the pulse is too great to measure, Var is set to zero.

    What is the period of the PULSOUT command. The SRF05 doc says it needs to be a minimum of 10uS. That's a "1" for a 4MHz osc.

    Are you doing anything between the trigger pulse (PULSOUT) and the PULSIN? If so you may be blowing right by the leading edge and the PIC is seeing nothing so it returns a zero in VAR.

    The manual also says "The resolution of PULSIN is dependent on the oscillator grequency. If a 4MHz oscillator is used, the pulse width is returned in 10uS increments. (Paraphrase) "if 20Mhz pulse width is 2uS". OSC value has no effect on PULSIN. What is the width of the pulse coming back?

    Answering those to start should get you on the right track...

    Mike Tripoli

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    i've been struggling with this for some time now and i'm fairly confused.. any pointers would be very helpfull
    jim, instead to take one sample at the time, from your sonar, take several samples and average them, to have a more reliable reading and as conseguence a more reliable behavior of your robot.

    Al.
    All progress began with an idea

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    We have several PBP code examples for the SRF04 (works the same as the SRF05), and
    using photocells in our Micro-Bot projects section you might find helpful.

    http://www.rentron.com/Micro-Bot/Sonar.htm

    Main page: http://www.rentron.com/Micro-Bot/index.htm
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Apr 2007
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    wow a blast from the past.

    Does it normally take 3years to get a response around here

    i cant remember the ins & outs of it now but it looks like there are some good suggestions posted

  7. #7
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default I think I found a solution, but...

    My problem was that the length of the PULSOUT pulse was way toooo long. This was true even if I did a PULSOUT trigfront, 1. I have no explanation for that behavior of a 16F887.

    So I changed PULSOUT to:


    HIGH trigfront
    PAUSE 1
    LOW trigfront.
    Followed by a PULSIN.

    Why? I am modifying a hobby level radio control car to toggle between RC and autonomous control. The project has been the theme of
    "PBP projects for R/C models" thread for a some months.

    With the above fix the car seems to respond correctly on its blocks with me moving a oak cutting board in front and on the right side to simulate the inside a room with no furniture.

    Thanks, gang. Whoever you are.

    Ken

  8. #8
    Join Date
    Nov 2009
    Location
    Fitchburg, Mass
    Posts
    483


    Did you find this post helpful? Yes | No

    Default It works! But there may be a problem

    I have the car running around on the floor being guided by its PIC. This is a hobby level car with electronic speed control and continuous servo steering.

    The steering seems to respond too slowly. Particularly when told to steer straight. That is the position of no current into the servo. I'm not sure there is a fix for this short of going to a toy level car with a bang bang servo and a mechanically controlled neutral.

    Ken

    Ken

Similar Threads

  1. Replies: 23
    Last Post: - 23rd September 2008, 18:20
  2. PIC based SONAR
    By PICtron in forum Off Topic
    Replies: 1
    Last Post: - 3rd February 2005, 21:44
  3. sonar transducers
    By cjsanders in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th November 2004, 11:37

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts