handle_robot.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  STDR Simulator - Simple Two DImensional Robot Simulator
3  Copyright (C) 2013 STDR Simulator
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 3 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 
16  Authors :
17  * Manos Tsardoulias, etsardou@gmail.com
18  * Aris Thallas, aris.thallas@gmail.com
19  * Chris Zalidis, zalidis@gmail.com
20 ******************************************************************************/
21 
23 
24 namespace stdr_robot {
25 
31  : _spawnRobotClient("stdr_server/spawn_robot", true)
32  , _deleteRobotClient("stdr_server/delete_robot", true)
33  {
34  }
35 
41  stdr_msgs::RobotIndexedMsg HandleRobot::spawnNewRobot(
42  const stdr_msgs::RobotMsg msg)
43  {
44 
45  stdr_msgs::SpawnRobotGoal goal;
46  goal.description = msg;
47 
49  ROS_WARN("Could not find stdr_server/spawn_robot action.");
50  }
51 
53 
54  bool success = _spawnRobotClient.waitForResult(ros::Duration(10));
55  if (!success) {
56  throw ConnectionException("Could not spawn robot...");
57  }
58 
60  if(state.toString() == "ABORTED")
61  {
62  std::string msg = std::string("Could not spawn robot. ") +
63  _spawnRobotClient.getResult()->message;
64  throw DoubleFrameIdException(msg);
65  }
66 
67  ROS_INFO("New robot spawned successfully, with name %s.",
68  _spawnRobotClient.getResult()->indexedDescription.name.c_str());
69 
70  return _spawnRobotClient.getResult()->indexedDescription;
71 
72  }
73 
79  bool HandleRobot::deleteRobot(const std::string& name)
80  {
81 
82  stdr_msgs::DeleteRobotGoal goal;
83  goal.name = name;
84 
86  ROS_WARN("Could not find stdr_server/delete_robot action.");
87  }
88 
90 
92 
93  if (!success) {
94  throw ConnectionException("Could not delete robot, connection error...");
95  }
96 
97  return _deleteRobotClient.getResult()->success;
98 
99  }
100 
108  const std::string& name, const geometry_msgs::Pose2D newPose)
109  {
110 
111  while (!ros::service::waitForService(name + "/replace",
112  ros::Duration(.1)) && ros::ok()) {
113  ROS_WARN("Could not find %s/replace ...", name.c_str());
114  }
115 
116  stdr_msgs::MoveRobot srv;
117  srv.request.newPose = newPose;
118 
119  if (ros::service::call(name + "/replace", srv)) {
120  return true;
121  }
122 
123  return false;
124  }
125 
126 } // end of namespace stdr_robot
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
stdr_msgs::RobotIndexedMsg spawnNewRobot(const stdr_msgs::RobotMsg msg)
Spawns a new robot.
Provides a double frame id exception. Publicly inherits from std::runtime_error. Used in robot handle...
Definition: exceptions.h:50
bool waitForResult(const ros::Duration &timeout=ros::Duration(0, 0))
The main namespace for STDR Robot.
Definition: exceptions.h:27
bool call(const std::string &service_name, MReq &req, MRes &res)
#define ROS_WARN(...)
std::string toString() const
DeleteRobotClient _deleteRobotClient
Definition: handle_robot.h:57
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
SpawnRobotClient _spawnRobotClient
< Action client for spawning robots
Definition: handle_robot.h:55
bool deleteRobot(const std::string &name)
Deletes a robot by frame_id.
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
Provides a connection exception. Publicly inherits from std::runtime_error. Used in robot handler...
Definition: exceptions.h:33
SimpleClientGoalState getState() const
ResultConstPtr getResult() const
bool moveRobot(const std::string &name, const geometry_msgs::Pose2D newPose)
Re-places a robot by frame_id.
HandleRobot()
Default constructor.
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)


stdr_robot
Author(s): Manos Tsardoulias, Chris Zalidis, Aris Thallas
autogenerated on Mon Jun 10 2019 15:15:10