Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdr_robot/handle_robot.h>
00023
00024 namespace stdr_robot {
00025
00030 HandleRobot::HandleRobot()
00031 : _spawnRobotClient("stdr_server/spawn_robot", true)
00032 , _deleteRobotClient("stdr_server/delete_robot", true)
00033 {
00034 }
00035
00041 stdr_msgs::RobotIndexedMsg HandleRobot::spawnNewRobot(
00042 const stdr_msgs::RobotMsg msg)
00043 {
00044
00045 stdr_msgs::SpawnRobotGoal goal;
00046 goal.description = msg;
00047
00048 while (!_spawnRobotClient.waitForServer(ros::Duration(1)) && ros::ok()) {
00049 ROS_WARN("Could not find stdr_server/spawn_robot action.");
00050 }
00051
00052 _spawnRobotClient.sendGoal(goal);
00053
00054 bool success = _spawnRobotClient.waitForResult(ros::Duration(10));
00055 if (!success) {
00056 throw ConnectionException("Could not spawn robot...");
00057 }
00058
00059 actionlib::SimpleClientGoalState state = _spawnRobotClient.getState();
00060 if(state.toString() == "ABORTED")
00061 {
00062 std::string msg = std::string("Could not spawn robot. ") +
00063 _spawnRobotClient.getResult()->message;
00064 throw DoubleFrameIdException(msg);
00065 }
00066
00067 ROS_INFO("New robot spawned successfully, with name %s.",
00068 _spawnRobotClient.getResult()->indexedDescription.name.c_str());
00069
00070 return _spawnRobotClient.getResult()->indexedDescription;
00071
00072 }
00073
00079 bool HandleRobot::deleteRobot(const std::string& name)
00080 {
00081
00082 stdr_msgs::DeleteRobotGoal goal;
00083 goal.name = name;
00084
00085 while (!_deleteRobotClient.waitForServer(ros::Duration(1)) && ros::ok()) {
00086 ROS_WARN("Could not find stdr_server/delete_robot action.");
00087 }
00088
00089 _deleteRobotClient.sendGoal(goal);
00090
00091 bool success = _deleteRobotClient.waitForResult(ros::Duration(10));
00092
00093 if (!success) {
00094 throw ConnectionException("Could not delete robot, connection error...");
00095 }
00096
00097 return _deleteRobotClient.getResult()->success;
00098
00099 }
00100
00107 bool HandleRobot::moveRobot(
00108 const std::string& name, const geometry_msgs::Pose2D newPose)
00109 {
00110
00111 while (!ros::service::waitForService(name + "/replace",
00112 ros::Duration(.1)) && ros::ok()) {
00113 ROS_WARN("Could not find %s/replace ...", name.c_str());
00114 }
00115
00116 stdr_msgs::MoveRobot srv;
00117 srv.request.newPose = newPose;
00118
00119 if (ros::service::call(name + "/replace", srv)) {
00120 return true;
00121 }
00122
00123 return false;
00124 }
00125
00126 }