45 if (nh.
getParam(
"default_controllers", controller_params))
49 ROS_ERROR_NAMED(
"ControllerManager",
"Parameter 'default_controllers' should be a list.");
55 for (
int c = 0; c < controller_params.
size(); c++)
61 ROS_WARN_NAMED(
"ControllerManager",
"Controller name is not a string?");
66 load(static_cast<std::string>(controller_name));
91 if ((*c)->getController()->getName() ==
name)
101 ROS_ERROR_STREAM_NAMED(
"ControllerManager",
"Unable to start " << name.c_str() <<
": no such controller.");
106 if (controller->isActive())
113 std::vector<std::string> names = controller->getController()->getCommandedNames();
117 if (!(*c)->isActive())
120 std::vector<std::string> names2 = (*c)->getController()->getClaimedNames();
121 bool conflict =
false;
122 for (
size_t i = 0; i < names.size(); i++)
124 for (
size_t i2 = 0; i2 < names2.size(); i2++)
126 if (names[i] == names2[i2])
137 if ((*c)->stop(
false))
145 (*c)->getController()->getName().c_str() <<
146 " when trying to start " << name.c_str());
153 if (controller->start())
155 ROS_INFO_STREAM_NAMED(
"ControllerManager",
"Started " << controller->getController()->getName().c_str());
167 if ((*c)->getController()->getName() ==
name)
170 if ((*c)->stop(
true))
187 for (JointHandleList::iterator j =
joints_.begin(); j !=
joints_.end(); j++)
193 (*c)->update(time, dt);
216 for (JointHandleList::iterator j =
joints_.begin(); j !=
joints_.end(); j++)
218 if ((*j)->getName() ==
name)
225 if ((*c)->getController()->getName() ==
name)
226 return (*c)->getController();
236 for (JointHandleList::iterator j =
joints_.begin(); j !=
joints_.end(); j++)
238 if ((*j)->getName() ==
name)
248 robot_controllers_msgs::QueryControllerStatesFeedback feedback;
249 robot_controllers_msgs::QueryControllerStatesResult
result;
251 for (
size_t i = 0; i < goal->updates.size(); i++)
254 robot_controllers_msgs::ControllerState
state = goal->updates[i];
257 bool in_controller_list =
false;
260 if ((*c)->getController()->getName() == state.name)
262 if (state.type !=
"")
264 if (state.type == (*c)->getController()->getType())
266 in_controller_list =
true;
271 std::stringstream ss;
272 ss <<
"Controller " << state.name <<
" is of type " << (*c)->getController()->getType() <<
" not " << state.type;
274 server_->setAborted(result, ss.str());
278 in_controller_list =
true;
282 if (!in_controller_list)
289 if (!
load(static_cast<std::string>(state.name)))
291 std::stringstream ss;
292 ss <<
"Failed to load controller: " << state.name;
294 server_->setAborted(result, ss.str());
300 std::stringstream ss;
301 ss <<
"No such controller to update: " << state.name;
303 server_->setAborted(result, ss.str());
309 if (state.state == state.STOPPED)
313 std::stringstream ss;
314 ss <<
"Unable to stop " << state.name;
316 server_->setAborted(result, ss.str());
320 else if (state.state == state.RUNNING)
324 std::stringstream ss;
325 ss <<
"Unable to start " << state.name;
327 server_->setAborted(result, ss.str());
333 std::stringstream ss;
334 ss <<
"Invalid state for controller " << state.name <<
": " <<
static_cast<int>(state.state);
336 server_->setAborted(result, ss.str());
347 robot_controllers_msgs::QueryControllerStatesResult&
result)
349 result.state.clear();
352 robot_controllers_msgs::ControllerState
state;
353 state.name = (*c)->getController()->getName();
354 state.type = (*c)->getController()->getType();
355 if ((*c)->isActive())
357 state.state = state.RUNNING;
361 state.state = state.STOPPED;
363 result.state.push_back(state);
375 if (!controller->init(name,
this))
virtual void reset()
Reset all controllers.
#define ROS_DEBUG_STREAM_NAMED(name, args)
#define ROS_ERROR_STREAM_NAMED(name, args)
#define ROS_WARN_NAMED(name,...)
bool load(const std::string &name)
Load a controller.
virtual int init(ros::NodeHandle &nh)
Startup the controller manager, loading default controllers.
virtual int requestStart(const std::string &name)
Start a controller.
actionlib::SimpleActionServer< robot_controllers_msgs::QueryControllerStatesAction > server_t
#define ROS_INFO_STREAM_NAMED(name, args)
Type const & getType() const
HandlePtr getHandle(const std::string &name)
Get the handle associated with a particular joint/controller name.
bool addJointHandle(JointHandlePtr &j)
Add a joint handle.
virtual int requestStop(const std::string &name)
Stop a controller.
boost::shared_ptr< JointHandle > JointHandlePtr
void execute(const robot_controllers_msgs::QueryControllerStatesGoalConstPtr &goal)
Action callback.
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR_NAMED(name,...)
void getState(robot_controllers_msgs::QueryControllerStatesResult &result)
Fill in the current state of controllers.
boost::shared_ptr< server_t > server_
ControllerList controllers_
JointHandlePtr getJointHandle(const std::string &name)
Get the joint handle associated with a particular joint name.
Class for loading and managing a single controller.
bool hasParam(const std::string &key) const
virtual void update(const ros::Time &time, const ros::Duration &dt)
Update active controllers.
boost::shared_ptr< Handle > HandlePtr