PlayBack

Dependencies:   TPixy-Interface

Fork of ObjectFollower by ECE4333 - 2018 - Ahmed & Brandon

Committer:
asobhy
Date:
Tue Apr 10 20:54:37 2018 +0000
Branch:
ManualControl
Revision:
29:83c103d12078
Parent:
22:c09acff62e6a
Child:
23:1839085ffdcf
Child:
28:00b21c648d31
ManualControl

Who changed what in which revision?

UserRevisionLine numberNew contents of line
asobhy 8:a0890fa79084 1 /******************************************************************************/
asobhy 8:a0890fa79084 2 // ECE4333
asobhy 9:fe56b888985c 3 // LAB Partner 1: Ahmed Sobhy - ID: 3594449
asobhy 9:fe56b888985c 4 // LAB Partner 2: Brandon Kingman - ID: 3470444
asobhy 9:fe56b888985c 5 // Project: Autonomous Robot Design
asobhy 9:fe56b888985c 6 // Instructor: Prof. Chris Diduch
asobhy 8:a0890fa79084 7 /******************************************************************************/
asobhy 8:a0890fa79084 8 // filename: ui.cpp
asobhy 8:a0890fa79084 9 // file content description:
asobhy 8:a0890fa79084 10 // * Functions to display and manage the user interface on the PC terminal.
asobhy 8:a0890fa79084 11 /******************************************************************************/
asobhy 8:a0890fa79084 12
asobhy 0:a355e511bc5d 13 #include "mbed.h"
asobhy 0:a355e511bc5d 14 #include "WatchdogThread.h"
asobhy 0:a355e511bc5d 15 #include "ui.h"
asobhy 15:cf67f83d5409 16 #include "CameraThread.h"
asobhy 17:1184df616383 17 #include "PiControlThread.h"
asobhy 0:a355e511bc5d 18
asobhy 0:a355e511bc5d 19 Serial bluetooth(p9,p10); // Define the bluetooth channel and IO pins
asobhy 0:a355e511bc5d 20 Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel
asobhy 0:a355e511bc5d 21
asobhy 15:cf67f83d5409 22 bool killRobot = false;
asobhy 15:cf67f83d5409 23
asobhy 0:a355e511bc5d 24 // variable to store character recieved from terminal
asobhy 0:a355e511bc5d 25 char x;
asobhy 0:a355e511bc5d 26
asobhy 1:3e9684e81312 27
asobhy 15:cf67f83d5409 28 void displayStartupMsg()
asobhy 15:cf67f83d5409 29 {
asobhy 15:cf67f83d5409 30 bluetooth.printf("\r\n************************************");
asobhy 15:cf67f83d5409 31 bluetooth.printf("\r\n**** AUTONOMOUS FOLLOWING ROBOT ****");
asobhy 15:cf67f83d5409 32 bluetooth.printf("\r\n************************************");
asobhy 15:cf67f83d5409 33 bluetooth.printf("\r\n-PRESS 'r' TO KILL ROBOT");
asobhy 15:cf67f83d5409 34 }
asobhy 0:a355e511bc5d 35
asobhy 0:a355e511bc5d 36 /******************************************************************************
asobhy 20:9118203f7c9c 37 User interface 3 - Manual Control
asobhy 17:1184df616383 38 ******************************************************************************/
asobhy 14:5777377537a2 39
asobhy 18:db6d9fc1ebd0 40 void consoleUI(void)
asobhy 17:1184df616383 41 {
asobhy 17:1184df616383 42 if (bluetooth.readable()) {
asobhy 17:1184df616383 43 x = bluetooth.getc();
asobhy 17:1184df616383 44
asobhy 17:1184df616383 45 // if input from console is the letter 'r'
asobhy 17:1184df616383 46 if(x == 'r') {
asobhy 17:1184df616383 47 // reset watchdog timer
asobhy 17:1184df616383 48 WatchdogReset();
asobhy 17:1184df616383 49 setpointR = 0;
asobhy 17:1184df616383 50 setpointL = 0;
asobhy 17:1184df616383 51 bluetooth.printf("\r\nWatchdog has been reset");
asobhy 17:1184df616383 52 }
asobhy 17:1184df616383 53
asobhy 17:1184df616383 54 /******************************ROBOT FWD RVS***********************************/
asobhy 17:1184df616383 55 // if w is pressed increase the speed
asobhy 17:1184df616383 56 // by incrementing u
asobhy 17:1184df616383 57 else if(x == 'w') {
asobhy 17:1184df616383 58 mutexSetpoint.lock();
asobhy 20:9118203f7c9c 59 Setpoint = -40;
asobhy 17:1184df616383 60 mutexSetpoint.unlock();
asobhy 17:1184df616383 61
asobhy 17:1184df616383 62 }
asobhy 17:1184df616383 63
asobhy 17:1184df616383 64 // if s is pressed decrease the speed
asobhy 17:1184df616383 65 // by decrementing u
asobhy 17:1184df616383 66 else if(x == 's') {
asobhy 17:1184df616383 67 mutexSetpoint.lock();
asobhy 20:9118203f7c9c 68 Setpoint = 40;
asobhy 17:1184df616383 69 mutexSetpoint.unlock();
asobhy 17:1184df616383 70
asobhy 17:1184df616383 71 }
asobhy 17:1184df616383 72
asobhy 17:1184df616383 73 /******************************ROBOT STEERING**********************************/
asobhy 18:db6d9fc1ebd0 74 else if (x=='a')
asobhy 18:db6d9fc1ebd0 75 {
asobhy 18:db6d9fc1ebd0 76 mutexSetpoint.lock();
asobhy 20:9118203f7c9c 77 SteeringError = 80;
asobhy 18:db6d9fc1ebd0 78 mutexSetpoint.unlock();
asobhy 18:db6d9fc1ebd0 79 }
asobhy 17:1184df616383 80 else if (x=='d')
asobhy 17:1184df616383 81 {
asobhy 17:1184df616383 82 mutexSetpoint.lock();
asobhy 20:9118203f7c9c 83 SteeringError = -80;
asobhy 17:1184df616383 84 mutexSetpoint.unlock();
asobhy 17:1184df616383 85 }
asobhy 17:1184df616383 86 // error wrong input
asobhy 17:1184df616383 87 else {
asobhy 17:1184df616383 88 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");
asobhy 17:1184df616383 89 }
asobhy 17:1184df616383 90 }
asobhy 18:db6d9fc1ebd0 91 else{
asobhy 18:db6d9fc1ebd0 92 // If no key is pressed stop the robot.
asobhy 18:db6d9fc1ebd0 93 Setpoint = 0;
asobhy 18:db6d9fc1ebd0 94 SteeringError = 0;
asobhy 18:db6d9fc1ebd0 95 }
asobhy 17:1184df616383 96
asobhy 17:1184df616383 97 }