48 FollowJointTrajectoryController::FollowJointTrajectoryController() :
83 for (
int i = 0; i < names.
size(); ++i)
91 joint_names_.push_back(static_cast<std::string>(name_value));
103 feedback_.joint_names.push_back(j->getName());
141 "Unable to start, not initialized.");
148 "Unable to start, action server is not active.");
165 control_msgs::FollowJointTrajectoryResult
result;
166 server_->setAborted(result,
"Controller manager forced preemption.");
202 for (
size_t i = 0; i <
joints_.size(); ++i)
210 for (
size_t i = 0; i <
joints_.size(); ++i)
218 for (
size_t i = 0; i <
joints_.size(); ++i)
226 for (
size_t j = 0; j <
joints_.size(); ++j)
234 for (
size_t j = 0; j <
joints_.size(); ++j)
245 for (
size_t j = 0; j <
joints_.size(); ++j)
250 control_msgs::FollowJointTrajectoryResult
result;
251 result.error_code = control_msgs::FollowJointTrajectoryResult::PATH_TOLERANCE_VIOLATED;
252 server_->setAborted(result,
"Trajectory path tolerances violated (position).");
253 ROS_ERROR(
"Trajectory path tolerances violated (position).");
264 control_msgs::FollowJointTrajectoryResult
result;
265 result.error_code = control_msgs::FollowJointTrajectoryResult::PATH_TOLERANCE_VIOLATED;
266 server_->setAborted(result,
"Trajectory path tolerances violated (velocity).");
267 ROS_ERROR(
"Trajectory path tolerances violated (velocity).");
280 bool inside_tolerances =
true;
281 for (
size_t j = 0; j <
joints_.size(); ++j)
286 inside_tolerances =
false;
290 if (inside_tolerances)
292 control_msgs::FollowJointTrajectoryResult
result;
293 result.error_code = control_msgs::FollowJointTrajectoryResult::SUCCESSFUL;
294 server_->setSucceeded(result,
"Trajectory succeeded.");
299 control_msgs::FollowJointTrajectoryResult
result;
300 result.error_code = control_msgs::FollowJointTrajectoryResult::GOAL_TOLERANCE_VIOLATED;
301 server_->setAborted(result,
"Trajectory not executed within time limits.");
302 ROS_ERROR(
"Trajectory not executed within time limits");
307 for (
size_t j = 0; j <
joints_.size(); ++j)
320 for (
size_t j = 0; j <
joints_.size(); ++j)
331 for (
size_t j = 0; j <
joints_.size(); ++j)
346 control_msgs::FollowJointTrajectoryResult
result;
350 server_->setAborted(result,
"Controller is not initialized.");
354 if (goal->trajectory.points.empty())
361 if (goal->trajectory.joint_names.size() !=
joints_.size())
363 result.error_code = control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS;
364 server_->setAborted(result,
"Trajectory goal size does not match controlled joints size.");
365 ROS_ERROR(
"Trajectory goal size does not match controlled joints size.");
371 goal_time = goal->trajectory.header.stamp;
376 result.error_code = control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS;
377 server_->setAborted(result,
"Trajectory goal does not match controlled joints");
378 ROS_ERROR(
"Trajectory goal does not match controlled joints");
391 &executable_trajectory))
393 result.error_code = control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS;
394 server_->setAborted(result,
"Unable to splice trajectory");
395 ROS_ERROR(
"Unable to splice trajectory");
407 &executable_trajectory))
409 result.error_code = control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS;
410 server_->setAborted(result,
"Unable to splice trajectory");
411 ROS_ERROR(
"Unable to splice trajectory");
418 if (new_trajectory.
size() > 1)
421 executable_trajectory = new_trajectory;
425 if (goal->trajectory.points[0].time_from_start.toSec() > 0.0 ||
428 executable_trajectory.
points.insert(
429 executable_trajectory.
points.begin(),
431 new_trajectory.
points[0].qdd.size() > 0,
438 executable_trajectory.
points.push_back(
440 new_trajectory.
points[0].qdd.size() > 0,
442 executable_trajectory.
points.push_back(new_trajectory.
points[0]);
456 if (goal->path_tolerance.size() ==
joints_.size())
459 for (
size_t j = 0; j <
joints_.size(); ++j)
463 for (
size_t i = 0; i < goal->path_tolerance.size(); ++i)
474 result.error_code = control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS;
475 server_->setAborted(result,
"Unable to convert path tolerances");
476 ROS_ERROR(
"Unable to convert path tolerances");
490 if (goal->goal_tolerance.size() ==
joints_.size())
492 for (
size_t j = 0; j <
joints_.size(); ++j)
496 for (
size_t i = 0; i < goal->goal_tolerance.size(); ++i)
507 result.error_code = control_msgs::FollowJointTrajectoryResult::INVALID_JOINTS;
508 server_->setAborted(result,
"Unable to convert goal tolerances");
509 ROS_ERROR(
"Unable to convert goal tolerances");
520 for (
size_t j = 0; j <
joints_.size(); ++j)
533 result.error_code = control_msgs::FollowJointTrajectoryResult::GOAL_TOLERANCE_VIOLATED;
534 server_->setAborted(result,
"Cannot execute trajectory, unable to start controller.");
535 ROS_ERROR(
"Cannot execute trajectory, unable to start controller.");
542 if (
server_->isPreemptRequested())
544 control_msgs::FollowJointTrajectoryResult result;
545 server_->setPreempted(result,
"Trajectory preempted");
573 bool incl_vel,
bool incl_acc,
bool zero_vel)
578 for (
size_t j = 0; j <
joints_.size(); ++j)
579 point.
q[j] =
joints_[j]->getPosition();
581 if (incl_vel && zero_vel)
584 for (
size_t j = 0; j <
joints_.size(); ++j)
590 for (
size_t j = 0; j <
joints_.size(); ++j)
598 for (
size_t j = 0; j <
joints_.size(); ++j)
Basis for a Trajectory Point.
bool trajectoryFromMsg(const trajectory_msgs::JointTrajectory &message, const std::vector< std::string > joints, Trajectory *trajectory)
Convert message into Trajectory.
boost::shared_ptr< TrajectorySampler > sampler_
control_msgs::FollowJointTrajectoryFeedback feedback_
TrajectoryPoint goal_tolerance_
std::vector< double > qdd
This ROS interface implements a FollowJointTrajectoryAction interface for controlling (primarily) rob...
virtual bool stop(bool force)
Attempt to stop the controller. This should be called only by the ControllerManager instance...
Sampler that uses splines.
std::vector< TrajectoryPoint > points
virtual std::vector< std::string > getClaimedNames()
Get the names of joints/controllers which this controller exclusively claims.
bool windupTrajectory(std::vector< bool > continuous, Trajectory &trajectory)
Windup the trajectory so that continuous joints do not wrap.
virtual int requestStart(const std::string &name)
Type const & getType() const
TrajectoryPoint path_tolerance_
bool stop_on_path_violation_
virtual int requestStop(const std::string &name)
void executeCb(const control_msgs::FollowJointTrajectoryGoalConstPtr &goal)
Callback for goal.
actionlib::SimpleActionServer< control_msgs::FollowJointTrajectoryAction > server_t
boost::shared_ptr< server_t > server_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
virtual std::vector< std::string > getCommandedNames()
Get the names of joints/controllers which this controller commands.
boost::mutex sampler_mutex_
const std::string & getNamespace() const
virtual void update(const ros::Time &now, const ros::Duration &dt)
This is the update loop for the controller.
TrajectoryPoint last_sample_
virtual bool reset()
Cleanly reset the controller to it's initial state. Some controllers may choose to stop themselves...
ControllerManager * manager_
std::vector< std::string > joint_names_
std::vector< JointHandlePtr > joints_
virtual int init(ros::NodeHandle &nh, ControllerManager *manager)
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR_NAMED(name,...)
std::vector< bool > continuous_
virtual bool start()
Attempt to start the controller. This should be called only by the ControllerManager instance...
TrajectoryPoint getPointFromCurrent(bool incl_vel, bool incl_acc, bool zero_vel)
Get a trajectory point from the current position/velocity/acceleration.
double goal_time_tolerance_
JointHandlePtr getJointHandle(const std::string &name)
bool unwindTrajectoryPoint(std::vector< bool > continuous, TrajectoryPoint &p)
#define ROS_ERROR_STREAM(args)
bool spliceTrajectories(const Trajectory &t1, const Trajectory &t2, const double time, Trajectory *t)
Splice two trajectories.
virtual int init(ros::NodeHandle &nh, ControllerManager *manager)
Initialize the controller and any required data structures.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
def shortest_angular_distance(from_angle, to_angle)