-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaypointNavigation.hpp
161 lines (132 loc) · 4.12 KB
/
WaypointNavigation.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/****************************************************************
*
* Copyright (c) 2016
*
* European Space Technology and Research Center
* ESTEC - European Space Agency
*
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* Description: Library for pure-pursuit based path following
*
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*
* Author: Jan Filip, email:[email protected], [email protected]
* Supervised by: Martin Azkarate, email:[email protected]
*
* Date of creation: Dec 2016
*
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
#ifndef WAYPOINT_NAVIGATION_HPP
#define WAYPOINT_NAVIGATION_HPP
#include <Eigen/Geometry>
#include <vector>
#include <base/samples/rigid_body_state.h>
#include <base/waypoint.h>
#include <base/commands/Motion2D.hpp>
namespace waypoint_navigation_lib{
#define WAYPOINT_NAVIGATION_DEBUG 0
enum NavigationState{
DRIVING=0, // 0
ALIGNING, // 1
TARGET_REACHED, // 2
OUT_OF_BOUNDARIES,// 3
NO_TRAJECTORY, // 4
NO_POSE // 5
};
class WaypointNavigation
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
WaypointNavigation();
/**
* Set positon and orientation, where to drive to
*/
void setLookaheadPoint(base::Waypoint &pose);
/**
* Set current orientation and position
*/
bool setPose(base::samples::RigidBodyState &pose);
/**
* Sets the trajecory the robot should follow
*/
void setTrajectory(std::vector<base::Waypoint *> &t);
/**
* Returns the trajectory
*/
const std::vector<base::Waypoint *> &getTrajectory() const {
return trajectory;
}
NavigationState getNavigationState();
void setNavigationState(NavigationState state);
const base::Waypoint* getLookaheadPoint();
bool update(base::commands::Motion2D& mc);
bool configure( double minR,
double tv, double rv,
double cr, double lad, bool backward
);
bool configurePD(double P, double D, double saturation);
bool configureTol(double TolPos, double TolHeading);
/**
* Calculates a motion command (Ackermann or Point turn)
* given the robot pose and DRIVING mode
*/
void getMovementCommand (base::commands::Motion2D& mc);
bool getProgressOnSegment(int segmentNumber,
double& progress, double& distAlong, double& distPerpend);
double getLookaheadDistance();
void setCurrentSegment(int segmentNumber); // TESTING ONLY - TODO Remove
int getCurrentSegment();
private:
/*
* MEMBER VARIABLES
*/
NavigationState mNavigationState;
bool aligning;
bool targetSet;
bool poseSet;
bool newWaypoint;
bool finalPhase;
bool backwardPerimtted;
double minTurnRadius; // Minimum turn radius [m]
double maxDisplacementAckermannTurn;
double translationalVelocity;
double rotationalVelocity;
double corridor; // Allowed Distance perpendicular to path segment
double lookaheadDistance;
double distanceToPath;
double targetHeading;
// Alignment tolerances
double defaultTolHeading, defaultTolPos;
// Alignment controller
double alignment_deadband, alignment_saturation;
double headingErr, alignment_P, alignment_D;
bool pd_initialized;
base::Time tprev;
base::samples::RigidBodyState curPose;
base::Waypoint targetPose;
std::vector<double> *distanceToNext;
std::vector<base::Waypoint *> trajectory;
base::Waypoint lookaheadPoint;
int currentSegment;
base::Vector2d w1, w2, l1, l2, xr;
/* -------------------------------
* PRIVATE FUNCTIONS
* -------------------------------*/
/**
* Helper function for setting values of Vector2d with X, Y of a trajectory waypoint
*/
bool setSegmentWaypoint(base::Vector2d& waypoint, int indexSegment);
/**
* Helper function for finding the closes point on the path segment
* from the current position of the robot
*/
base::Vector2d getClosestPointOnPath();
void initilalizeCurrentSegment();
bool isInsideBoundaries(double& distAlong, double& distPerpend);
inline void wrapAngle(double& angle);
inline void saturation(double& value, double limit);
};
}
#endif