MultiDOFControllerManager.cpp
Go to the documentation of this file.
00001 #include <moveit_controller_multidof/MultiDOFControllerManager.h>
00002 #include <moveit_controller_multidof/ForwardingControllerHandle.h>
00003 
00004 // XXX BEGIN MULTIDOF_CHANGE  : don't support these actions yet, just to save copying them over here too...
00005 //  unfortunately, those headers are not included as with the catkin dependencies on moveit_simple_controller_manager
00006 //  as of Jade, Feb '16.
00007 // #include <moveit_simple_controller_manager/gripper_controller_handle.h>
00008 // #include <moveit_simple_controller_manager/follow_joint_trajectory_controller_handle.h>
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     // XXX BEGIN MULTIDOF_CHANGE
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=""; //disable virtual joint
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=""; //disable virtual joint
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 /*    if (trajectory_action_topic.empty()) {
00058         ROS_ERROR_STREAM_NAMED("manager","Empty joint_trajectory_action_topic specified. Cannot use this controller.");
00059         return;
00060     }
00061 */
00062     // XXX END MULTIDOF_CHANGE
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     /* actually create each controller */
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           /* TODO: this used to be called "ns", renaming to "action_ns" and will remove in the future */
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 // XXX BEGIN MULTIDOF_CHANGE: Don't support the next two types yet
00119 /*
00120         if ( type == "GripperCommand" )
00121         {
00122           new_handle.reset(new GripperControllerHandle(name, action_ns));
00123           if (static_cast<GripperControllerHandle*>(new_handle.get())->isConnected())
00124           {
00125             if (controller_list[i].hasMember("parallel"))
00126             {
00127               if (controller_list[i]["joints"].size() != 2)
00128               {
00129                 ROS_ERROR_STREAM_NAMED("manager","Parallel Gripper requires exactly two joints");
00130                 continue;
00131               }
00132               static_cast<GripperControllerHandle*>(new_handle.get())->setParallelJawGripper(controller_list[i]["joints"][0], controller_list[i]["joints"][1]);
00133             }
00134             else
00135             {
00136               if (controller_list[i].hasMember("command_joint"))
00137                 static_cast<GripperControllerHandle*>(new_handle.get())->setCommandJoint(controller_list[i]["command_joint"]);
00138               else
00139                 static_cast<GripperControllerHandle*>(new_handle.get())->setCommandJoint(controller_list[i]["joints"][0]);
00140             }
00141 
00142             if (controller_list[i].hasMember("allow_failure"))
00143                 static_cast<GripperControllerHandle*>(new_handle.get())->allowFailure(true);
00144 
00145             ROS_INFO_STREAM_NAMED("manager","Added GripperCommand controller for " << name );
00146             controllers_[name] = new_handle;
00147           }
00148         }
00149         else if ( type == "FollowJointTrajectory" )
00150         {
00151           new_handle.reset(new FollowJointTrajectoryControllerHandle(name, action_ns));
00152           if (static_cast<FollowJointTrajectoryControllerHandle*>(new_handle.get())->isConnected())
00153           {
00154             ROS_INFO_STREAM_NAMED("manager","Added FollowJointTrajectory controller for " << name );
00155             controllers_[name] = new_handle;
00156           }
00157         }
00158         else
00159 */
00160 // XXX END MULTIDOF_CHANGE
00161 
00162 // XXX BEGIN MULTIDOF_CHANGE : Support the "FollowRobotTrajectory" type.
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 // XXX END MULTIDOF_CHANGE
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         /* add list of joints, used by controller manager and moveit */
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 


moveit_controller_multidof
Author(s): Jennifer Buehler
autogenerated on Sat Mar 2 2019 03:50:48