ManualControl
Dependencies: TPixy-Interface
Fork of MbedOS_Robot_Team by
Diff: ui.cpp
- Revision:
- 15:cf67f83d5409
- Parent:
- 14:5777377537a2
- Child:
- 17:1184df616383
- Child:
- 24:e88753f090b8
diff -r 5777377537a2 -r cf67f83d5409 ui.cpp --- a/ui.cpp Sat Mar 03 02:14:40 2018 +0000 +++ b/ui.cpp Sat Mar 03 04:47:26 2018 +0000 @@ -13,6 +13,7 @@ #include "mbed.h" #include "WatchdogThread.h" #include "ui.h" +#include "CameraThread.h" Serial bluetooth(p9,p10); // Define the bluetooth channel and IO pins Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel @@ -24,23 +25,11 @@ int setpointR = 0; int setpointL = 0; +bool killRobot = false; + // variable to store character recieved from terminal char x; -/* -extern int16_t dPosition, dTime; -extern float Ki; -extern float Kp; -extern int vel; -extern int32_t e; -extern int32_t xState; -extern int32_t u; -//extern int time_passed; -*/ - -extern int xR, yR, ObjectWidth, ObjectHeight, ObjectArea, SteeringError, DistanceError; -extern int xRAvg, yRAvg, ObjectWidthAvg, ObjectHeightAvg, ObjectAreaAvg; -extern Mutex cameraData_mutex; int16_t position; /****************************************************************************** @@ -48,8 +37,24 @@ ******************************************************************************/ void consoleUI(void){ - //bluetooth.printf("\r\nsetpointR: %d setpointL: %d ObjectWidth: %d ObjectXcoordinate: %d SteeringError: %d DistanceError: %d", setpointR, setpointL, ObjectWidth, xR, SteeringError, DistanceError); - bluetooth.printf("\r\nsetpointR: %d setpointL: %d ObjectWidth: %d ObjectXcoordinate: %d SteeringError: %d DistanceError: %d", setpointR, setpointL, ObjectWidth, xR, SteeringError, DistanceError); + cameraData_mutex.lock(); + bluetooth.printf("\r\nsetpointR: %d setpointL: %d ObjectWidth: %d ObjectXcoordinate: %d SteeringError: %d DistanceError: %d", setpointR, setpointL, ObjectWidth, xR, SteeringError, DistanceError); + cameraData_mutex.unlock(); + //bluetooth.printf("\r\nsetpointR: %d setpointL: %d ObjectWidth: %d ObjectXcoordinate: %d SteeringError: %d DistanceError: %d", setpointR, setpointL, ObjectWidth, xR, SteeringError, DistanceError); + + // safety mechanism + if (bluetooth.readable()){ + x = bluetooth.getc(); + if (x == 'r') + { + killRobot = true; + } + else if (x == 's') + { + killRobot = false; + } + } + } @@ -75,7 +80,7 @@ /****************************************************************************** A function to Display startup Messsage ******************************************************************************/ -void displayStartupMsg() +void displayStartupMsg_old() { bluetooth.printf("\r\n************************************"); bluetooth.printf("\r\n**** DC Motor Control using PWM ****"); @@ -87,6 +92,13 @@ bluetooth.printf("\r\n-press k to decrease motor speedL"); } +void displayStartupMsg() +{ + bluetooth.printf("\r\n************************************"); + bluetooth.printf("\r\n**** AUTONOMOUS FOLLOWING ROBOT ****"); + bluetooth.printf("\r\n************************************"); + bluetooth.printf("\r\n-PRESS 'r' TO KILL ROBOT"); +} /****************************************************************************** User interface 1