Stop joint_trajectory_controller execution at rostopic event
I'm on Ubuntu 14.04 with ROS Indigo.
I am using joint_trajectory_controller to control a single actuated joint robotic hand. After having send a control_msgs::FollowJointTrajectoryGoal
to joint_trajectory_controller through an actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction>
, I'm listening for an event on a particular topic.
When this event occurs, I would like to interrupt the execution of the previously sent trajectory and stop the hand joint at the current position.
I have tried to get the joint value from the joint state topic and to publish this of the joint_trajectory_controller but this does not stop the execution of the previous trajectory.
I also tried to send an empty goal to the topic /hand_name/joint_trajectory_controller/follow_joint_trajectory/goal
but this didn't work either.
An outline of the code is the following:
std::shared_ptr<actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction>> client;
client = std::make_shared<actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction>>("/hand_name/joint_trajectory_controller/follow_joint_trajectory", true);
if (client->waitForServer(ros::Duration(1,0))){
control_msgs::FollowJointTrajectoryGoal joint_goal = create_trajectory_goal(joint_position);
client->sendGoalAndWait(joint_goal, ros::Duration(0.5));
}
int id = 0;
while(id == 0){
ROS_INFO("I'm waiting for event!\n");
std_msgs::Int8::ConstPtr id_ptr;
id_ptr = ros::topic::waitForMessage<std_msgs::Int8>("/event_topic", n);
id = id_ptr->data;
if (!id) {
ROS_INFO("No event yet!\n");
} else {
ROS_INFO("Event detected with id %d!\n", id);
// THIS IS WHERE I NEED TO STOP THE JOINT TRAJECTORY CONTROLLER AND SEND ANOTHER TRAJECTORY
}
}
Thank you in advance for the help.