joint_trajectory_action question
I am reading the joint_trajectory_action.cpp file in joint_trajectory_action ros package.
I have a question about following callback function.
void goalCB(GoalHandle gh)
{
// Ensures that the joints in the goal match the joints we are commanding.
if (!setsEqual(joint_names_, gh.getGoal()->trajectory.joint_names))
{
ROS_ERROR("Joints on incoming goal don't match our joints");
gh.setRejected();
return;
}
// Cancels the currently active goal.
if (has_active_goal_)
{
// Stops the controller.
trajectory_msgs::JointTrajectory empty;
empty.joint_names = joint_names_;
pub_controller_command_.publish(empty);
// Marks the current goal as canceled.
active_goal_.setCanceled();
has_active_goal_ = false;
}
gh.setAccepted();
active_goal_ = gh;
has_active_goal_ = true;
// Sends the trajectory along to the controller
current_traj_ = active_goal_.getGoal()->trajectory;
pub_controller_command_.publish(current_traj_);
}
I don't understand why it needs to cancel the currently active goal.
Thanks for any help in advance!