Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <ros/ros.h>
00018 #include <mtconnect_state_machine/utilities.h>
00019 #include <boost/shared_ptr.hpp>
00020 #include <actionlib/client/simple_action_client.h>
00021 #include <control_msgs/FollowJointTrajectoryAction.h>
00022 #include <arm_navigation_msgs/FilterJointTrajectoryWithConstraints.h>
00023
00024 typedef actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction> JointTractoryClient;
00025 typedef boost::shared_ptr<JointTractoryClient> JointTractoryClientPtr;
00026 typedef std::map<std::string, trajectory_msgs::JointTrajectoryPtr>::iterator JTPMapItr;
00027
00028 static const std::string PARAM_TASK_DESCRIPTION = "task_description";
00029 static const std::string DEFAULT_TRAJECTORY_FILTER_SERVICE = "filter_trajectory_with_constraints";
00030 static const std::string DEFAULT_JOINT_TRAJ_ACTION = "joint_trajectory_action";
00031
00032 int main(int argc, char** argv)
00033 {
00034 ros::init(argc, argv, "mtconnect_state_machine");
00035
00036 ros::NodeHandle ph("~");
00037 ros::NodeHandle nh;
00038
00039 std::string task_desc;
00040 std::map<std::string, trajectory_msgs::JointTrajectoryPtr> joint_paths;
00041
00042 JointTractoryClientPtr joint_traj_client_ptr;
00043 control_msgs::FollowJointTrajectoryGoal joint_traj_goal;
00044
00045 ros::ServiceClient trajectory_filter_client;
00046 arm_navigation_msgs::FilterJointTrajectoryWithConstraints trajectory_filter_;
00047
00048
00049
00050 ROS_INFO_STREAM("Loading parameters");
00051 if (!ph.getParam(PARAM_TASK_DESCRIPTION, task_desc))
00052 {
00053 ROS_ERROR("Failed to load task description parameter");
00054 return false;
00055 }
00056
00057 std::map<std::string, boost::shared_ptr<mtconnect::JointPoint> > temp_pts;
00058 if (!mtconnect_state_machine::parseTaskXml(task_desc, joint_paths, temp_pts))
00059 {
00060 ROS_ERROR("Failed to parse xml");
00061 return false;
00062 }
00063
00064 ROS_INFO_STREAM("Loaded " << joint_paths.size() << " paths");
00065
00066
00067
00068 joint_traj_client_ptr = JointTractoryClientPtr(new JointTractoryClient(DEFAULT_JOINT_TRAJ_ACTION, true));
00069
00070 trajectory_filter_client = nh.serviceClient<arm_navigation_msgs::FilterJointTrajectoryWithConstraints>(
00071 DEFAULT_TRAJECTORY_FILTER_SERVICE);
00072
00073 ROS_INFO_STREAM("Waiting for joint trajectory filter and action server");
00074 joint_traj_client_ptr->waitForServer(ros::Duration(0));
00075 trajectory_filter_client.waitForExistence();
00076
00077 ROS_INFO_STREAM("Starting loop through trajectory");
00078
00079 while (ros::ok())
00080 {
00081 for(JTPMapItr itr = joint_paths.begin(); itr != joint_paths.end(); itr++)
00082 {
00083 ROS_INFO_STREAM("Loading " << itr->first << " path");
00084 joint_traj_goal.trajectory = *itr->second;
00085 ROS_INFO_STREAM("Filtering a joint trajectory with " << joint_traj_goal.trajectory.points.size() << " points");
00086 trajectory_filter_.request.trajectory = joint_traj_goal.trajectory;
00087
00088 if (trajectory_filter_client.call(trajectory_filter_))
00089 {
00090 if (trajectory_filter_.response.error_code.val == trajectory_filter_.response.error_code.SUCCESS)
00091 {
00092 ROS_INFO_STREAM("======================== MOVING ROBOT ========================");
00093 ROS_INFO("Trajectory successfully filtered...sending goal");
00094 joint_traj_goal.trajectory = trajectory_filter_.response.trajectory;
00095 ROS_INFO_STREAM("Sending a joint trajectory with " << joint_traj_goal.trajectory.points.size() << " points");
00096
00097
00098 joint_traj_client_ptr->sendGoalAndWait(joint_traj_goal, ros::Duration(120), ros::Duration(120));
00099 }
00100 }
00101
00102 else
00103 {
00104 ROS_ERROR("Failed to call filter trajectory");
00105 }
00106 }
00107 }
00108
00109 return 0;
00110 }