123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #ifndef __NAV_COMM_H__
- #define __NAV_COMM_H__
- #include <stdio.h>
- #include <vector>
- #include <cmath>
- namespace common
- {
- using Point = struct _Point;
- using Path = std::vector<struct _Point>;
- using Twist = struct _Twist;
- using Config = struct _Config;
- struct _Twist
- {
- _Twist() : x(0.0), y(0.0), angular(0.0)
- {}
- float x;
- float y;
- float angle;
- float angular;
- };
- struct _Point {
- _Point() : x(0.0),
- y(0.0),
- theta(0.0),
- head(0.0),
- max_linear(0.0)
- {}
- float x;
- float y;
- float theta;
- float head;
- float max_linear;
- };
- struct _Config
- {
- _Config() : max_linear(0.5),
- max_transla(0.5),
- max_angular(0.5),
- minmal_next(0.4),
- maxmal_next(0.8),
- const_next(false),
- maxmal_offset(1.2),
- close_ad(1.0),
- toler_x(0.01),
- toler_y(0.01),
- toler_theta(0.01),
- toler_start_theta(0.1),
- toler_follow(0.2),
- toler_follow_theta(0.51),
- angular_slow_p(0.8),
- linear_slow_p(0.3)
- {}
- float max_linear;
- float max_transla;
- float max_angular;
- float minmal_next;
- float maxmal_next;
- bool const_next;
- float maxmal_offset;
- float close_ad;
-
- float toler_x;
- float toler_y;
- float toler_theta;
- float toler_start_theta;
- float toler_follow;
- float toler_follow_theta;
- float angular_slow_p;
- float linear_slow_p;
- };
- enum NavState {
- DATA_MISS = -2,
- HEAD_WARN,
- HIT_OBSTACLE,
- OFF_COURSE,
- PATH_BLOCK,
- STOP,
- PATH_EMPTY,
- TOO_CLOSE,
- ING,
- ROTATE,
- DONE
- };
- enum NavStep {
- STANDBY = 0,
- TANGENT,
- TRACK,
- ANGLE,
- COMPLETE
- };
- inline float dist(Point p1, Point p2)
- {
- return hypot(p1.x - p2.x, p1.y - p2.y);
- }
- inline float lineL(common::Path& path, int s, int e)
- {
- float l = 0;
- for (int i = s;i < e - 1;i++) {
- l += dist(path[i], path[i + 1]);
- }
- return l;
- }
- inline float PLD(common::Point& p1, common::Point& p2, common::Point& p)
- {
- float mu = p.y * (p2.x - p1.x) - p.x * (p2.y - p1.y) + p1.x * (p2.y - p1.y) - p1.y * (p2.x - p1.x);
- float z = sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y));
- return fabs(mu) / z;
- }
- inline float norm(float t)
- {
- float pi = 3.1415926;
- while (t > 2.0 * pi) {
- t -= 2.0 * pi;
- }
- while (t < -2.0 * pi) {
- t += 2.0 * pi;
- }
- if (t > pi) {
- t -= 2.0 * pi;
- }
- if (t < -pi) {
- t += 2.0 * pi;
- }
-
- return t;
- }
- }
- #endif
|