Lidar

Dependencies:   TS_DISCO_F746NG mbed BufferedSerial LCD_DISCO_F746NG mbed-rtos Trigo BSP_DISCO_F746NG

Committer:
Carminio
Date:
Mon Nov 28 15:36:07 2016 +0000
Revision:
7:d51b8b7f9960
Parent:
6:b6efac82e5f9
Come versione precedente ma con Duty Cicle = 80%

Who changed what in which revision?

UserRevisionLine numberNew 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 6:b6efac82e5f9 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 6:b6efac82e5f9 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 wait(1);
Carminio 4:0df95765b1b0 30 while(true) {
Carminio 6:b6efac82e5f9 31 if (myStopButton==1) {
Carminio 4:0df95765b1b0 32 SendCommands.Stop();
Carminio 4:0df95765b1b0 33 wait_ms(10);
Carminio 4:0df95765b1b0 34 lid_Motor.StopMotor_Scan();
Carminio 4:0df95765b1b0 35 wait_ms(10);
Carminio 4:0df95765b1b0 36 SendCommands.Reset();
Carminio 5:734551a9f4e7 37 wait_ms(10);
Carminio 5:734551a9f4e7 38 lcd_Thread.DisplayOff();
Carminio 4:0df95765b1b0 39 }
Carminio 4:0df95765b1b0 40 }
Carminio 3:43ab856b5efa 41 }
Carminio 3:43ab856b5efa 42
Carminio 3:43ab856b5efa 43
Carminio 0:88706d6abbf7 44 int main() {
Carminio 4:0df95765b1b0 45 // Threads start here
Carminio 5:734551a9f4e7 46 Thread StopLidar__th(StopLidar_thread);
Carminio 4:0df95765b1b0 47
Carminio 0:88706d6abbf7 48 // Initialize Display
Carminio 0:88706d6abbf7 49 lcd.Clear(LCD_COLOR_BLACK);
Carminio 0:88706d6abbf7 50 lcd.SetBackColor(LCD_COLOR_BLACK);
Carminio 0:88706d6abbf7 51 lcd.SetTextColor(LCD_COLOR_GREEN);
Carminio 0:88706d6abbf7 52 wait(0.3);
Carminio 0:88706d6abbf7 53 lcd.SetFont(&Font24);
Carminio 0:88706d6abbf7 54 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"SLAMTEC LIDAR A2", CENTER_MODE);
Carminio 2:8f71c97fe9d7 55 lcd.SetFont(&Font8);
Carminio 2:8f71c97fe9d7 56 lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"STMicroelectronics", RIGHT_MODE);
Carminio 2:8f71c97fe9d7 57 lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"D. Ruggiero 2016", RIGHT_MODE);
Carminio 2:8f71c97fe9d7 58
Carminio 1:1ff3fe3679c1 59 // Configure buttons and TFT display
Carminio 1:1ff3fe3679c1 60 lcd.SetTextColor(LCD_COLOR_GREEN);
Carminio 2:8f71c97fe9d7 61 lcd.FillRect(136, 200, 200, 50); ///Disegna bottone Verde
Carminio 2:8f71c97fe9d7 62
Carminio 2:8f71c97fe9d7 63 lcd.SetFont(&Font24);
Carminio 1:1ff3fe3679c1 64 lcd.SetBackColor(LCD_COLOR_GREEN);
Carminio 1:1ff3fe3679c1 65 lcd.SetTextColor(LCD_COLOR_BLACK);
Carminio 2:8f71c97fe9d7 66 lcd.DisplayStringAt(202, LINE(9), (uint8_t *)"SCAN", LEFT_MODE);
Carminio 2:8f71c97fe9d7 67
Carminio 2:8f71c97fe9d7 68 while(start) {
Carminio 1:1ff3fe3679c1 69
Carminio 1:1ff3fe3679c1 70 // Initialize TFT display
Carminio 1:1ff3fe3679c1 71 ts.GetState(&TS_State);
Carminio 1:1ff3fe3679c1 72 if (TS_State.touchDetected) {
Carminio 1:1ff3fe3679c1 73 for (idx = 0; idx < TS_State.touchDetected; idx++) {
Carminio 1:1ff3fe3679c1 74 x = TS_State.touchX[idx];
Carminio 1:1ff3fe3679c1 75 y = TS_State.touchY[idx];
Carminio 1:1ff3fe3679c1 76 }
Carminio 2:8f71c97fe9d7 77
Carminio 2:8f71c97fe9d7 78 if((x>=136) && (x<=336) && (y>=200) && (y<=250)) {
Carminio 2:8f71c97fe9d7 79 lcd.Clear(LCD_COLOR_BLACK);
Carminio 0:88706d6abbf7 80
Carminio 0:88706d6abbf7 81 // Initialize UART
Carminio 0:88706d6abbf7 82 SendCommands.confUART();
Carminio 0:88706d6abbf7 83
Carminio 0:88706d6abbf7 84 // Perform a device reset
Carminio 0:88706d6abbf7 85 // SendCommands.Reset();
Carminio 0:88706d6abbf7 86
Carminio 0:88706d6abbf7 87 // Send Get_Health command
Carminio 0:88706d6abbf7 88 // SendCommands.Get_Health();
Carminio 0:88706d6abbf7 89
Carminio 0:88706d6abbf7 90 // Send Get_Info command
Carminio 0:88706d6abbf7 91 // SendCommands.Get_Info();
Carminio 0:88706d6abbf7 92
Carminio 0:88706d6abbf7 93 // Start motor (PWM: Frequency 25KHz, Duty cycle 60%)
Carminio 0:88706d6abbf7 94 lid_Motor.StartMotor_Scan();
Carminio 3:43ab856b5efa 95
Carminio 0:88706d6abbf7 96 // Start scan
Carminio 0:88706d6abbf7 97 SendCommands.Scan();
Carminio 2:8f71c97fe9d7 98 start=0;
Carminio 2:8f71c97fe9d7 99 }
Carminio 1:1ff3fe3679c1 100 }
Carminio 0:88706d6abbf7 101 }
Carminio 4:0df95765b1b0 102
Carminio 0:88706d6abbf7 103 }
Carminio 3:43ab856b5efa 104
Carminio 3:43ab856b5efa 105