Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #ifndef _FOLLOW_JOINT_TRAJECTORY_CONTROLLER_HANDLER_H_
00038 #define _FOLLOW_JOINT_TRAJECTORY_CONTROLLER_HANDLER_H_
00039
00040 #include <trajectory_execution_monitor/trajectory_controller_handler.h>
00041 #include <control_msgs/FollowJointTrajectoryAction.h>
00042
00043 #include <actionlib/client/simple_action_client.h>
00044 #include <actionlib/client/simple_client_goal_state.h>
00045
00047 class FollowJointTrajectoryControllerHandler : public trajectory_execution_monitor::TrajectoryControllerHandler {
00048
00049 public:
00050
00051 FollowJointTrajectoryControllerHandler(const std::string& group_name,
00052 const std::string& controller_name) :
00053 TrajectoryControllerHandler(group_name, controller_name),
00054 follow_joint_trajectory_action_client_(controller_name, true)
00055 {
00056 while(ros::ok() && !follow_joint_trajectory_action_client_.waitForServer(ros::Duration(5.0))){
00057 ROS_INFO_STREAM("Waiting for the follow joint trajectory action for group " << group_name << " on the topic " << controller_name << " to come up");
00058 }
00059 }
00060
00061 bool executeTrajectory(const trajectory_msgs::JointTrajectory& trajectory,
00062 boost::shared_ptr<trajectory_execution_monitor::TrajectoryRecorder>& recorder,
00063 const trajectory_execution_monitor::TrajectoryFinishedCallbackFunction& traj_callback)
00064 {
00065 recorder_ = recorder;
00066 trajectory_finished_callback_ = traj_callback;
00067
00068 initializeRecordedTrajectory(trajectory);
00069
00070 control_msgs::FollowJointTrajectoryGoal goal;
00071 goal.trajectory = trajectory;
00072
00073 follow_joint_trajectory_action_client_.sendGoal(goal,
00074 boost::bind(&FollowJointTrajectoryControllerHandler::controllerDoneCallback, this, _1, _2),
00075 boost::bind(&FollowJointTrajectoryControllerHandler::controllerActiveCallback, this),
00076 boost::bind(&FollowJointTrajectoryControllerHandler::controllerFeedbackCallback, this, _1));
00077 recorder_->registerCallback(group_controller_combo_name_,
00078 boost::bind(&FollowJointTrajectoryControllerHandler::addNewStateToRecordedTrajectory, this, _1, _2, _3));
00079 return true;
00080 }
00081
00082 void cancelExecution() {
00083 }
00084
00085 void controllerDoneCallback(const actionlib::SimpleClientGoalState& state,
00086 const control_msgs::FollowJointTrajectoryResultConstPtr& result)
00087 {
00088 ROS_INFO_STREAM("Controller is done with state " << state.toString() );
00089
00090 if( controller_state_ == trajectory_execution_monitor::TrajectoryControllerStates::EXECUTING ||
00091 controller_state_ == trajectory_execution_monitor::TrajectoryControllerStates::OVERSHOOTING )
00092 {
00093 if(state == actionlib::SimpleClientGoalState::SUCCEEDED)
00094 {
00095 controller_state_ = trajectory_execution_monitor::TrajectoryControllerStates::SUCCESS;
00096 }
00097 else
00098 {
00099 ROS_WARN_STREAM("Failed state is " << state.toString() << " code " << result->error_code);
00100 controller_state_ = trajectory_execution_monitor::TrajectoryControllerStates::EXECUTION_FAILURE;
00101 }
00102
00103
00104 if( controller_state_==trajectory_execution_monitor::TrajectoryControllerStates::SUCCESS )
00105 {
00106 if( monitor_overshoot_ )
00107 {
00108 initializeOvershootTrajectory();
00109 }
00110 else
00111 {
00112 done();
00113 }
00114 }
00115 else
00116 {
00117 ROS_WARN_STREAM("Controller returned an error. Not recording the overshoot.");
00118 done();
00119 }
00120 }
00121 }
00122
00123 void controllerActiveCallback()
00124 {
00125 ROS_DEBUG_STREAM("Controller went active");
00126 }
00127
00128 void controllerFeedbackCallback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback)
00129 {
00130 ROS_INFO_STREAM("Got feedback");
00131 }
00132
00133
00134 protected:
00135 actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction> follow_joint_trajectory_action_client_;
00136 };
00137
00138 #endif