Code

10 views
Skip to first unread message

Brian Higgins

unread,
Sep 4, 2021, 7:40:30 PM9/4/21
to hbrob...@googlegroups.com
What line of code controls the distance at which the Lidar lite V3 detects an object?


*/


 unsigned long pulse_width;


 

void setup()

{


pinMode( 2, OUTPUT ); // Set pin 2 as trigger pin

digitalWrite( 2, LOW ); // Set trigger LOW for continuous read

pinMode( 3, INPUT ); // Set pin 3 as monitor pin


 

pinMode( 9, OUTPUT ); // Vibe motor output


 pinMode( 5, OUTPUT ); // Using this pin as the buzzer ground

digitalWrite( 5, LOW ); // Using this pin as the buzzer ground


}


 

void loop()

{


 

pulse_width = pulseIn ( 3, HIGH ); // Count how long the pulse is high in microseconds

 

if ( pulse_width != 0 ) { 


 

pulse_width = pulse_width / 10; // 10usec = 1 cm of distance for LIDAR-Lite


 

if ( pulse_width < 80 ) { digitalWrite( 9, HIGH ); // Signal the user w/ vibe motor


} else { digitalWrite( 9, LOW ); }


 

tone( 8, map( pulse_width, 0, 500, 1000, 0 ), 10 ); // Generate Proximity Tone

 


}

 

delay(20);


 

}



Sent from my iPad

Chris Albertson

unread,
Sep 4, 2021, 8:34:56 PM9/4/21
to hbrob...@googlegroups.com
The line below signals the user if the detection is less than 80 cm distant

if ( pulse_width < 80 ) { digitalWrite( 9, HIGH ); // Signal the user w/ vibe motor

But notice that the vibrator motor remains on until something else is detected that is farther away.

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hbrobotics/2788FA2B-7186-4654-9D54-9CE97807CAA2%40gmail.com.


--

Chris Albertson
Redondo Beach, California

Brain Higgins

unread,
Sep 4, 2021, 10:53:45 PM9/4/21
to hbrob...@googlegroups.com
The Lidar has a range of 130 ft. So it detects only at 80cm?

Sent from my iPhone 12 Pro Max

On Sep 4, 2021, at 5:34 PM, Chris Albertson <alberts...@gmail.com> wrote:



Chris Albertson

unread,
Sep 4, 2021, 11:45:39 PM9/4/21
to hbrob...@googlegroups.com
It does not matter what the range of the LIDAR might be, the software activates the vibrator motor only if it detects something closer than 80cm.Then it turns off the vibrtor only after detecting something farther than 80cm.

The software could be changed to do just about anything.  I am surprised you don't want better notification than just buzz or not.  and not be told the actual distance somehow.

Brian Higgins

unread,
Sep 5, 2021, 12:01:42 AM9/5/21
to hbrob...@googlegroups.com
There is a pizeo speaker and a vibrator motor.  The speaker appears to work around 10 feet. Not sure what code controls that.

Has any one developed an obstacle course for robots?


Sent from my iPhone 12 Pro Max

On Sep 4, 2021, at 8:45 PM, Chris Albertson <alberts...@gmail.com> wrote:



Chris Albertson

unread,
Sep 5, 2021, 12:23:19 AM9/5/21
to hbrob...@googlegroups.com
On Sat, Sep 4, 2021 at 9:01 PM Brian Higgins <blind...@gmail.com> wrote:
There is a pizeo speaker and a vibrator motor.  The speaker appears to work around 10 feet. Not sure what code controls that.

Has any one developed an obstacle course for robots?
 
Yes.  This demo represents the current state of the art of robots attempting an obstacle course.  The robot outperforms many humans
The above is far too advanced for us amateurs to even attempt.  But here is one done on the cheap with a $50 robot and well within amatuer DIY limits.
The above robot sees and plans routes around random obstacles that it has never seen before and does well at it.





 

Marco Walther

unread,
Sep 5, 2021, 2:08:10 AM9/5/21
to hbrob...@googlegroups.com, Brian Higgins
On 9/4/21 9:01 PM, Brian Higgins wrote:
> There is a pizeo speaker and a vibrator motor.  The speaker appears to
> work around 10 feet. Not sure what code controls that.

tone( 8, map( pulse_width, 0, 500, 1000, 0 ), 10 ); // Generate
Proximity Tone

I don't know, what your speaker has a minimum frequency, but it's
probably not 0 Hz;-)

-- Marco

>
> Has any one developed an obstacle course for robots?
>
> Sent from my iPhone 12 Pro Max
>
>> On Sep 4, 2021, at 8:45 PM, Chris Albertson
>> <alberts...@gmail.com> wrote:
>>
>> 
>> It does not matter what the range of the LIDAR might be, the software
>> activates the vibrator motor only if it detects something closer than
>> 80cm.Then it turns off the vibrtor only after detecting something
>> farther than 80cm.
>>
>> The software could be changed to do just about anything.  I am
>> surprised you don't want better notification than just buzz or not.
>>  and not be told the actual distance somehow.
>>
>> On Sat, Sep 4, 2021 at 7:53 PM Brain Higgins <see...@comcast.net
>> <mailto:see...@comcast.net>> wrote:
>>
>> The Lidar has a range of 130 ft. So it detects only at 80cm?
>>
>> Sent from my iPhone 12 Pro Max
>>
>>> On Sep 4, 2021, at 5:34 PM, Chris Albertson
>>> <mailto:hbrobotics+...@googlegroups.com>.
>>> <https://groups.google.com/d/msgid/hbrobotics/2788FA2B-7186-4654-9D54-9CE97807CAA2%40gmail.com?utm_medium=email&utm_source=footer>.
>>>
>>>
>>>
>>> --
>>>
>>> Chris Albertson
>>> Redondo Beach, California
>>>
>>> --
>>> You received this message because you are subscribed to the
>>> Google Groups "HomeBrew Robotics Club" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to hbrobotics+...@googlegroups.com
>>> <mailto:hbrobotics+...@googlegroups.com>.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/hbrobotics/CABbxVHu7J5fSh9cHcYGPN_sKaEvai7JyXumRTd%2BAVHXEDaEdgw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/hbrobotics/CABbxVHu7J5fSh9cHcYGPN_sKaEvai7JyXumRTd%2BAVHXEDaEdgw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "HomeBrew Robotics Club" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to hbrobotics+...@googlegroups.com
>> <mailto:hbrobotics+...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/hbrobotics/899AB44A-315C-44E6-9433-C6452DDBCC66%40comcast.net
>> <https://groups.google.com/d/msgid/hbrobotics/899AB44A-315C-44E6-9433-C6452DDBCC66%40comcast.net?utm_medium=email&utm_source=footer>.
>>
>>
>>
>> --
>>
>> Chris Albertson
>> Redondo Beach, California
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "HomeBrew Robotics Club" group.
>> To unsubscribe from this group and stop receiving emails from it, send
>> an email to hbrobotics+...@googlegroups.com
>> <mailto:hbrobotics+...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/hbrobotics/CABbxVHs6EbKg-q_CBytXNTp_Kh%3DVqskW_a5dxEPCuHs-k8VLHw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/hbrobotics/CABbxVHs6EbKg-q_CBytXNTp_Kh%3DVqskW_a5dxEPCuHs-k8VLHw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "HomeBrew Robotics Club" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to hbrobotics+...@googlegroups.com
> <mailto:hbrobotics+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/hbrobotics/CA7353BC-7D56-4C10-ADD8-04A40C6F2661%40gmail.com
> <https://groups.google.com/d/msgid/hbrobotics/CA7353BC-7D56-4C10-ADD8-04A40C6F2661%40gmail.com?utm_medium=email&utm_source=footer>.

Chris Albertson

unread,
Sep 5, 2021, 5:04:47 PM9/5/21
to hbrob...@googlegroups.com, Brian Higgins
10 feet is 304.8 centimeters.  The code rounds this down to 304.

The "map() function below would map 304 cm (10 feet) to 392 Hz.   
392 is  the "G" key near the center of a piano (that's G4)

Objects that are closer will have higher pitch sound,   The pizo speaker should be able to reproduce sound at least one octave lower than G4 (for an object 20 feet away) and it should handle higher pitches close to the limit of human hearing.



To unsubscribe from this group and stop receiving emails from it, send an email to hbrobotics+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hbrobotics/b6e7e659-cab8-21bd-a482-7344aef7be99%40gmail.com.

Sergei Grichine

unread,
Sep 6, 2021, 11:25:47 AM9/6/21
to hbrob...@googlegroups.com
A typical TTL-driven piezo speaker is really, really bad at reproducing a wide range of frequencies. There are somewhat better ones (https://www.analogictips.com/ultra-thin-piezo-speakers-handle-high-spl-large-frequency-range/) - but that's rare.

If you connect a piezo speaker (buzzer, to be exact) to a frequency generator, you will find that it sounds VERY loud at, say, 5230 Hz and fades very quickly within a 200 Hz margin, to almost nothing at frequencies below 1 kHz.

I'd guess, if you want to deliver some valuable information over an audio channel, you want that channel to be as close in bandwidth as your receiver (human ear, which come in pairs, BTW). In this case you can play with tone, harmonics, modulation, duration, stereo direction - delivering many aspects of your environment information by, let's say it - a generated "music". I'd guess people with visual impairments have exceptional ability to perceive such information and would naturally respond to audial clues.



--
Best Regards,
-- Sergei

Sergei Grichine

unread,
Sep 6, 2021, 11:39:41 AM9/6/21
to hbrob...@googlegroups.com
Here's a machine that could be used for audial alerting:


I never tried this, but it looks easy to program and mighty rich in features. And dirt cheap :-)

Here are some specs:

  • Features the VS1053B codec chip - decodes Ogg Vorbis, MP3/MP2/MP1, MP4, AAC, WMA, FLAC, WAV/PCM, MIDI.
  • Stereo audio out with proper audio filter caps and ground reference so it can be safely connected directly to headphones, a stereo system or other powered speakers
  • MicroSD card socket, for any FAT16/FAT32 formatted SD card from 64MB or greater
  • Built in MIDI synth/drum machine with dozens of instruments

Chris Albertson

unread,
Sep 6, 2021, 2:55:27 PM9/6/21
to hbrob...@googlegroups.com
I agree that it makes sense to use audio to send information to a user.  I'd use the highest quality stereo audio I could fit in the space and cost budget.  Stereo can give a sense of direction but also modulation can be used or even sampling.  A huge wall could sound different from small curb.

I ;oiled up the frequency response of several piezo speakers and they do seem to be able to reproduce a middle C pitch

But look at the code.  It is primitive at best.  The "tone()" function is called ever 20 milliseconds.  Does this reset the waveform?  Basically the state of the alarm signal ischanged 50 times per second.   This is much faster then a human reaction time.   Why is the signal updated at such ahigh rate.

A proper solution is that the sensors are used to update a "model" of the environment, even if that model is very primitive like "obstacle/no-obstacle" and then the output device communicates the model to the user.  and each is updated at a rate that is reasonable.

The problem is that the sensor data is very noisy but we know the actual real environment is not.  curbs and walls and trees do not pop up and move about but remain in place.  Even small running children typically keep a steady velocity in about the one second time frame.     Changing the state of the output 50 times per second is just going to tack noise






Brian Higgins

unread,
Sep 6, 2021, 2:55:56 PM9/6/21
to hbrob...@googlegroups.com
So I guess what I hearing, is no where in the code controls what distance the Lidar picked up an object


Sent from my iPhone 12 Pro Max

On Sep 6, 2021, at 8:39 AM, Sergei Grichine <vital...@gmail.com> wrote:



Chris Albertson

unread,
Sep 6, 2021, 3:56:49 PM9/6/21
to hbrob...@googlegroups.com
No.  What people are saying is this:
  1. the vibrator motor is turned on if an object is closer than 80 centimeters and
  2. a tone is played with pitch proportional to the distance.  But no one knows of the speaker is good enough to reproduce the tone
And finally, everything is recomputed 50 times a second and we don't know if a user can notice anything at all in 1/50th of a second.

The detections are likely being made, but the question is if the information is being communicated is the best way?   No one can know.

Brian Higgins

unread,
Sep 6, 2021, 4:35:48 PM9/6/21
to hbrob...@googlegroups.com
So does it makes sense to change the 50 times a second and where in the code can I change that


Sent from my iPhone 12 Pro Max

On Sep 6, 2021, at 12:56 PM, Chris Albertson <alberts...@gmail.com> wrote:



Chris Albertson

unread,
Sep 6, 2021, 5:19:31 PM9/6/21
to hbrob...@googlegroups.com
I don't know what is the best rate.  Perhaps the sensor needs to ping at the fastest rate it can and the user interface needs to update at the best rate for communication with a user.    I doubt the two rates are the same.   I'd run them on different time scales

As for what controls this.  Notice the 20 millisecond delay at the bottom.   20ms is is 20/1000 or 1/50 seconds.

Richard Chycoski

unread,
Sep 6, 2021, 5:31:34 PM9/6/21
to hbrob...@googlegroups.com
For reaction time, you want to be able to 'indicate' as quickly as possible to give the human time to react. The human reaction time is typically 200+ milliseconds after an indication. Being able to indicate in microseconds is not at all necessary, and 20 milliseconds is plenty short enough that it wouldn't significantly impact human response time, and even 50 milliseconds would likely not matter much either.

- Richard, VE7CVS

Chris Albertson

unread,
Sep 6, 2021, 6:11:32 PM9/6/21
to hbrob...@googlegroups.com
The problem is that the indication could go away after only 20 ms.  

Perhaps you run the sendor at 100 Hz, then if an object is seen three times in a row you turn on the warning.  Then aft the object is not seen five times you turn off the warning.   I just made-up those numbers but you get the idea -- some kind of sanity filter over the raw data

The goal is to only ward the user if the threat is real and to continue the warning until you are certain the threat is gone.

As I wrote before.  It is very unlikely that the sansor and the human interface need to act on the same time scales.  Take advantage of the fact that the sensor is very fast compared to human reaction times.   Why should the code EVERY ring and alarm for 20ms then turn it off?   That should be impossible.

Reply all
Reply to author
Forward
0 new messages