ManualControl

Dependencies:   TPixy-Interface

Fork of MbedOS_Robot by ECE4333 - 2018 - Ahmed & Brandon

Revision:
17:1184df616383
Parent:
15:cf67f83d5409
Child:
18:db6d9fc1ebd0
--- a/ui.cpp	Sun Mar 11 00:37:58 2018 +0000
+++ b/ui.cpp	Sun Mar 11 01:26:23 2018 +0000
@@ -14,6 +14,7 @@
 #include "WatchdogThread.h"
 #include "ui.h"
 #include "CameraThread.h"
+#include "PiControlThread.h"
 
 Serial bluetooth(p9,p10); // Define the bluetooth channel and IO pins
 Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel
@@ -25,12 +26,13 @@
 int setpointR = 0;
 int setpointL = 0;
 
+
 bool killRobot = false;
 
 // variable to store character recieved from terminal
 char x;
+int16_t position;
 
-int16_t position;
 
 /******************************************************************************
                            User interface 3
@@ -45,14 +47,16 @@
     // safety mechanism
     if (bluetooth.readable()){
         x = bluetooth.getc();
-        if (x == 'r')
+        if (x == 't')
         {
             killRobot = true;
         }
-        else if (x == 's')
+        else if (x == 'r')
         {
             killRobot = false;
         }
+        
+        
     }
     
 }
@@ -259,4 +263,65 @@
     
 }
 
+/******************************************************************************
+                           User interface 3 - manual control
+******************************************************************************/
 
+void consoleUIManualControl(void)
+{
+     
+    if (bluetooth.readable()) {
+        x = bluetooth.getc();
+        
+        // if input from console is the letter 'r'
+        if(x == 'r') {
+            // reset watchdog timer
+            WatchdogReset();
+            setpointR = 0;
+            setpointL = 0;
+            bluetooth.printf("\r\nWatchdog has been reset");
+        }
+        
+/******************************ROBOT FWD RVS***********************************/
+        // if w is pressed increase the speed
+        // by incrementing u
+        else if(x == 'w') {
+            mutexSetpoint.lock();
+            Setpoint = Setpoint + 100;
+            mutexSetpoint.unlock();
+        
+        }
+
+        // if s is pressed decrease the speed
+        // by decrementing u
+        else if(x == 's') {
+            mutexSetpoint.lock();
+            Setpoint = Setpoint - 100;
+            mutexSetpoint.unlock();
+        
+        }
+
+/******************************ROBOT STEERING**********************************/        
+        else if (x=='d')
+        {
+            mutexSetpoint.lock();
+            SteeringError = SteeringError + 10;
+            mutexSetpoint.unlock();
+        }
+        else if (x=='a')
+        {
+            mutexSetpoint.lock();
+            SteeringError = SteeringError - 10;
+            mutexSetpoint.unlock();
+        }        
+        // error wrong input
+        else {
+            bluetooth.printf("\r\nwrong input please enter \'w\' to increase the speed, \'s\' to reduce it or move in the opposite direction and \'r\' to reset the watchdog");
+        }
+    }
+    
+    // If no key is pressed stop the robot. 
+    Setpoint = 0;
+    SteeringError = 0;   
+    
+}