ObjectFollower
Dependencies: TPixy-Interface
Fork of PlayBack by
ui.cpp@23:1839085ffdcf, 2018-03-29 (annotated)
- Committer:
- asobhy
- Date:
- Thu Mar 29 22:33:52 2018 +0000
- Revision:
- 23:1839085ffdcf
- Parent:
- 22:c09acff62e6a
PLAYBACK SUBSYSTEM WORKING!!!
Who changed what in which revision?
User | Revision | Line number | New 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 | 23:1839085ffdcf | 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 | 23:1839085ffdcf | 19 | bool startRecording = false; |
asobhy | 23:1839085ffdcf | 20 | bool MC = true; |
asobhy | 23:1839085ffdcf | 21 | |
asobhy | 0:a355e511bc5d | 22 | Serial bluetooth(p9,p10); // Define the bluetooth channel and IO pins |
asobhy | 0:a355e511bc5d | 23 | Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel |
asobhy | 0:a355e511bc5d | 24 | |
asobhy | 15:cf67f83d5409 | 25 | bool killRobot = false; |
asobhy | 15:cf67f83d5409 | 26 | |
asobhy | 0:a355e511bc5d | 27 | // variable to store character recieved from terminal |
asobhy | 0:a355e511bc5d | 28 | char x; |
asobhy | 0:a355e511bc5d | 29 | |
asobhy | 1:3e9684e81312 | 30 | |
asobhy | 15:cf67f83d5409 | 31 | void displayStartupMsg() |
asobhy | 15:cf67f83d5409 | 32 | { |
asobhy | 15:cf67f83d5409 | 33 | bluetooth.printf("\r\n************************************"); |
asobhy | 15:cf67f83d5409 | 34 | bluetooth.printf("\r\n**** AUTONOMOUS FOLLOWING ROBOT ****"); |
asobhy | 15:cf67f83d5409 | 35 | bluetooth.printf("\r\n************************************"); |
asobhy | 23:1839085ffdcf | 36 | bluetooth.printf("\r\n-PRESS 'r' TO reset"); |
asobhy | 15:cf67f83d5409 | 37 | } |
asobhy | 0:a355e511bc5d | 38 | |
asobhy | 0:a355e511bc5d | 39 | /****************************************************************************** |
asobhy | 20:9118203f7c9c | 40 | User interface 3 - Manual Control |
asobhy | 17:1184df616383 | 41 | ******************************************************************************/ |
asobhy | 14:5777377537a2 | 42 | |
asobhy | 18:db6d9fc1ebd0 | 43 | void consoleUI(void) |
asobhy | 17:1184df616383 | 44 | { |
asobhy | 17:1184df616383 | 45 | if (bluetooth.readable()) { |
asobhy | 17:1184df616383 | 46 | x = bluetooth.getc(); |
asobhy | 23:1839085ffdcf | 47 | |
asobhy | 23:1839085ffdcf | 48 | // enter manual control and exit patrol mode |
asobhy | 23:1839085ffdcf | 49 | if(x == 'm') { |
asobhy | 23:1839085ffdcf | 50 | MC = true; |
asobhy | 23:1839085ffdcf | 51 | } |
asobhy | 23:1839085ffdcf | 52 | |
asobhy | 23:1839085ffdcf | 53 | // exit manual control and enter patrol mode |
asobhy | 23:1839085ffdcf | 54 | if(x == 'p') { |
asobhy | 23:1839085ffdcf | 55 | MC = false; |
asobhy | 23:1839085ffdcf | 56 | startRecording = false; |
asobhy | 23:1839085ffdcf | 57 | } |
asobhy | 17:1184df616383 | 58 | |
asobhy | 23:1839085ffdcf | 59 | if(x == 'l'){ |
asobhy | 23:1839085ffdcf | 60 | startRecording = true; |
asobhy | 23:1839085ffdcf | 61 | } |
asobhy | 23:1839085ffdcf | 62 | |
asobhy | 17:1184df616383 | 63 | // if input from console is the letter 'r' |
asobhy | 23:1839085ffdcf | 64 | if(x == 'r' && (MC)) { |
asobhy | 23:1839085ffdcf | 65 | |
asobhy | 17:1184df616383 | 66 | // reset watchdog timer |
asobhy | 17:1184df616383 | 67 | WatchdogReset(); |
asobhy | 17:1184df616383 | 68 | setpointR = 0; |
asobhy | 17:1184df616383 | 69 | setpointL = 0; |
asobhy | 23:1839085ffdcf | 70 | MC = true; |
asobhy | 23:1839085ffdcf | 71 | startRecording = false; |
asobhy | 23:1839085ffdcf | 72 | memoryFull = false; |
asobhy | 23:1839085ffdcf | 73 | dpArray.i = 0; |
asobhy | 23:1839085ffdcf | 74 | |
asobhy | 23:1839085ffdcf | 75 | // reset array |
asobhy | 23:1839085ffdcf | 76 | for(int i = 0; i < dpArray.size; i++){ |
asobhy | 23:1839085ffdcf | 77 | dpArray.dpR[i] = 0; |
asobhy | 23:1839085ffdcf | 78 | dpArray.dpL[i] = 0; |
asobhy | 23:1839085ffdcf | 79 | } |
asobhy | 23:1839085ffdcf | 80 | |
asobhy | 23:1839085ffdcf | 81 | bluetooth.printf("\r\nSystem has been Reset"); |
asobhy | 23:1839085ffdcf | 82 | |
asobhy | 17:1184df616383 | 83 | } |
asobhy | 23:1839085ffdcf | 84 | |
asobhy | 23:1839085ffdcf | 85 | /******************************ROBOT FWD RVS***********************************/ |
asobhy | 17:1184df616383 | 86 | // if w is pressed increase the speed |
asobhy | 17:1184df616383 | 87 | // by incrementing u |
asobhy | 23:1839085ffdcf | 88 | else if(x == 'w'&& (MC)) { |
asobhy | 17:1184df616383 | 89 | mutexSetpoint.lock(); |
asobhy | 20:9118203f7c9c | 90 | Setpoint = -40; |
asobhy | 17:1184df616383 | 91 | mutexSetpoint.unlock(); |
asobhy | 23:1839085ffdcf | 92 | |
asobhy | 17:1184df616383 | 93 | } |
asobhy | 17:1184df616383 | 94 | |
asobhy | 17:1184df616383 | 95 | // if s is pressed decrease the speed |
asobhy | 17:1184df616383 | 96 | // by decrementing u |
asobhy | 23:1839085ffdcf | 97 | else if(x == 's' && (MC)) { |
asobhy | 17:1184df616383 | 98 | mutexSetpoint.lock(); |
asobhy | 20:9118203f7c9c | 99 | Setpoint = 40; |
asobhy | 17:1184df616383 | 100 | mutexSetpoint.unlock(); |
asobhy | 23:1839085ffdcf | 101 | |
asobhy | 17:1184df616383 | 102 | } |
asobhy | 17:1184df616383 | 103 | |
asobhy | 23:1839085ffdcf | 104 | /******************************ROBOT STEERING**********************************/ |
asobhy | 23:1839085ffdcf | 105 | else if (x=='a'&& (MC)) { |
asobhy | 18:db6d9fc1ebd0 | 106 | mutexSetpoint.lock(); |
asobhy | 20:9118203f7c9c | 107 | SteeringError = 80; |
asobhy | 18:db6d9fc1ebd0 | 108 | mutexSetpoint.unlock(); |
asobhy | 23:1839085ffdcf | 109 | } else if (x=='d'&& (MC)) { |
asobhy | 17:1184df616383 | 110 | mutexSetpoint.lock(); |
asobhy | 20:9118203f7c9c | 111 | SteeringError = -80; |
asobhy | 17:1184df616383 | 112 | mutexSetpoint.unlock(); |
asobhy | 23:1839085ffdcf | 113 | } |
asobhy | 17:1184df616383 | 114 | // error wrong input |
asobhy | 17:1184df616383 | 115 | else { |
asobhy | 23:1839085ffdcf | 116 | //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 | 117 | } |
asobhy | 23:1839085ffdcf | 118 | } else { |
asobhy | 23:1839085ffdcf | 119 | // If no key is pressed stop the robot. |
asobhy | 18:db6d9fc1ebd0 | 120 | Setpoint = 0; |
asobhy | 18:db6d9fc1ebd0 | 121 | SteeringError = 0; |
asobhy | 18:db6d9fc1ebd0 | 122 | } |
asobhy | 17:1184df616383 | 123 | |
asobhy | 23:1839085ffdcf | 124 | if(memoryFull){ |
asobhy | 23:1839085ffdcf | 125 | bluetooth.printf("\r\nmemory is full"); |
asobhy | 23:1839085ffdcf | 126 | } |
asobhy | 23:1839085ffdcf | 127 | |
asobhy | 17:1184df616383 | 128 | } |