00001 /* 00002 * Copyright (C) 2014-2015 Fetch Robotics Inc. 00003 * Copyright (C) 2013-2014 Unbounded Robotics Inc. 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 // Author: Michael Ferguson 00019 00020 #ifndef ROBOT_CALIBRATION_CAPTURE_CHAIN_MANAGER_H 00021 #define ROBOT_CALIBRATION_CAPTURE_CHAIN_MANAGER_H 00022 00023 #include <ros/ros.h> 00024 #include <boost/thread/mutex.hpp> 00025 #include <sensor_msgs/JointState.h> 00026 #include <actionlib/client/simple_action_client.h> 00027 #include <control_msgs/FollowJointTrajectoryAction.h> 00028 #include <moveit_msgs/MoveGroupAction.h> 00029 00030 namespace robot_calibration 00031 { 00032 00037 class ChainManager 00038 { 00039 typedef actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction> TrajectoryClient; 00040 typedef actionlib::SimpleActionClient<moveit_msgs::MoveGroupAction> MoveGroupClient; 00041 typedef boost::shared_ptr<MoveGroupClient> MoveGroupClientPtr; 00042 typedef boost::shared_ptr<const moveit_msgs::MoveGroupResult> MoveGroupResultPtr; 00043 00044 // This controls a single chain 00045 struct ChainController 00046 { 00047 ChainController(const std::string& name, 00048 const std::string& topic, 00049 const std::string& planning_group) : 00050 client(topic, true), 00051 chain_name(name), 00052 chain_planning_group(planning_group) 00053 { 00054 } 00055 00056 bool shouldPlan() 00057 { 00058 return (chain_planning_group != ""); 00059 } 00060 00061 TrajectoryClient client; 00062 std::string chain_name; 00063 std::string chain_planning_group; 00064 std::vector<std::string> joint_names; 00065 }; 00066 00067 public: 00073 ChainManager(ros::NodeHandle& nh, double wait_time = 15.0); 00074 00080 bool moveToState(const sensor_msgs::JointState& state); 00081 00085 bool waitToSettle(); 00086 00090 bool getState(sensor_msgs::JointState* state); 00091 00095 std::vector<std::string> getChains(); 00096 00100 std::vector<std::string> getChainJointNames(const std::string& chain_name); 00101 00102 // Mainly for testing 00103 std::string getPlanningGroupName(const std::string& chain_name); 00104 00105 private: 00106 void stateCallback(const sensor_msgs::JointStateConstPtr& msg); 00107 00108 trajectory_msgs::JointTrajectoryPoint makePoint(const sensor_msgs::JointState& state, 00109 const std::vector<std::string>& joints); 00110 00111 ros::Subscriber subscriber_; 00112 sensor_msgs::JointState state_; 00113 double duration_; 00114 boost::mutex state_mutex_; 00115 std::vector<boost::shared_ptr<ChainController> > controllers_; 00116 MoveGroupClientPtr move_group_; 00117 double velocity_factor_; // scaling factor to slow down move_group plans 00118 }; 00119 00120 } // namespace robot_calibration 00121 00122 #endif // ROBOT_CALIBRATION_CAPTURE_CHAIN_MANAGER_H