void simple_example() { PlayerCc::PlayerClient robot("localhost"); PlayerCc::Position2dProxy positionProxy(&robot, 0); PlayerCc::SonarProxy sonarProxy(&robot, 0); for (;;) { // read from the proxies robot.Read(); // print out sonars for fun std::cout << sonarProxy << std::endl; // do simple collision avoidance double turnrate; if ((sonarProxy[0] + sonarProxy[1]) < (sonarProxy[6] + sonarProxy[7])) turnrate = PlayerCc::dtor(-20); // turn 20 degrees per second else turnrate = PlayerCc::dtor(20); double speed; if (sonarProxy[3] < 0.500) speed = 0; else speed = 0.100; // command the motors positionProxy.SetSpeed(speed, turnrate); } }
Robot::Robot() { PlayerCc::PlayerClient player(PlayerCc::PLAYER_HOSTNAME, PlayerCc::PLAYER_PORTNUM); //create ranger and motor classes PlayerCc::Position2dProxy positionProxy(&player, 0); PlayerCc::RangerProxy rangerProxy1(&player, 0); PlayerCc::RangerProxy rangerProxy2(&player, 1); //connect rangers/motor with player player.Read(); positionProxy.RequestGeom(); rangerProxy1.RequestConfigure(); rangerProxy1.RequestGeom(); rangerProxy2.RequestConfigure(); rangerProxy2.RequestGeom(); player.Read(); this->player = &player; motor = new Motor(positionProxy); ranger.push_back(new Ranger(rangerProxy1)); ranger.push_back(new Ranger(rangerProxy2)); local = new Local(positionProxy); controller = new Controller(*motor); power = false; Logger::setConsole(console); LOG_CTOR << "Constructed." << std::endl; }