PlayerClient robot("localhost", 6665); Position2dProxy p2d(&robot, 0); PlayerCc::Motion* motion = robot.GetMotionMaster(); motion->GoTo(0.5, 0.5, 0);
PlayerClient robot("localhost", 6665); LaserProxy laser(&robot, 0); PlayerCc::Motion* motion = robot.GetMotionMaster(); while (true) { double left_reading = laser.GetRange(0); double right_reading = laser.GetRange(719); if (left_reading < 0.5 || right_reading < 0.5) { motion->Stop(); } else { motion->Go(0.2, 0); } }In this example, we again create a PlayerClient object and retrieve a pointer to the Motion Master object. We also create a LaserProxy object to interface with the robot's laser range finder. We then enter an infinite loop, continuously checking the readings from the leftmost and rightmost laser beams. If either of the beams detects an obstacle less than 0.5 meters away, the robot stops moving with Stop(). Otherwise, it moves forward at a speed of 0.2 meters per second with Go(). The Player library is available as a package in various Linux distributions and can also be downloaded from the official website.