int main(int argc, char** argv) { std::cout << "Hello, world!" << std::endl; // setup signal interrupt handler signal(SIGINT, signal_callback_handler); // specify which options are available as cmd line arguments setupCmdLineReader(); // read agent id from command line parameters (--agent=mario) agent = readAgentFromCmdLine(argc, argv); // initialize the behavior tree client node ros::init(argc, argv, std::string("behavior_tree") + "_" + agent); // initialize OpenGL engine for visualization glut_setup(argc, argv); // point to the root of the behavior tree node_cursor = node = &root; node_cursor->set_highlighted(true); // create the bt from the file bt.txt (put on the path) std::cout << "----------------- PARSE FILE -----------------" << std::endl; parse_file(std::string("bt") + "_" + agent + ".txt"); // print the data parsed from the specification file std::cout << "----------------- PRINT TREE -----------------" << std::endl; root.print_subtree(); // wait until user inputs Enter to start std::cout << "Press Enter To Start" << std::endl; std::cin.get(); // start ticking the root of the tree at frequency: TICK_FREQUENCY while (ros::ok()) { std::cout << "**** run" << run << std::endl; std::cout << "-------------- EXECUTE TREE --------------" << std::endl; root.execute_reset_status(); root.execute(); // sending tick get_keypressed(); // processing keystrokes process_keypressed(); glut_process(); // update visualization glutPostRedisplay(); ros::Duration(1.0/TICK_FREQUENCY).sleep(); std::cout << "**** run" << run << std::endl; } // missing to clear the dynamically allocated tree // delete_tree(); return 0; }
void KeyboardInput::handle_input(Event & e) { if (e.type() == SDL_KEYDOWN && (e.get_key()->keysym.sym != SDLK_LSHIFT && e.get_key()->keysym.sym != SDLK_RSHIFT)) { keypressed = true; } if (e.type() == SDL_KEYUP && keypressed) { std::string temp = str; if (temp.length() <= 14) { char key = 0; keypressed = false; //std::cout << "this key was pressed: " << (char)e.get_event()->key.keysym.unicode << std::endl; // If the key is a space if ((char)e.get_key()->keysym.sym == ' ') { key = ' '; } // If the key is a number else if ( ( (char)e.get_key()->keysym.sym >= (int)'1' ) && ( (char)e.get_key()->keysym.sym <= (int)'9' ) ) { // Append the character //str += (char)e.get_key()->keysym.sym; key = (char)e.get_key()->keysym.sym; } //If the key is a lowercase letter else if( ( (char)e.get_key()->keysym.sym >= (int)'a' ) && ( (char)e.get_key()->keysym.sym <= (int)'z' ) ) { //Append the character key = (char)e.get_key()->keysym.sym; } KeyPressed k = get_keypressed(); if (k[SDLK_LSHIFT] || k[SDLK_RSHIFT]) { key = (char)((int)key - 32); } if (key != 0) str += key; } // If backspace was pressed and the string isn't blank if ( ( e.get_key()->keysym.sym == SDLK_BACKSPACE ) && ( str.length() != 0 ) ) { // Remove a character from the end str.erase( str.length() - 1 ); } // If the string was changed if ( str != temp ) { if (str.length() == 0) s.set_text(" "); else { // Render a new text surface s.set_text(str); } } } }