Previously on agayon.be, I mentioned a new small project: a SLAM device.
It was finished recently and this article presents its final form.
After many trials, the chosen design includes an optical rotary encoder disk with 360 teeth in order to provide a theoretical resolution of one degree. The Arduino code sends the data through serial connection in a compatible way with the xvlidar library. Therefore, the lidar module can be used with the BreezySLAM module of Simon D. Levy. Moreover, the data are being sent through XMPP to another computer where the map can be plotted.
The encoder wheel displays 360 markers in order to provide a theoretical resolution of one degree [ref]The disk was generated by using the following website: http://www.bushytails.net/~randyg/encoder/encoderwheel.html.[/ref]. The Arduino nano sends the data through serial connection. A Python script collects the data and
- sends it through XMPP to another device where it is analyzed.
- save it in a CSV file on the SD card for future use.
This script saves
- the distance,
- time between detections (called timer),
- the global and local counter which are the counter gathered in interrupt functions. They are triggered by the optical disk for each degree. In other words, local counter is equal to 360 after each rotation and global rotation is equal to the number of counts since the beginning of rotation.
The figure displays the timer as a function of the counter. As you can see, the timer drastically increases periodically. These values correspond to the 300 ms stops of the disk after a full rotation. The Arduino nano detects it and sends a "EOR" message (End of Rotation) by serial which is used by the python script.
As the device is thought to be portable, I wanted it to be run on a Raspberry Pi 2. The lidar is wireless and almost cordless. The data is sent by Wifi, the electronic cards (Pi and micro-controllers) are powered with the help of a 5000 mAh power bank and the only cord is the 5V alimentation of the motors.
Optical Rotary Encoder Disks
In a first attempt, the encoder disk was printed on transparent film. Unfortunately, accurate optical detection is not easy. Depending on the rotation speed or the number of steps and the printing quality, it was not trivial to obtain the 360 bits per tour. In order to obtain more accurate data, the disk was printed on a standard paper and the white stripes were cut out. The resulting disk was glued between two layers of transparent film. Over the course of a full rotation, 962 steps of the small stepper motor are needed to match the 360 teeth (remember the belt and the pulleys). Every tooth is detected when the distance measurement is deactivated. When the lidar is activated, the process is slower and about 180 values are detected over a full rotation. As a result, undetected angles must be filled with null values [ref]Because null values give unaesthetic maps, a distance of 1 mm is saved for undetected angles[/ref].
As the lidar is running, the map is drawn on another computer in a practical way with the help of another small script even if the Pi could save a PNG file on the SD card. This script can be used in two ways.
- The data is gathered from XMPP and the map is drawn in real time [ref]The variables for this settings are: file = True and xmpp_instance = False. An option parser will be added soon in order to make is more user-friendly[/ref]. Each data serie is saved in a csv file (one line per 360° scan).
- The data is read from the previously written CSV file [ref]The variables for this settings are: file = False and xmpp_instance = True.[/ref].
The data is managed in a compatible way with the xvlidar library. Therefore, my lidar module is compatible with the BreezySLAM library of Simon D. Levy.
Pictures and video
Here are two pictures of my living room.
The following video dislays the acquisition process in a entrance hall.
During the building of the device, several questions arised and the outcome was uncertain. The following list shows some answers. I let you find the questions. ;-)
- The slip ring works like a charm
- The motor rotation is quite constant. I do not regret using a stepper motor instead of a simple DC motor. A 360° rotation is performed by counting steps. The rotation is paused for several milliseconds. This pause triggers the emission of data through serial connection.
- The Arduino IDE is better and better on Linux. I had synchronization problems on Linux in the past when unplugging the micro-controller but everything is fine in the last versions.
- BreezySLAM is working with my data even if I had to use the Deterministic_SLAM function. RMHC_SLAM tried to dynamically find anew position of the lidar even if it stayed still.
- I can send the data from the lidar through XMPP and analyze them on another computer on a big screen. Speed is not a concern.
- I can easily reuse my LCD from Adafruit to print useful information about the process.
In the following months, I will try to mount the lidar on the agayon in order to map entire rooms and not only immediate environment of a single point.
- BreezySLAM and http://aerospacerobotics.com/blogs/learn/14881837-unraveling-breezyslam
- Gitlab repository
- Arduino code of Nano and Mega