
Dr. Davis and Dr. Dyer special studies robotics project
Dependencies: BSP_DISCO_F469NI LCD_DISCO_F469NI TS_DISCO_F469NI mbed Motordriver
Fork of Configurable_Robots by
Revision 10:4dd8b18e07d0, committed 2017-05-09
- Comitter:
- blu12758
- Date:
- Tue May 09 18:48:47 2017 +0000
- Parent:
- 9:4ae116881502
- Child:
- 11:10a7bb4bc714
- Child:
- 13:a8a8a471d347
- Commit message:
- UI update
Changed in this revision
--- a/Classes/RobotMVC/RobotController.cpp Thu Feb 09 20:46:26 2017 +0000 +++ b/Classes/RobotMVC/RobotController.cpp Tue May 09 18:48:47 2017 +0000 @@ -2,7 +2,10 @@ //Spring 2017 //William Bonner +#ifndef R_CONTROLLER +#define R_CONTROLLER #include "RobotController.h" +#endif //Constructors/Destructors RobotController::~RobotController() @@ -20,8 +23,11 @@ //input: selection value void RobotController::userSelection(int s) { + //no input if(s < 0) return; + + model->setMode(0); switch(view->getPage()) { default: @@ -30,29 +36,39 @@ return; case 0: return; - case 1: + case 1://Main Menu switch(s) { case 0: view->setPage(2); + model->setMode(2); return; case 1: view->setPage(3); + model->setMode(3); return; case 2: view->setPage(4); + model->setMode(4); return; case 3: view->setPage(5); + model->setMode(5); return; case 4: view->setPage(6); - return; - case 5: - view->setPage(7); + model->setMode(6); return; } - + return; + case 2://Line Follower + case 3://Object Avoidance + case 4://Light Avoidance + case 5://TV Remote Control + case 6://Wiimote Control + if(s==0) + view->setPage(1); + return; } } @@ -67,4 +83,37 @@ void RobotController::listen() { userSelection(view->listen()); +} + +//Update robot state +void RobotController::update() +{ + int info = model->update(); + char buffer[50]; + switch(model->getMode()) + { + default: + case 0: + break; + case 2://Line Follower + sprintf (buffer, "%d", info); + view->writeString(buffer, 15); + break; + case 3://Object Avoidance + sprintf (buffer, "%d", info); + view->writeString(buffer, 15); + break; + case 4://Light Avoidance + sprintf (buffer, "%d", info); + view->writeString(buffer, 15); + break; + case 5://TV Remote Control + sprintf (buffer, "%d", info); + view->writeString(buffer, 15); + break; + case 6://Wiimote Control + sprintf (buffer, "%d", info); + view->writeString(buffer, 15); + break; + } } \ No newline at end of file
--- a/Classes/RobotMVC/RobotController.h Thu Feb 09 20:46:26 2017 +0000 +++ b/Classes/RobotMVC/RobotController.h Tue May 09 18:48:47 2017 +0000 @@ -31,4 +31,7 @@ //Listens for inputs void listen(); + + //Update robot state + void update(); }; \ No newline at end of file
--- a/Classes/RobotMVC/RobotModel.cpp Thu Feb 09 20:46:26 2017 +0000 +++ b/Classes/RobotMVC/RobotModel.cpp Tue May 09 18:48:47 2017 +0000 @@ -4,6 +4,16 @@ #include "RobotModel.h" +//Pin definitions +//Onboard LEDs +DigitalOut led_green(LED1); +DigitalOut led_orange(LED2); +DigitalOut led_red(LED3); +DigitalOut led_blue(LED4); + +//Input Pins +AnalogIn ain(A0); + //Constructors/Destructors RobotModel::~RobotModel() @@ -13,4 +23,28 @@ RobotModel::RobotModel() { _mode = 0; +} + +//initialize the robot's hardware +void RobotModel::init() +{ + led_green = 0; + led_orange = 0; + led_red = 0; + led_blue = 0; + wait_ms(200); + led_orange = 1; + led_red = 1; + led_blue = 1; +} + +//update the model based on the mode +int RobotModel::update() +{ + if(_mode == 0) + led_green = 0; + else + led_green = !led_green; + + return (int)(ain.read()*100); } \ No newline at end of file
--- a/Classes/RobotMVC/RobotModel.h Thu Feb 09 20:46:26 2017 +0000 +++ b/Classes/RobotMVC/RobotModel.h Tue May 09 18:48:47 2017 +0000 @@ -4,6 +4,7 @@ #include "mbed.h" + class RobotModel { //Current mode of operation @@ -20,4 +21,8 @@ int getMode() const {return _mode;} void setMode(int m){_mode = m;} + //initialize the robot's hardware + void init(); + //update the model based on the mode + int update(); }; \ No newline at end of file
--- a/Classes/RobotMVC/RobotView.cpp Thu Feb 09 20:46:26 2017 +0000 +++ b/Classes/RobotMVC/RobotView.cpp Tue May 09 18:48:47 2017 +0000 @@ -42,7 +42,7 @@ { //Clear Screen clear(); - + _infoline=0; //Write current page switch(_page) { @@ -55,11 +55,49 @@ _lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"University of Oklahoma", CENTER_MODE); _lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"Line Follower", CENTER_MODE); _lcd.DisplayStringAt(0, LINE(8), (uint8_t *)"Object Avoidance", CENTER_MODE); - _lcd.DisplayStringAt(0, LINE(11), (uint8_t *)"Object Seeking", CENTER_MODE); - _lcd.DisplayStringAt(0, LINE(14), (uint8_t *)"Light Avoidance", CENTER_MODE); - _lcd.DisplayStringAt(0, LINE(17), (uint8_t *)"TV Remote Control", CENTER_MODE); - _lcd.DisplayStringAt(0, LINE(20), (uint8_t *)"Wiimote Control", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(11), (uint8_t *)"Light Avoidance", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(14), (uint8_t *)"TV Remote Control", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(17), (uint8_t *)"Wiimote Control", CENTER_MODE); + break; + case 2://Line Follower + _lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"Configurable Robot", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"University of Oklahoma", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(11), (uint8_t *)"Line Following...", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(14), (uint8_t *)"UNDER CONSTRUCTION", CENTER_MODE); + _infoline=14; + break; + case 3://Object Avoidance + _lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"Configurable Robot", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"University of Oklahoma", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(11), (uint8_t *)"Object Avoidance", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(14), (uint8_t *)"UNDER CONSTRUCTION", CENTER_MODE); + _infoline=14; + break; + case 4://Light Avoidance + _lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"Configurable Robot", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"University of Oklahoma", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(11), (uint8_t *)"Light Avoidance", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(14), (uint8_t *)"UNDER CONSTRUCTION", CENTER_MODE); + _infoline=14; + break; + case 5://TV Remote Control + _lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"Configurable Robot", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"University of Oklahoma", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(11), (uint8_t *)"TV Remote Control", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(14), (uint8_t *)"UNDER CONSTRUCTION", CENTER_MODE); + _infoline=14; + break; + case 6://Wiimote Control + _lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"Configurable Robot", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(2), (uint8_t *)"University of Oklahoma", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(11), (uint8_t *)"Wiimote Control", CENTER_MODE); + _lcd.DisplayStringAt(0, LINE(14), (uint8_t *)"UNDER CONSTRUCTION", CENTER_MODE); + _infoline=14; + break; default: + char buffer[50]; + sprintf (buffer, "%d", _page); + _lcd.DisplayStringAt(0, LINE(14), (uint8_t *)buffer, CENTER_MODE); break; } @@ -88,6 +126,7 @@ { ts_x = TS_State.touchX[0]; ts_y = TS_State.touchY[0]; + wait_ms(200); return checkSelection(); } return -1; @@ -96,14 +135,14 @@ //Check which selection the user made based on the current page int RobotView::checkSelection() { - if(_page > 1 && ts_y <=(20)) - return 0; + if(_page > 1 && ts_y <=(18)) + return -1; switch(_page) { case 0: default: return -1; - case 1: + case 1://Main Menu if(ts_y <= LINE(6)) return 0; else if(ts_y <= LINE(9)) @@ -116,5 +155,24 @@ return 4; else return 5; + case 2://Line Following + case 3://Object Avoidance + case 4://Light Avoidance + case 5://TV Remote Control + case 6://Wiimote Control + if(ts_y >= LINE(18) && ts_x >= LINE(10)) + return 0; + } + return -1; +} + +//Display string given in parameters +void RobotView::writeString(char* c, int line) +{ + if(line >= 0) + _infoline = line; + _lcd.ClearStringLine(_infoline); + _lcd.DisplayStringAt(0, LINE(_infoline), (uint8_t *)c, CENTER_MODE); + _infoline++; } \ No newline at end of file
--- a/Classes/RobotMVC/RobotView.h Thu Feb 09 20:46:26 2017 +0000 +++ b/Classes/RobotMVC/RobotView.h Tue May 09 18:48:47 2017 +0000 @@ -10,6 +10,8 @@ { //The current page displayed by the robot interface int _page; + //The current line for info to be display on + int _infoline; //LCD Display Object LCD_DISCO_F469NI _lcd; @@ -25,7 +27,7 @@ RobotView(); //Accessors/Mutators - int getPage() const {return _page;} + int getPage(){return _page;} void setPage(int p) {_page = p; update();} //Initialize the screen to display the robot menu @@ -38,4 +40,6 @@ int listen(); //Check which selection the user made based on the current page int checkSelection(); + //Display string given in parameters + void writeString(char* c, int line); }; \ No newline at end of file
--- a/main.cpp Thu Feb 09 20:46:26 2017 +0000 +++ b/main.cpp Tue May 09 18:48:47 2017 +0000 @@ -8,16 +8,19 @@ { //Initialize variables RobotController* controller = new RobotController(); - + + //Initialize the robot hardware + controller->model->init(); //Initialize the robot screen controller->view->init(); controller->main(); - while(1) { //check for user selections and react accordingly controller->listen(); + controller->update(); + wait_ms(5); } } \ No newline at end of file