by Marsman » Mon Aug 16, 2010 5:33 am
by Marsman
Mon Aug 16, 2010 5:33 am
Hi,
I know, I should have bought the I2C version of the Ultra-Sonic sensors (SRF08 or SRF10) but I have not. The operation of the SRF05 (or SRF04) still is quite simple but I wonder which are the best library elements of the RB100 SW to use.
I connect the Trigger Input / Echo Output of SRF05 (Mode 2 - single pin) to one of the PWM ports (her channel 10) and intend to use the rcservo.h library. A sequence similar to this should do:
rcservo_Initialize(RCSERVO_USECHANNEL10);
rcservo_EnterPWMMode();
rcservo_SendPWMPulses(10, 15L, 14L, 1): // send 1 pulse of 15us to SRF05
while (!rcservo_IsPWMCompleted(10)); // wait until finished
while (in_value = rcservo_Inp(10) = 0); // check for rising edge of return signal
t1 = localtime(&tv.tv_sec); // will build a function to get system time in micro-seconds
while (in_value = rcservo_Inp(10) = 1); // check for falling edge of return signal
t2 = localtime(&tv.tv_sec); // will build a function to get system time in micro-seconds
pulse_length = t2 - t1; // return signal length in micro-seconds
Would you please comment if that would work with enough accuracy to determine the object's distance? To improve statistics I could put the measurement into a loop to repeat say 10 times.
I wonder if any of the servo commands in "Capture Mode" could be used to determine the return signal's pulse length?
Best regards,
Marsman
Hi,
I know, I should have bought the I2C version of the Ultra-Sonic sensors (SRF08 or SRF10) but I have not. The operation of the SRF05 (or SRF04) still is quite simple but I wonder which are the best library elements of the RB100 SW to use.
I connect the Trigger Input / Echo Output of SRF05 (Mode 2 - single pin) to one of the PWM ports (her channel 10) and intend to use the rcservo.h library. A sequence similar to this should do:
rcservo_Initialize(RCSERVO_USECHANNEL10);
rcservo_EnterPWMMode();
rcservo_SendPWMPulses(10, 15L, 14L, 1): // send 1 pulse of 15us to SRF05
while (!rcservo_IsPWMCompleted(10)); // wait until finished
while (in_value = rcservo_Inp(10) = 0); // check for rising edge of return signal
t1 = localtime(&tv.tv_sec); // will build a function to get system time in micro-seconds
while (in_value = rcservo_Inp(10) = 1); // check for falling edge of return signal
t2 = localtime(&tv.tv_sec); // will build a function to get system time in micro-seconds
pulse_length = t2 - t1; // return signal length in micro-seconds
Would you please comment if that would work with enough accuracy to determine the object's distance? To improve statistics I could put the measurement into a loop to repeat say 10 times.
I wonder if any of the servo commands in "Capture Mode" could be used to determine the return signal's pulse length?
Best regards,
Marsman