47 #include <nav_msgs/Path.h>
58 constexpr
double PI = 3.14159265358979323846;
67 inline bool almost_equal(
double d1,
double d2,
double epsilon = 1.0e-12)
69 return std::fabs(d1 - d2) <
epsilon ? true :
false;
80 const auto q = std::floor((rad +
PI) / (2.0 *
PI));
81 rad = (rad +
PI) - q * 2.0 *
PI;
99 const auto q = std::floor(rad / (2.0 *
PI));
100 rad = (rad)-q * 2.0 *
PI;
118 inline double getYaw(
double qx,
double qy,
double qz,
double qw)
122 const auto sqx = qx * qx;
123 const auto sqy = qy * qy;
124 const auto sqz = qz * qz;
125 const auto sqw = qw * qw;
128 const auto sarg = -2.0 * (qx * qz - qw * qy) / (sqx + sqy + sqz + sqw);
133 return -2.0 * std::atan2(qy, qx);
138 return 2.0 * std::atan2(qy, qx);
141 return std::atan2(2.0 * (qx * qy + qw * qz), sqw + sqx - sqy - sqz);
152 inline double distance(
double x0,
double y0,
double x1,
double y1)
154 const auto dx = x1 - x0;
155 const auto dy = y1 - y0;
156 return std::sqrt(dx * dx + dy * dy);
178 return -p * std::log(p) - (1.0 - p) * std::log(1.0 - p);
188 const auto x = range * std::cos(
angle);
189 const auto y = range * std::sin(
angle);
200 const auto x = range * std::cos(
angle);
201 const auto y = range * std::sin(
angle);
202 return { x, y, 1.0 };
214 const mat trans2d = { { std::cos(
angle), -std::sin(
angle), x },
229 const mat trans2d = { { 1.0, 0.0, x }, { 0.0, 1.0, y }, { 0.0, 0.0, 1.0 } };
241 const mat trans2d = { { std::cos(
angle), -std::sin(
angle), 0.0 },
255 const auto stheta = -trans2d(1, 0);
256 const auto ctheta = trans2d(0, 0);
257 const auto theta = std::atan2(stheta, ctheta);
260 const auto x = -(ctheta * trans2d(0, 2) - stheta * trans2d(1, 2));
261 const auto y = -(stheta * trans2d(0, 2) + ctheta * trans2d(1, 2));
289 const vec vb = u * dt;
290 dqb(0) = (vb(0) * std::sin(vb(2)) + vb(1) * (std::cos(vb(2)) - 1.0)) / vb(2);
292 dqb(1) = (vb(1) * std::sin(vb(2)) + vb(0) * (1.0 - std::cos(vb(2)))) / vb(2);
313 const vec& x0,
const vec& u,
double dt,
double horizon)
316 const auto steps =
static_cast<unsigned int>(std::abs(horizon / dt));
318 for (
unsigned int i = 0; i < steps; i++)
340 inline nav_msgs::Path
constTwistPath(
const std::string& map_frame_id,
const vec& x0,
341 const vec& u,
double dt,
double horizon)
344 path.header.frame_id = map_frame_id;
346 const auto steps =
static_cast<unsigned int>(std::abs(horizon / dt));
347 path.poses.resize(steps);
350 for (
unsigned int i = 0; i < steps; i++)
354 path.poses.at(i).pose.position.x = x(0);
355 path.poses.at(i).pose.position.y = x(1);
360 path.poses.at(i).pose.orientation.x = quat.x();
361 path.poses.at(i).pose.orientation.y = quat.y();
362 path.poses.at(i).pose.orientation.z = quat.z();
363 path.poses.at(i).pose.orientation.w = quat.w();