40 const geometry_msgs::Pose2D&
getClosestPose(
const dwb_msgs::Trajectory2D& trajectory,
const double time_offset)
43 const unsigned int num_poses = trajectory.poses.size();
48 unsigned int closest_index = num_poses;
49 double closest_diff = 0.0;
50 for (
unsigned int i=0; i < num_poses; ++i)
52 double diff = fabs((trajectory.time_offsets[i] - goal_time).toSec());
53 if (closest_index == num_poses || diff < closest_diff)
58 if (goal_time < trajectory.time_offsets[i])
63 return trajectory.poses[closest_index];
66 geometry_msgs::Pose2D
projectPose(
const dwb_msgs::Trajectory2D& trajectory,
const double time_offset)
69 const unsigned int num_poses = trajectory.poses.size();
74 if (goal_time <= trajectory.time_offsets[0])
76 return trajectory.poses[0];
78 else if (goal_time >= trajectory.time_offsets[num_poses - 1])
80 return trajectory.poses[num_poses - 1];
83 for (
unsigned int i=0; i < num_poses - 1; ++i)
85 if (goal_time >= trajectory.time_offsets[i] && goal_time < trajectory.time_offsets[i+1])
87 double time_diff = (trajectory.time_offsets[i+1] - trajectory.time_offsets[i]).toSec();
88 double ratio = (goal_time - trajectory.time_offsets[i]).toSec() / time_diff;
89 double inv_ratio = 1.0 - ratio;
90 const geometry_msgs::Pose2D& pose_a = trajectory.poses[i];
91 const geometry_msgs::Pose2D& pose_b = trajectory.poses[i + 1];
92 geometry_msgs::Pose2D projected;
93 projected.x = pose_a.x * inv_ratio + pose_b.x * ratio;
94 projected.y = pose_a.y * inv_ratio + pose_b.y * ratio;
95 projected.theta = pose_a.theta * inv_ratio + pose_b.theta * ratio;
101 return trajectory.poses[num_poses - 1];
const geometry_msgs::Pose2D & getClosestPose(const dwb_msgs::Trajectory2D &trajectory, const double time_offset)
Helper function to find a pose in the trajectory with a particular time time_offset.
geometry_msgs::Pose2D projectPose(const dwb_msgs::Trajectory2D &trajectory, const double time_offset)
Helper function to create a pose with an exact time_offset by linearly interpolating between existing...