Go to the documentation of this file.00001 #include <moveit_controller_multidof/MultiDOFControllerManager.h>
00002 #include <moveit_controller_multidof/ForwardingControllerHandle.h>
00003
00004
00005
00006
00007
00008
00009 #include <pluginlib/class_list_macros.h>
00010
00011 PLUGINLIB_EXPORT_CLASS(moveit_controller_multidof::MultiDOFControllerManager,
00012 moveit_controller_manager::MoveItControllerManager);
00013
00014 using moveit_controller_multidof::MultiDOFControllerManager;
00015
00016 MultiDOFControllerManager::MultiDOFControllerManager() : node_handle_("~")
00017 {
00018
00019
00020 std::string virtual_joint_name;
00021 std::string path_action_topic;
00022 std::string trajectory_action_topic;
00023 if (!node_handle_.hasParam("virtual_joint_name"))
00024 {
00025 ROS_INFO_STREAM_NAMED("manager","No virtual_joint_name specified, so only joint trajectories will be supported.");
00026 } else {
00027 node_handle_.getParam("virtual_joint_name",virtual_joint_name);
00028 if (virtual_joint_name.empty())
00029 {
00030 ROS_INFO_STREAM_NAMED("manager","Empty virtual_joint_name specified, so only joint trajectories will be supported.");
00031 }
00032 }
00033 if (!virtual_joint_name.empty())
00034 {
00035 if (!node_handle_.hasParam("path_navigation_action_topic"))
00036 {
00037 ROS_ERROR_STREAM_NAMED("manager","No path_navigation_action_topic specified, so only joint trajectories will be supported.");
00038 virtual_joint_name="";
00039 }
00040 else
00041 {
00042 node_handle_.getParam("path_navigation_action_topic",path_action_topic);
00043 ROS_INFO("Got path navigation action topic name: <%s>", path_action_topic.c_str());
00044 if (path_action_topic.empty())
00045 {
00046 ROS_ERROR_STREAM_NAMED("manager","Empty path_navigation_action_topic specified, so only joint trajectories will be supported.");
00047 virtual_joint_name="";
00048 }
00049 }
00050 }
00051 if (!node_handle_.hasParam("joint_trajectory_action_topic"))
00052 {
00053 ROS_WARN_STREAM_NAMED("manager","No joint_trajectory_action_topic parameter specified.");
00054 }
00055 node_handle_.getParam("joint_trajectory_action_topic",trajectory_action_topic);
00056 ROS_INFO("Got joint trajectory action topic name: <%s>", trajectory_action_topic.c_str());
00057
00058
00059
00060
00061
00062
00063
00064 if (!node_handle_.hasParam("controller_list"))
00065 {
00066 ROS_ERROR_STREAM_NAMED("manager","No controller_list specified.");
00067 return;
00068 }
00069
00070 XmlRpc::XmlRpcValue controller_list;
00071 node_handle_.getParam("controller_list", controller_list);
00072 if (controller_list.getType() != XmlRpc::XmlRpcValue::TypeArray)
00073 {
00074 ROS_ERROR("Parameter controller_list should be specified as an array");
00075 return;
00076 }
00077
00078
00079 for (int i = 0 ; i < controller_list.size() ; ++i)
00080 {
00081 if (!controller_list[i].hasMember("name") || !controller_list[i].hasMember("joints"))
00082 {
00083 ROS_ERROR_STREAM_NAMED("manager","Name and joints must be specifed for each controller");
00084 continue;
00085 }
00086
00087 try
00088 {
00089 std::string name = std::string(controller_list[i]["name"]);
00090
00091 std::string action_ns;
00092 if (controller_list[i].hasMember("ns"))
00093 {
00094
00095 action_ns = std::string(controller_list[i]["ns"]);
00096 ROS_WARN_NAMED("manager","Use of 'ns' is deprecated, use 'action_ns' instead.");
00097 }
00098 else if (controller_list[i].hasMember("action_ns"))
00099 action_ns = std::string(controller_list[i]["action_ns"]);
00100 else
00101 ROS_WARN_NAMED("manager","Please note that 'action_ns' no longer has a default value.");
00102
00103 if (controller_list[i]["joints"].getType() != XmlRpc::XmlRpcValue::TypeArray)
00104 {
00105 ROS_ERROR_STREAM_NAMED("manager","The list of joints for controller " << name << " is not specified as an array");
00106 continue;
00107 }
00108
00109 if (!controller_list[i].hasMember("type"))
00110 {
00111 ROS_ERROR_STREAM_NAMED("manager","No type specified for controller " << name);
00112 continue;
00113 }
00114
00115 std::string type = std::string(controller_list[i]["type"]);
00116
00117 ActionBasedControllerHandleBasePtr new_handle;
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 if ( type == "FollowRobotTrajectory" )
00164 {
00165 ROS_INFO_STREAM_NAMED("mangager","Adding 'FollowRobotTrajectory'...");
00166 new_handle.reset(new ForwardingControllerHandle(trajectory_action_topic, path_action_topic, virtual_joint_name));
00167 ROS_INFO_STREAM_NAMED("manager","Added FollowRobotTrajectory controller for " << name );
00168 controllers_[name] = new_handle;
00169 }
00170
00171 else
00172 {
00173 ROS_ERROR_STREAM_NAMED("manager","Unknown controller type: " << type.c_str());
00174 continue;
00175 }
00176 if (!controllers_[name])
00177 {
00178 controllers_.erase(name);
00179 continue;
00180 }
00181
00182
00183 for (int j = 0 ; j < controller_list[i]["joints"].size() ; ++j)
00184 controllers_[name]->addJoint(std::string(controller_list[i]["joints"][j]));
00185 }
00186 catch (...)
00187 {
00188 ROS_ERROR_STREAM_NAMED("manager","Unable to parse controller information");
00189 }
00190 }
00191 }
00192
00193 moveit_controller_manager::MoveItControllerHandlePtr MultiDOFControllerManager::getControllerHandle(const std::string &name)
00194 {
00195 std::map<std::string, ActionBasedControllerHandleBasePtr>::const_iterator it = controllers_.find(name);
00196 if (it != controllers_.end())
00197 return static_cast<moveit_controller_manager::MoveItControllerHandlePtr>(it->second);
00198 else
00199 ROS_FATAL_STREAM_NAMED("manager","No such controller: " << name);
00200 return moveit_controller_manager::MoveItControllerHandlePtr();
00201 }
00202
00203 void MultiDOFControllerManager::getControllersList(std::vector<std::string> &names)
00204 {
00205 for (std::map<std::string, ActionBasedControllerHandleBasePtr>::const_iterator it = controllers_.begin() ; it != controllers_.end() ; ++it)
00206 names.push_back(it->first);
00207 ROS_INFO_STREAM_NAMED("manager","Returned " << names.size() << " controllers in list");
00208 }
00209
00210 void MultiDOFControllerManager::getControllerJoints(const std::string &name, std::vector<std::string> &joints)
00211 {
00212 std::map<std::string, ActionBasedControllerHandleBasePtr>::const_iterator it = controllers_.find(name);
00213 if (it != controllers_.end())
00214 {
00215 it->second->getJoints(joints);
00216 }
00217 else
00218 {
00219 ROS_WARN_NAMED("manager","The joints for controller '%s' are not known. Perhaps the controller configuration is not loaded on the param server?", name.c_str());
00220 joints.clear();
00221 }
00222 }
00223
00224
00225 moveit_controller_manager::MoveItControllerManager::ControllerState MultiDOFControllerManager::getControllerState(const std::string &name)
00226 {
00227 moveit_controller_manager::MoveItControllerManager::ControllerState state;
00228 state.active_ = true;
00229 state.default_ = true;
00230 return state;
00231 }
00232