ECE4333 - 2018 - Ahmed & Brandon / Mbed OS ObjectFollower

Dependencies:   TPixy-Interface

Fork of PlayBack by ECE4333 - 2018 - Ahmed & Brandon

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ui.cpp Source File

ui.cpp

00001 /******************************************************************************/
00002 // ECE4333
00003 // LAB Partner 1:   Ahmed Sobhy - ID: 3594449
00004 // LAB Partner 2:   Brandon Kingman - ID: 3470444
00005 // Project:         Autonomous Robot Design
00006 // Instructor:      Prof. Chris Diduch
00007 /******************************************************************************/
00008 // filename: ui.cpp
00009 // file content description:
00010 //      * Functions to display and manage the user interface on the PC terminal. 
00011 /******************************************************************************/
00012 
00013 #include "mbed.h"
00014 #include "WatchdogThread.h"
00015 #include "ui.h"
00016 #include "CameraThread.h"
00017 #include "PiControlThread.h"
00018 
00019 Serial bluetooth(p9,p10); // Define the bluetooth channel and IO pins
00020 Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel
00021 
00022 bool killRobot = false;
00023 
00024 // variable to store character recieved from terminal
00025 char x;
00026 
00027 
00028 void displayStartupMsg()
00029 {
00030     bluetooth.printf("\r\n************************************");
00031     bluetooth.printf("\r\n**** AUTONOMOUS FOLLOWING ROBOT ****");
00032     bluetooth.printf("\r\n************************************");
00033     bluetooth.printf("\r\n-PRESS 'r' TO KILL ROBOT");
00034 }
00035 
00036 /******************************************************************************
00037                            User interface 3 - Manual Control
00038 ******************************************************************************/
00039 
00040 void consoleUI(void)
00041 {
00042     if (bluetooth.readable()) {
00043         x = bluetooth.getc();
00044         
00045         // if input from console is the letter 'r'
00046         if(x == 'r') {
00047             // reset watchdog timer
00048             WatchdogReset();
00049             setpointR = 0;
00050             setpointL = 0;
00051             bluetooth.printf("\r\nWatchdog has been reset");
00052         }
00053         
00054 /******************************ROBOT FWD RVS***********************************/
00055         // if w is pressed increase the speed
00056         // by incrementing u
00057         else if(x == 'w') {
00058             mutexSetpoint.lock();
00059             Setpoint = -40;
00060             mutexSetpoint.unlock();
00061         
00062         }
00063 
00064         // if s is pressed decrease the speed
00065         // by decrementing u
00066         else if(x == 's') {
00067             mutexSetpoint.lock();
00068             Setpoint = 40;
00069             mutexSetpoint.unlock();
00070         
00071         }
00072 
00073 /******************************ROBOT STEERING**********************************/        
00074         else if (x=='a')
00075         {
00076             mutexSetpoint.lock();
00077             SteeringError = 80;
00078             mutexSetpoint.unlock();
00079         }
00080         else if (x=='d')
00081         {
00082             mutexSetpoint.lock();
00083             SteeringError = -80;
00084             mutexSetpoint.unlock();
00085         }        
00086         // error wrong input
00087         else {
00088             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");
00089         }
00090     }
00091     else{
00092         // If no key is pressed stop the robot. 
00093         Setpoint = 0;
00094         SteeringError = 0;
00095     }
00096     
00097 }