30 #ifndef TRAJECTORY_TRACKER_PATH2D_H 31 #define TRAJECTORY_TRACKER_PATH2D_H 37 #include <Eigen/Geometry> 39 #include <geometry_msgs/Pose.h> 60 inline Pose2D(
const Eigen::Vector2d& p,
float y,
float velocity)
66 inline explicit Pose2D(
const geometry_msgs::Pose& pose,
float velocity)
67 : pos_(Eigen::Vector2d(pose.position.
x, pose.position.
y))
74 const float org_x = pos_.x();
75 const float org_y = pos_.y();
76 const float cos_v = std::cos(ang);
77 const float sin_v = std::sin(ang);
79 pos_.x() = cos_v * org_x - sin_v * org_y;
80 pos_.y() = sin_v * org_x + cos_v * org_y;
84 while (yaw_ > 2 * M_PI)
88 class Path2D :
public std::vector<Pose2D>
91 using Super = std::vector<Pose2D>;
94 using Iterator = std::vector<Pose2D>::iterator;
100 for (
size_t i = 1; i < size(); i++)
101 l += ((*
this)[i - 1].pos_ - (*this)[i].pos_).norm();
107 const bool allow_backward_motion)
const 109 float sign_vel_prev = 0;
114 if (it->pos_ == it_prev->pos_)
117 const Eigen::Vector2d inc = it->pos_ - it_prev->pos_;
120 const float angle_pose = allow_backward_motion ? it->yaw_ : angle;
121 const float sign_vel_req = std::cos(angle) * std::cos(angle_pose) + std::sin(angle) * std::sin(angle_pose);
122 if (sign_vel_prev * sign_vel_req < 0)
124 sign_vel_prev = sign_vel_req;
132 const Eigen::Vector2d& target,
133 const float max_search_range = 0,
134 const float epsilon = 1e-6)
const 139 float distance_path_search = 0;
141 float min_dist = (begin->pos_ - target).norm() +
epsilon;
146 const Eigen::Vector2d inc = it->pos_ - it_prev->pos_;
147 distance_path_search += inc.norm();
148 if (max_search_range > 0 && distance_path_search > max_search_range)
156 const float d_compare = (d > 0) ? d : (-d -
epsilon);
157 const float d_abs = std::abs(d);
161 if (d_compare <= min_dist || (it + 1 == end && d_abs <= min_dist +
epsilon))
174 const Eigen::Vector2d& target_on_line)
const 176 double remain = (nearest->pos_ - target_on_line).norm();
177 if (nearest + 1 >= end)
181 if (last_pre < begin || last < begin)
186 const Eigen::Vector2d vec_path = last->pos_ - last_pre->pos_;
187 const Eigen::Vector2d vec_remain = last->pos_ - target_on_line;
188 if (vec_path.dot(vec_remain) >= 0)
199 remain += (it_prev->pos_ - it->pos_).norm();
207 const Eigen::Vector2d& target_on_line,
208 const float max_search_range)
const 210 if (end - begin <= 1)
214 else if (end - begin == 2)
219 Pose2D rel(it->pos_ - it_prev->pos_, it->yaw_, 0.0f);
220 rel.
rotate(-it_prev->yaw_);
221 const float sin_v = std::sin(rel.
yaw_);
222 static const float EPS = 1.0e-6
f;
223 if (std::abs(sin_v) < EPS)
227 const float cos_v = std::cos(rel.
yaw_);
228 const float r1 = rel.
pos_.y() + rel.
pos_.x() * cos_v / sin_v;
229 const float r2 = std::copysign(
230 std::sqrt(std::pow(rel.
pos_.x(), 2) + std::pow(rel.
pos_.x() * cos_v / sin_v, 2)),
231 rel.
pos_.x() * sin_v);
232 return 1.0f / ((r1 + r2) / 2);
234 const float max_search_range_sq = max_search_range * max_search_range;
241 if ((it->pos_ - target_on_line).squaredNorm() > max_search_range_sq)
251 #endif // TRAJECTORY_TRACKER_PATH2D_H
double remainedDistance(const ConstIterator &begin, const ConstIterator &nearest, const ConstIterator &end, const Eigen::Vector2d &target_on_line) const
std::vector< Pose2D >::const_iterator ConstIterator
ConstIterator findLocalGoal(const ConstIterator &begin, const ConstIterator &end, const bool allow_backward_motion) const
ConstIterator findNearest(const ConstIterator &begin, const ConstIterator &end, const Eigen::Vector2d &target, const float max_search_range=0, const float epsilon=1e-6) const
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
float getCurvature(const ConstIterator &begin, const ConstIterator &end, const Eigen::Vector2d &target_on_line, const float max_search_range) const
float lineStripDistanceSigned(const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &c)
std::vector< Pose2D > Super
std::vector< Pose2D >::iterator Iterator
float curv3p(const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &c)
TFSIMD_FORCE_INLINE const tfScalar & x() const
double getYaw(const tf2::Quaternion &q)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
Pose2D(const Eigen::Vector2d &p, float y, float velocity)
Pose2D(const geometry_msgs::Pose &pose, float velocity)
void rotate(const float ang)