This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:examples:sensor:lidar [2012/05/22 09:36] – raivo.sell | en:examples:sensor:lidar [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Lidar ====== | ====== Lidar ====== | ||
| - | <note important> | + | |
| //Necessary knowledge: [HW] [[en: | //Necessary knowledge: [HW] [[en: | ||
| + | ===== Theory ===== | ||
| - | [{{ | + | [{{ : |
| - | + | ||
| - | + | ||
| - | ===== Theory ===== | + | |
| LIDAR (Light Detection and Ranging) is an optical remote sensing system which can measure the distance of a target by illuminating it with light. LIDAR technology is being used in Robotics for the perception of the environment as well as object classification. The ability of LIDAR technology to provide 2D elevation maps of the terrain, high precision distance to the ground, and approach velocity can enable safe landing of robotic and manned vehicles with a high degree of precision. | LIDAR (Light Detection and Ranging) is an optical remote sensing system which can measure the distance of a target by illuminating it with light. LIDAR technology is being used in Robotics for the perception of the environment as well as object classification. The ability of LIDAR technology to provide 2D elevation maps of the terrain, high precision distance to the ground, and approach velocity can enable safe landing of robotic and manned vehicles with a high degree of precision. | ||
| Line 28: | Line 26: | ||
| c = f ∙ τ | c = f ∙ τ | ||
| - | where c is the speed of light and f the modulating frequency, and τ the known modulating wavelength. | + | where c is the speed of light and f the modulating frequency and τ the known modulating wavelength. |
| The total distance D' covered by the emitted light is: | The total distance D' covered by the emitted light is: | ||
| Line 44: | Line 42: | ||
| ===== Practice ===== | ===== Practice ===== | ||
| - | |||
| [{{ : | [{{ : | ||
| - | [{{ : | ||
| - | In autonomous robotics as well as industrial robotics SICK laser rangers are very widely used. The SICK LMS 200 can easily be interfaced through RS-232 or RS-422, providing distance measurements over a 180 degree area up to 80 meters away. This lidar is based on a time-of-flight measurement principle. | ||
| - | To make the SICK operational, | + | In autonomous robotics as well as industrial robotics SICK laser rangers are very widely used. The SICK LMS 200 can easily be interfaced through RS-232 or RS-422, providing distance measurements over a 180 degree area up to 80 meters away. This lidar is based on a time-of-flight measurement principle. The example output of one scan measurement result is shown in the picture on the right. |
| + | |||
| + | [{{ : | ||
| + | |||
| + | To make the SICK operational, | ||
| The SICK receives commands as streams of bytes through the serial port. When transmitting data, it sends back streams of bytes corresponding to distance measurements at a given angle. | The SICK receives commands as streams of bytes through the serial port. When transmitting data, it sends back streams of bytes corresponding to distance measurements at a given angle. | ||
| Line 60: | Line 59: | ||
| Decimal Form: | Decimal Form: | ||
| - | After the start string | + | If the start string |
| - | Finally, to stop the sensor from sending data, a stop string must be sent. This string is: | + | Finally to stop the sensor from sending data a stop string must be sent. This string is: |
| Hexadecimal Form: | Hexadecimal Form: | ||
| Line 68: | Line 67: | ||
| Decimal Form: | Decimal Form: | ||
| - | Following example shows how to initiate Lidar and measure | + | Following example shows how to initiate Lidar and get the count of package. |
| <code c> | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| - | </code> | + | // Defining USART interface. |
| + | usart port = USART(0); | ||
| + | // Defining button pins. | ||
| + | pin button1 = PIN(C, 0); | ||
| + | pin button2 = PIN(C, 1); | ||
| + | |||
| + | // Initialize | ||
| + | static inline void init() | ||
| + | { | ||
| + | // Setting buttons pins as inputs. | ||
| + | pin_setup_input_with_pullup(button1); | ||
| + | pin_setup_input_with_pullup(button2); | ||
| + | |||
| + | // Set-up of the LCD. | ||
| + | lcd_gfx_init(); | ||
| + | // Cleaning the screen. | ||
| + | lcd_gfx_clear(); | ||
| + | // Switching on the background light. | ||
| + | lcd_gfx_backlight(true); | ||
| + | // Displaying the name of the program. | ||
| + | lcd_gfx_goto_char_xy(3, | ||
| + | lcd_gfx_write_string(" | ||
| + | |||
| + | // The set-up of the USART interface. | ||
| + | usart_init_async | ||
| + | ( | ||
| + | port, | ||
| + | USART_DATABITS_8, | ||
| + | USART_STOPBITS_ONE, | ||
| + | USART_PARITY_NONE, | ||
| + | USART_BAUDRATE_ASYNC(9600) | ||
| + | ); | ||
| + | } | ||
| + | |||
| + | // Main program | ||
| + | int main(void) | ||
| + | { | ||
| + | unsigned char new_value1, new_value2, old_value1 = 0, old_value2 = 0; | ||
| + | |||
| + | char c; | ||
| + | int i = 0; | ||
| + | int count = 0; | ||
| + | char text[16]; | ||
| + | |||
| + | // Initialize | ||
| + | init(); | ||
| + | |||
| + | // Endless cycle | ||
| + | while (1) | ||
| + | { | ||
| + | // Reads buttons states | ||
| + | new_value1 = pin_get_debounced_value(button1); | ||
| + | new_value2 = pin_get_debounced_value(button2); | ||
| + | |||
| + | // Button S1 is pressed. | ||
| + | if((!new_value1) && (old_value1)) | ||
| + | { | ||
| + | //Send "02 00 02 00 20 24 34 08" to start scanning. | ||
| + | |||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | } | ||
| + | |||
| + | // Button S2 is pressed. | ||
| + | if((!new_value2) && (old_value2)) | ||
| + | { | ||
| + | //Send "0x 02 00 02 00 20 25 35 08" to stop scanning. | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | usart_send_char(port, | ||
| + | } | ||
| + | |||
| + | // Remembers the last keys values. | ||
| + | old_value1 = new_value1; | ||
| + | old_value2 = new_value2; | ||
| + | |||
| + | // Try to read serial port | ||
| + | if (usart_try_read_char(port, | ||
| + | { | ||
| + | // Find a header "0x 02 81 D6 02 B0 69 41" | ||
| + | // Very basic package start search. | ||
| + | if(c == 0x02) i++; | ||
| + | if(c == 0x81) i++; | ||
| + | if(c == 0xD6) i++; | ||
| + | if(c == 0x02) i++; | ||
| + | if(c == 0xB0) i++; | ||
| + | if(c == 0x69) i++; | ||
| + | if(c == 0x41) i++; | ||
| + | |||
| + | //If there is an header | ||
| + | if(i >= 7) | ||
| + | { | ||
| + | // | ||
| + | count++; | ||
| + | |||
| + | // | ||
| + | lcd_gfx_goto_char_xy(0, | ||
| + | |||
| + | sprintf(text, | ||
| + | |||
| + | lcd_gfx_write_string(text); | ||
| + | |||
| + | i=0; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </ | ||