PDA

View Full Version : sonar



jimbobjones
- 21st May 2007, 12:23
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:


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:

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

Kenjones1935
- 2nd March 2010, 04:13
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

mtripoli
- 2nd March 2010, 17:43
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

aratti
- 2nd March 2010, 17:58
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.

Bruce
- 2nd March 2010, 19:08
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

jimbobjones
- 3rd March 2010, 14:34
wow a blast from the past.

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

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

Kenjones1935
- 3rd March 2010, 20:52
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

Kenjones1935
- 4th March 2010, 04:00
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