![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
ManualControl
Dependencies: TPixy-Interface
Fork of MbedOS_Robot_Team by
Diff: ui.cpp
- Revision:
- 9:fe56b888985c
- Parent:
- 8:a0890fa79084
- Child:
- 12:172c448a359e
--- a/ui.cpp Mon Feb 19 17:42:33 2018 +0000 +++ b/ui.cpp Fri Feb 23 20:58:34 2018 +0000 @@ -1,9 +1,9 @@ /******************************************************************************/ // ECE4333 -// LAB Partner 1: Ahmed Sobhy - ID: 3594449 -// LAB Partner 2: Brandon Kingman - ID: 3470444 -// Project: Autonomous Robot Design -// Instructor: Prof. Chris Diduch +// LAB Partner 1: Ahmed Sobhy - ID: 3594449 +// LAB Partner 2: Brandon Kingman - ID: 3470444 +// Project: Autonomous Robot Design +// Instructor: Prof. Chris Diduch /******************************************************************************/ // filename: ui.cpp // file content description: @@ -17,14 +17,17 @@ Serial bluetooth(p9,p10); // Define the bluetooth channel and IO pins Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel -Mutex setpoint_mutex; +Mutex setpointR_mutex; +Mutex setpointL_mutex; // speed -int setpoint = 0; -float total_time_passed = 0; +int setpointR = 0; +int setpointL = 0; + // variable to store character recieved from terminal char x; +/* extern int16_t dPosition, dTime; extern float Ki; extern float Kp; @@ -33,6 +36,7 @@ extern int32_t xState; extern int32_t u; extern int time_passed; +*/ int16_t position; @@ -65,8 +69,10 @@ bluetooth.printf("\r\n**** DC Motor Control using PWM ****"); bluetooth.printf("\r\n************************************"); bluetooth.printf("\r\n-Enter r to reset the watchdog timer"); - bluetooth.printf("\r\n-press w to increase motor speed"); - bluetooth.printf("\r\n-press s to decrease motor speed"); + bluetooth.printf("\r\n-press w to increase motor speedR"); + bluetooth.printf("\r\n-press s to decrease motor speedR"); + bluetooth.printf("\r\n-press i to increase motor speedL"); + bluetooth.printf("\r\n-press k to decrease motor speedL"); } @@ -142,57 +148,68 @@ if(x == 'r') { // reset watchdog timer WatchdogReset(); - setpoint = 0; + setpointR = 0; + setpointL = 0; bluetooth.printf("\r\nWatchdog has been reset"); } - + +/******************************RIGHT MOTOR*************************************/ // if w is pressed increase the speed // by incrementing u else if(x == 'w') { - setpoint_mutex.lock(); - if ( setpoint < 560 ) + setpointR_mutex.lock(); + if ( setpointR < 560 ) { //setpoint = setpoint + SPEED_STEP; - setpoint = 280; + setpointR = 280; } - setpoint_mutex.unlock(); - - // display speed - //bluetooth.printf("\r\n %5d", setpoint); + setpointR_mutex.unlock(); } // if s is pressed decrease the speed // by decrementing u else if(x == 's') { - setpoint_mutex.lock(); - if (setpoint > -560) + setpointR_mutex.lock(); + if (setpointR > -560) { - setpoint = -280; + setpointR = -280; //setpoint = setpoint - SPEED_STEP; } - setpoint_mutex.unlock(); + setpointR_mutex.unlock(); // display speed - bluetooth.printf("\r\n %5d", setpoint); + bluetooth.printf("\r\n %5d", setpointR); } + +/******************************LEFT MOTOR**************************************/ else if (x=='i') { - Ki = Ki + 0.01; + setpointL_mutex.lock(); + if ( setpointL < 560 ) + { + //setpoint = setpoint + SPEED_STEP; + setpointL = 280; + } + setpointL_mutex.unlock(); + } else if (x=='k') { - Ki = Ki - 0.01; + setpointL_mutex.lock(); + if (setpointL > -560) + { + setpointL = -280; + //setpoint = setpoint - SPEED_STEP; + } + + setpointL_mutex.unlock(); + + // display speed + bluetooth.printf("\r\n %5d", setpointL); } - else if (x=='o') - { - Kp = Kp + 0.1; - } - else if (x=='l') - { - Kp = Kp - 0.1; - } +/******************************END MOTOR SETPOINT******************************/ // error wrong input else { @@ -200,20 +217,18 @@ } } - position += dPosition; - //bluetooth.printf("\r\nPos: %d, dP: %d, dT: %d, Kp: %f, Ki: %f, vel: %d, e: %d", position, dPosition, dTime, Kp, Ki, vel, e); //bluetooth.printf("\r\ndP: %d, vel: %d, (Kp*e) Kp: %f, (Ki*xState) Ki: %f, e: %d, xState: %d, u: %d", dPosition, vel, Kp, Ki, e, xState , u); - + /* bluetooth.printf("\r\n %d, ", e); bluetooth.printf("%d, ", dPosition); bluetooth.printf("%d, ", xState); bluetooth.printf("%d, ", u); - + */ //bluetooth.printf("\r\ne: %d, Pos: %d, dP: %d, xState: %d, u: %d, dT: %d", e, position, dPosition, xState, u, dTime);