44 double discretization, std::string group_name)
45 : planning_group_name_(group_name)
46 , num_points_((duration / discretization) + 1)
47 , discretization_(discretization)
50 , end_index_(num_points_ - 2)
58 double discretization, std::string group_name)
62 ,
duration_((num_points - 1) * discretization)
79 int start_extra = (diff_rule_length - 1) - source_traj.
start_index_;
95 int source_traj_point = i - start_extra;
96 if (source_traj_point < 0)
97 source_traj_point = 0;
103 (*this)(i, j) = source_traj(source_traj_point, j);
109 const trajectory_msgs::JointTrajectory& traj)
114 double discretization = (traj.points[1].time_from_start - traj.points[0].time_from_start).toSec();
116 double discretization2 = (traj.points[2].time_from_start - traj.points[1].time_from_start).toSec();
118 if (fabs(discretization2 - discretization) > .001)
120 ROS_WARN_STREAM(
"Trajectory Discretization not constant " << discretization <<
" " << discretization2);
125 duration_ = (traj.points.back().time_from_start - traj.points[0].time_from_start).toSec();
148 for (
unsigned int i = 1; i <= traj.points.size(); i++)
150 for (
unsigned int j = 0; j < traj.joint_names.size(); j++)
152 trajectory_(i, j) = traj.points[i - 1].positions[j];
168 trajectory_.block(start_index_, i, num_vars_free, 1) =
179 double theta = ((*this)(end_index, i) - (*
this)(start_index, i)) / (end_index - 1);
180 for (
int j = start_index + 1; j < end_index; j++)
182 (*this)(j, i) = (*
this)(start_index, i) + j * theta;
192 std::vector<double> coeffs(4, 0);
193 double total_time = (end_index - 1) * dt;
196 coeffs[0] = (*this)(start_index, i);
197 coeffs[2] = (3 / (
pow(total_time, 2))) * ((*this)(end_index, i) - (*
this)(start_index, i));
198 coeffs[3] = (-2 / (
pow(total_time, 3))) * ((*this)(end_index, i) - (*
this)(start_index, i));
201 for (
int j = start_index + 1; j < end_index; j++)
204 (*this)(j, i) = coeffs[0] + coeffs[2] *
pow(t, 2) + coeffs[3] *
pow(t, 3);
217 for (
int i = 2; i <= 5; i++)
218 T[i] = T[i - 1] * T[1];
225 double x0 = (*this)(start_index, i);
226 double x1 = (*this)(end_index, i);
230 coeff[i][3] = (-20 * x0 + 20 * x1) / (2 * T[3]);
231 coeff[i][4] = (30 * x0 - 30 * x1) / (2 * T[4]);
232 coeff[i][5] = (-12 * x0 + 12 * x1) / (2 * T[5]);
236 for (
int i = start_index + 1; i < end_index; i++)
241 for (
int k = 2; k <= 5; k++)
242 t[k] = t[k - 1] * t[1];
247 for (
int k = 0; k <= 5; k++)
249 (*this)(i, j) += t[k] * coeff[j][k];
258 moveit_msgs::RobotTrajectory trajectory_msg = res.trajectory[0];
261 int num_chomp_trajectory_points = (*this).getNumPoints();
263 int num_response_points = trajectory_msg.joint_trajectory.points.size();
266 if (num_response_points < 2)
270 int num_joints_trajectory = trajectory_msg.joint_trajectory.points[0].positions.size();
273 int repeated_factor = num_chomp_trajectory_points / num_response_points;
274 int repeated_balance_factor = num_chomp_trajectory_points % num_response_points;
277 int response_point_id = 0;
278 if (num_chomp_trajectory_points >= num_response_points)
280 for (
int i = 0; i < num_response_points; i++)
284 for (
int k = 0; k < repeated_factor; k++)
291 if (i < repeated_balance_factor)
302 double decimation_sampling_factor = ((double)num_response_points) / ((double)num_chomp_trajectory_points);
304 for (
int i = 0; i < num_chomp_trajectory_points; i++)
306 int sampled_point = floor(i * decimation_sampling_factor);
314 int num_joints_trajectory,
315 int trajectory_msgs_point_index,
316 int chomp_trajectory_point_index)
320 for (
int j = 0; j < num_joints_trajectory; j++)
321 (*
this)(chomp_trajectory_point_index, j) =
322 trajectory_msg.joint_trajectory.points[trajectory_msgs_point_index].positions[j];
ChompTrajectory(const moveit::core::RobotModelConstPtr &robot_model, double duration, double discretization, std::string groupName)
Constructs a trajectory for a given robot model, trajectory duration, and discretization.
bool fillInFromTrajectory(moveit_msgs::MotionPlanDetailedResponse &res)
Receives the path obtained from a given MotionPlanDetailedResponse res object's trajectory (e...
virtual ~ChompTrajectory()
Destructor.
void fillInCubicInterpolation()
Generates a cubic interpolation of the trajectory from the start index to end index.
std::vector< int > full_trajectory_index_
void assignCHOMPTrajectoryPointFromInputTrajectoryPoint(moveit_msgs::RobotTrajectory trajectory_msg, int num_joints_trajectory, int trajectory_msgs_point, int chomp_trajectory_point)
Eigen::MatrixXd trajectory_
void init()
Allocates memory for the trajectory.
void fillInMinJerk()
Generates a minimum jerk trajectory from the start index to end index.
std::string planning_group_name_
void updateFromGroupTrajectory(const ChompTrajectory &group_trajectory)
Updates the full trajectory (*this) from the group trajectory.
#define ROS_WARN_STREAM(args)
Represents a discretized joint-space trajectory for CHOMP.
void overwriteTrajectory(const trajectory_msgs::JointTrajectory &traj)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
void fillInLinearInterpolation()
Generates a linearly interpolated trajectory from the start index to end index.
const std::vector< const JointModel * > & getActiveJointModels() const
int getNumJoints() const
Gets the number of joints in each trajectory point.