Practice English Speaking&Listening with: DIY Autonomous Vehicle with 2D LiDAR

Difficulty: 0

Hi, welcome, this is Clemens at Elektor.

In this video we will have a look at a two-dimensional lidar.

Recently I was chatting with my long-distance pal over at SparkFun, Rob Reynolds, about lidar.

Lidar is an incredible technology with an amazing history,

and we thought it was selfish of us to just talk among ourselves about it;

we thought we should share it with all of you.

So here it is.

Lidar is an acronym for light detection and ranging.

Lidar is like radar, except that it uses light instead of radio waves.

The light source is a laser.

A lidar sends out light pulses and measures the time it takes

for a reflection bouncing off a remote object to return to the device.

As the speed of light is a known constant, the distance to the object can be calculated

from the travel time of the light pulse.

Lidar can be one-dimensional, like laser distance meters.

It can also be two-dimensional, much like the radars used by ships and

traffic control towers on airports.

3D lidar exists too and is used for instance by planes to create

three-dimensional renderings of the surface of the earth below them.

In this video we will work with two-dimensional lidar.

New to Lidar?

Try working with one-dimensional first.

Check out the video by Rob Reynolds from SparkFun.

... and that's why I came up with the lidar stoplight.

So, who is SparkFun?

Well, since 2003, SparkFun has been helping turn ideas into reality

whether youre building a smart weather station or exploring the frontier of machine learning,

or maybe building a robot for school or prototyping your first or tenth product.

SparkFun is the place to get your components.

Together with SparkFun Elektor created the recent ElektorMag

which includes not just great projects but also some basics about electronics design

and also one project about LIDAR.

You can find the link in the description below.

Basically, a 2D lidar is nothing more than a rotating 1D lidar.

Instead of rotating both the laser and the detector,

it is often easier to shine the laser on a rotating mirror.

By sending out light pulses periodically 360 degrees can be covered

and a distance map with the lidar at the center can be created.

BTW, note that the reflectivity of an object is important.

An ideal black body cannot be seen by a lidar as it does not reflect any light at all.

For my experiments I used the X4 from Ydlidar.

It features a range of up to 10 meters and

an angular resolution of 0.5 degrees for distances up to 50 cm.

It has an infrared laser with a wavelength of 785 nm.

This device rotates the laser and detector, it does not use a rotating mirror.

The X4 lidar outputs distance data as a continuous serial stream at 128,000 baud.

It is also controlled over this serial link.

You can start and stop scanning by sending it simple commands.

You can also request some information about the device.

The motor is controlled separately with two extra wires, one for on/off and one for speed.

This means that this lidar can also work in one-dimensional mode.

I connected the serial port and the motor connections to an ESP32 Pico Kit.

To save power, I only used the lidar motor on its lowest speed,

which is about 400 rpm.

The lidar then consumes approximately 400 mA.

For programming the ESP32 Pico Kit I used the Arduino IDE.

After writing a function to parse the lidar data,

I had to check if my interpretation of the data was correct.

The X4 development manual is not very clear about how to do this and specifies two levels of detail.

The second level provides better angular resolution, but involves many inverse tangent calculations,

which are computationally intensive.

Therefore, I first tried nave interpretation.

I placed the lidar on a table inside a rectangular enclosed space and let it scan for a while.

After stopping it, I made it spit out the 360-degree scan on a serial port

as comma-separated CSV values

that I loaded into Excel.

With the radar chart function, I could display it.

The result looked a lot like my rectangle and the distances were correct too,

and so I didnt bother to try to improve the quality by adding inverse tangent calculations.

As a next step, I built a simple remote-controlled cart on which I mounted the lidar.

The cart has two motorized wheels in the middle and a stand-off on either end.

I glued ping-pong balls cut in half to the stand-offs to improve sliding behaviour.

Everything is mounted on a sheet of double-sided copper FR4 PCB material.

The wheels with motors, the motor driver board and the power supply,

a 3S 11.1 V Li-Po battery, are mounted on the bottom side.

The ESP32 module and the lidar are mounted on the top side.

The plate is grounded and shields the ESP32 module from the noisy motors.

The center of the lidar is in the center of the mounting plate.

The wheel axes too are in the center.

This simple car can spin around its center, which makes it very agile and manoeuvrable.

As a remote control, I used the free and open source Dabble library

which provides Bluetooth control for the ESP32 and Arduino

together with a smartphone app with multiple control surfaces.

One of the controls is a gamepad, which is perfect for my application.

It is really easy to use.

This let me control the cart with my phone.

My goal was to program the cart so that it would drive around all by itself

without bumping into objects like furniture and things.

A popular approach is to let the cart run around and back up or steer away

when it comes too close to an object, but this requires the cart to make decisions.

I wanted something simpler.

There are many examples of simple algorithms that result in complex behaviour,

for instance the way a flock of birds stays together,

and I wanted something like that.

My idea was to make the cart always move in the direction of the greatest distance

as reported by the lidar.

To avoid making it run in circles, it only looks forward, in the range of 270 to 90 degrees.

Implementing this rule was quite easy.

For every scan, a table is updated with the average distance for each degree.

Therefore, the table has 360 entries,

one per degree.

This table is then searched for the segment that has the highest average distance.

A segment has a width or aperture of 10 degrees, but this is an arbitrary value.

The middle degree of this segment is the direction the cart should take.

To achieve this, the cart will turn so that the middle degree,

the direction, moves to zero degrees.

We now have a classic control algorithm that tries to minimize an error.

To my great surprise, on its first run with this simple algorithm

the cart managed to move through our living room without bumping into obstacles.

It circled our couch and passed through narrow passages without difficulties.

The cart does not have any knowledge of its environment or itself, like its dimensions.

Also, I hadnt tried to optimize anything.

All parameters like forward and turning speed and search angle

were just set to values that I thought might be reasonable.

The Bluetooth remote control turned out to be very handy for confusing the cart

or to help it out difficult situations.

Also, it can be used to adjust parameters on the fly.

Now, as I am not into optimizing at all, I am more a proof-of-concept kind of person,

I stopped at this point.

If you want to have a play yourself, you can find the links to the code in the description below.

Summarizing, in this video I showed you how I managed to build a simple

autonomous vehicle that uses a low-cost lidar to avoid objects.

The control algorithm is simple, it always tries to steer the cart

in the direction of the object that is furthest away.

Even with arbitrary parameter values this worked straight out of the box.

There are many possibilities for improving this design,

and it is still far way from an autonomous vacuum cleaner or lawnmower,

but the obtained results are already very encouraging.

If you want to see part 1 of our coproduction with SparkFun check out the suggested video!

Okay, thats it.

I hope you found it interesting.

Please dont forget to subscribe to our channel and click or tap the bell button.

Thank you for watching.

The Description of DIY Autonomous Vehicle with 2D LiDAR