38 #ifndef ROBOT_CONTROLLERS_TRAJECTORY_H_ 39 #define ROBOT_CONTROLLERS_TRAJECTORY_H_ 43 #include <trajectory_msgs/JointTrajectory.h> 53 std::vector<double>
q;
54 std::vector<double>
qd;
55 std::vector<double>
qdd;
77 const std::vector<std::string> joints,
81 std::vector<int> mapping(joints.size(), -1);
82 for (
size_t j = 0; j < joints.size(); ++j)
84 for (
size_t i = 0; i < message.joint_names.size(); ++i)
86 if (joints[j] == message.joint_names[i])
99 trajectory->
points.clear();
101 double start_time = message.header.stamp.toSec();
102 if (start_time == 0.0)
106 for (
size_t p = 0; p < message.points.size(); ++p)
109 for (
size_t j = 0; j < joints.size(); ++j)
111 point.
q.push_back(message.points[p].positions[mapping[j]]);
112 if (message.points[p].velocities.size() == message.points[p].positions.size())
113 point.
qd.push_back(message.points[p].velocities[mapping[j]]);
114 if (message.points[p].accelerations.size() == message.points[p].positions.size())
115 point.
qdd.push_back(message.points[p].accelerations[mapping[j]]);
117 point.
time = start_time + message.points[p].time_from_start.toSec();
118 trajectory->
points.push_back(point);
151 size_t num_joints = t1.
points[0].q.size();
152 bool has_velocities = (t1.
points[0].qd.size() == num_joints) &&
153 (t2.
points[0].qd.size() == num_joints);
154 bool has_accelerations = (t1.
points[0].qdd.size() == num_joints) &&
155 (t2.
points[0].qdd.size() == num_joints);
161 double start_t2 = t2.
points[0].time;
164 for (
size_t p = 0; p < t1.
size(); ++p)
166 if (t1.
points[p].time >= time && t1.
points[p].time < start_t2)
168 if (t1.
points[p].time > time && t->
size() == 0)
180 for (
size_t p = 0; p < t2.
size(); ++p)
182 if (t2.
points[p].time >= time)
184 if (t2.
points[p].time > time && t->
size() == 0)
190 else if (t1.
size() > 0)
197 if (!has_accelerations)
200 for (
size_t i = 0; i < t->
points.size(); i++)
209 for (
size_t i = 0; i < t->
points.size(); i++)
224 for (
size_t p = 0; p < t.
size(); ++p)
227 for (
size_t j = 0; j < t.
points[p].q.size(); ++j)
232 ", " << std::setprecision (5) << t.
points[p].qd[j] <<
233 ", " << std::setprecision (5) << t.
points[p].qdd[j]);
238 ", " << std::setprecision (5) << t.
points[p].qd[j]);
256 for (
size_t p = 0; p < trajectory.
size(); p++)
258 if (continuous.size() != trajectory.
points[p].q.size())
264 for (
size_t j = 0; j < continuous.size(); j++)
272 trajectory.
points[p].q[j] = trajectory.
points[p-1].q[j] + shortest;
288 if (continuous.size() != p.
q.size())
293 for (
size_t j = 0; j < continuous.size(); j++)
318 virtual double end_time() = 0;
331 #endif // ROBOT_CONTROLLERS_TRAJECTORY_H_ Basis for a Trajectory Point.
bool trajectoryFromMsg(const trajectory_msgs::JointTrajectory &message, const std::vector< std::string > joints, Trajectory *trajectory)
Convert message into Trajectory.
std::vector< double > qdd
std::vector< TrajectoryPoint > points
bool windupTrajectory(std::vector< bool > continuous, Trajectory &trajectory)
Windup the trajectory so that continuous joints do not wrap.
def normalize_angle(angle)
virtual ~TrajectorySampler()
void rosPrintTrajectory(Trajectory &t)
Print trajectory to ROS INFO.
#define ROS_INFO_STREAM(args)
TrajectorySampler()
Construct a trajectory sampler.
bool unwindTrajectoryPoint(std::vector< bool > continuous, TrajectoryPoint &p)
bool spliceTrajectories(const Trajectory &t1, const Trajectory &t2, const double time, Trajectory *t)
Splice two trajectories.
def shortest_angular_distance(from_angle, to_angle)
Base class for samplers of trajectories.