Lidar
Dependencies: TS_DISCO_F746NG mbed BufferedSerial LCD_DISCO_F746NG mbed-rtos Trigo BSP_DISCO_F746NG
Main.cpp@5:734551a9f4e7, 2016-11-25 (annotated)
- Committer:
- Carminio
- Date:
- Fri Nov 25 10:04:16 2016 +0000
- Revision:
- 5:734551a9f4e7
- Parent:
- 4:0df95765b1b0
- Child:
- 6:b6efac82e5f9
Ver. 1.0 Finale OK
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Carminio | 0:88706d6abbf7 | 1 | #include "mbed.h" |
Carminio | 4:0df95765b1b0 | 2 | #include "rtos.h" |
Carminio | 0:88706d6abbf7 | 3 | #include "Serial.h" |
Carminio | 0:88706d6abbf7 | 4 | #include "BufferedSerial.h" |
Carminio | 0:88706d6abbf7 | 5 | #include "Communication.h" |
Carminio | 0:88706d6abbf7 | 6 | #include "Motor.h" |
Carminio | 0:88706d6abbf7 | 7 | #include <stdlib.h> |
Carminio | 0:88706d6abbf7 | 8 | #include <stdio.h> |
Carminio | 0:88706d6abbf7 | 9 | #include "LCD_DISCO_F746NG.h" |
Carminio | 1:1ff3fe3679c1 | 10 | #include "TS_DISCO_F746NG.h" |
Carminio | 0:88706d6abbf7 | 11 | |
Carminio | 3:43ab856b5efa | 12 | |
Carminio | 0:88706d6abbf7 | 13 | //Dichiarazione oggetti |
Carminio | 5:734551a9f4e7 | 14 | //DigitalIn myStopButton(USER_BUTTON); |
Carminio | 0:88706d6abbf7 | 15 | Motor lid_Motor(PWM_OUT); |
Carminio | 0:88706d6abbf7 | 16 | Communication SendCommands; |
Carminio | 1:1ff3fe3679c1 | 17 | LCD_DISCO_F746NG lcd; |
Carminio | 1:1ff3fe3679c1 | 18 | TS_DISCO_F746NG ts; |
Carminio | 5:734551a9f4e7 | 19 | LCD_DISCO_F746NG lcd_Thread; |
Carminio | 1:1ff3fe3679c1 | 20 | |
Carminio | 1:1ff3fe3679c1 | 21 | //Dichiarazione variabili |
Carminio | 5:734551a9f4e7 | 22 | TS_StateTypeDef TS_State; |
Carminio | 5:734551a9f4e7 | 23 | |
Carminio | 1:1ff3fe3679c1 | 24 | uint16_t x, y; |
Carminio | 1:1ff3fe3679c1 | 25 | uint8_t idx; |
Carminio | 2:8f71c97fe9d7 | 26 | uint8_t start=1; |
Carminio | 0:88706d6abbf7 | 27 | |
Carminio | 5:734551a9f4e7 | 28 | void StopLidar_thread(void const *args) { |
Carminio | 5:734551a9f4e7 | 29 | TS_DISCO_F746NG ts_Thread; |
Carminio | 5:734551a9f4e7 | 30 | wait(1); |
Carminio | 4:0df95765b1b0 | 31 | while(true) { |
Carminio | 5:734551a9f4e7 | 32 | ts_Thread.GetState(&TS_State); |
Carminio | 5:734551a9f4e7 | 33 | if (TS_State.touchDetected) { |
Carminio | 4:0df95765b1b0 | 34 | SendCommands.Stop(); |
Carminio | 4:0df95765b1b0 | 35 | wait_ms(10); |
Carminio | 4:0df95765b1b0 | 36 | lid_Motor.StopMotor_Scan(); |
Carminio | 4:0df95765b1b0 | 37 | wait_ms(10); |
Carminio | 4:0df95765b1b0 | 38 | SendCommands.Reset(); |
Carminio | 5:734551a9f4e7 | 39 | wait_ms(10); |
Carminio | 5:734551a9f4e7 | 40 | lcd_Thread.DisplayOff(); |
Carminio | 4:0df95765b1b0 | 41 | } |
Carminio | 4:0df95765b1b0 | 42 | } |
Carminio | 3:43ab856b5efa | 43 | } |
Carminio | 3:43ab856b5efa | 44 | |
Carminio | 3:43ab856b5efa | 45 | |
Carminio | 0:88706d6abbf7 | 46 | int main() { |
Carminio | 4:0df95765b1b0 | 47 | // Threads start here |
Carminio | 5:734551a9f4e7 | 48 | Thread StopLidar__th(StopLidar_thread); |
Carminio | 4:0df95765b1b0 | 49 | |
Carminio | 0:88706d6abbf7 | 50 | // Initialize Display |
Carminio | 0:88706d6abbf7 | 51 | lcd.Clear(LCD_COLOR_BLACK); |
Carminio | 0:88706d6abbf7 | 52 | lcd.SetBackColor(LCD_COLOR_BLACK); |
Carminio | 0:88706d6abbf7 | 53 | lcd.SetTextColor(LCD_COLOR_GREEN); |
Carminio | 0:88706d6abbf7 | 54 | wait(0.3); |
Carminio | 0:88706d6abbf7 | 55 | lcd.SetFont(&Font24); |
Carminio | 0:88706d6abbf7 | 56 | lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"SLAMTEC LIDAR A2", CENTER_MODE); |
Carminio | 2:8f71c97fe9d7 | 57 | lcd.SetFont(&Font8); |
Carminio | 2:8f71c97fe9d7 | 58 | lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"STMicroelectronics", RIGHT_MODE); |
Carminio | 2:8f71c97fe9d7 | 59 | lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"D. Ruggiero 2016", RIGHT_MODE); |
Carminio | 2:8f71c97fe9d7 | 60 | |
Carminio | 1:1ff3fe3679c1 | 61 | // Configure buttons and TFT display |
Carminio | 5:734551a9f4e7 | 62 | // TS_StateTypeDef TS_State; |
Carminio | 1:1ff3fe3679c1 | 63 | lcd.SetTextColor(LCD_COLOR_GREEN); |
Carminio | 2:8f71c97fe9d7 | 64 | lcd.FillRect(136, 200, 200, 50); ///Disegna bottone Verde |
Carminio | 2:8f71c97fe9d7 | 65 | |
Carminio | 2:8f71c97fe9d7 | 66 | lcd.SetFont(&Font24); |
Carminio | 1:1ff3fe3679c1 | 67 | lcd.SetBackColor(LCD_COLOR_GREEN); |
Carminio | 1:1ff3fe3679c1 | 68 | lcd.SetTextColor(LCD_COLOR_BLACK); |
Carminio | 2:8f71c97fe9d7 | 69 | lcd.DisplayStringAt(202, LINE(9), (uint8_t *)"SCAN", LEFT_MODE); |
Carminio | 2:8f71c97fe9d7 | 70 | |
Carminio | 2:8f71c97fe9d7 | 71 | while(start) { |
Carminio | 1:1ff3fe3679c1 | 72 | |
Carminio | 1:1ff3fe3679c1 | 73 | // Initialize TFT display |
Carminio | 1:1ff3fe3679c1 | 74 | ts.GetState(&TS_State); |
Carminio | 1:1ff3fe3679c1 | 75 | if (TS_State.touchDetected) { |
Carminio | 1:1ff3fe3679c1 | 76 | for (idx = 0; idx < TS_State.touchDetected; idx++) { |
Carminio | 1:1ff3fe3679c1 | 77 | x = TS_State.touchX[idx]; |
Carminio | 1:1ff3fe3679c1 | 78 | y = TS_State.touchY[idx]; |
Carminio | 1:1ff3fe3679c1 | 79 | } |
Carminio | 2:8f71c97fe9d7 | 80 | |
Carminio | 2:8f71c97fe9d7 | 81 | if((x>=136) && (x<=336) && (y>=200) && (y<=250)) { |
Carminio | 2:8f71c97fe9d7 | 82 | lcd.Clear(LCD_COLOR_BLACK); |
Carminio | 0:88706d6abbf7 | 83 | |
Carminio | 0:88706d6abbf7 | 84 | // Initialize UART |
Carminio | 0:88706d6abbf7 | 85 | SendCommands.confUART(); |
Carminio | 0:88706d6abbf7 | 86 | |
Carminio | 0:88706d6abbf7 | 87 | // Perform a device reset |
Carminio | 0:88706d6abbf7 | 88 | // SendCommands.Reset(); |
Carminio | 0:88706d6abbf7 | 89 | |
Carminio | 0:88706d6abbf7 | 90 | // Send Get_Health command |
Carminio | 0:88706d6abbf7 | 91 | // SendCommands.Get_Health(); |
Carminio | 0:88706d6abbf7 | 92 | |
Carminio | 0:88706d6abbf7 | 93 | // Send Get_Info command |
Carminio | 0:88706d6abbf7 | 94 | // SendCommands.Get_Info(); |
Carminio | 0:88706d6abbf7 | 95 | |
Carminio | 0:88706d6abbf7 | 96 | // Start motor (PWM: Frequency 25KHz, Duty cycle 60%) |
Carminio | 0:88706d6abbf7 | 97 | lid_Motor.StartMotor_Scan(); |
Carminio | 3:43ab856b5efa | 98 | |
Carminio | 0:88706d6abbf7 | 99 | // Start scan |
Carminio | 0:88706d6abbf7 | 100 | SendCommands.Scan(); |
Carminio | 2:8f71c97fe9d7 | 101 | start=0; |
Carminio | 2:8f71c97fe9d7 | 102 | } |
Carminio | 1:1ff3fe3679c1 | 103 | } |
Carminio | 0:88706d6abbf7 | 104 | } |
Carminio | 4:0df95765b1b0 | 105 | |
Carminio | 0:88706d6abbf7 | 106 | } |
Carminio | 3:43ab856b5efa | 107 | |
Carminio | 3:43ab856b5efa | 108 |