trajectory_follower
TrajectoryFollower.hpp
Go to the documentation of this file.
1 #ifndef TRAJECTORYFOLLOWER_HPP
2 #define TRAJECTORYFOLLOWER_HPP
3 
5 #include "SubTrajectory.hpp"
6 
7 namespace trajectory_follower
8 {
9 
10 class Controller {
11 public:
13  : configured(false)
14  {
15  }
16 
17  virtual ~Controller();
18 
19  virtual Motion2D& update(double speed, double distanceError, double angleError, double curvature, double variationOfCurvature) =0;
20  virtual void reset() =0;
21 
22 protected:
23  bool configured;
25 };
26 
28 public:
30  : Controller()
31  {
32  l1 = base::unset<double>();
33  K0 = base::unset<double>();
34  }
35 
38  {
39  if (config.l1 <= 0)
40  {
41  throw std::runtime_error("l1 value must be greater than zero.");
42  }
43 
44  if (config.K0 <= 0)
45  {
46  throw std::runtime_error("K0 value must be greater than zero.");
47  }
48 
49  l1 = config.l1;
50  K0 = config.K0;
51  configured = true;
52  }
53 
54  virtual Motion2D& update(double speed, double distanceError, double angleError, double curvature, double variationOfCurvature);
55  virtual void reset() { };
56 
57 private:
58  double l1, K0;
59 };
60 
61 class ChainedController : public Controller {
62 public:
64  : Controller()
65  {
66  K0 = base::unset<double>();
67  K2 = base::unset<double>();
68  K3 = base::unset<double>();
69  }
70 
73  {
74  if (config.K2 <= 0 || config.K3 <= 0)
75  {
76  throw std::runtime_error("K2 & K3 value must be greater than zero.");
77  }
78 
79  if (config.K0 <= 0 || base::isUnset< double >(config.K0))
80  {
81  std::cout << "ChainedController disabling integral" << std::endl;
82  // Disabling integral
83  K0 = 0;
84  }
85  else
86  {
87  K0 = config.K0;
88  }
89 
90  K2 = config.K2;
91  K3 = config.K3;
92  configured = true;
93  }
94 
95  virtual Motion2D& update(double speed, double distanceError, double angleError, double curvature, double variationOfCurvature);
96  virtual void reset() {
97  controllerIntegral = 0.;
98  };
99 
100 private:
101  double K0, K2, K3;
102  double controllerIntegral;
103 };
104 
105 class SamsonController : public Controller {
106 public:
108  : Controller()
109  {
110  K2 = base::unset<double>();
111  K3 = base::unset<double>();
112  }
113 
115  : SamsonController()
116  {
117  if(config.K2 <= 0 || config.K3 <= 0)
118  {
119  throw std::runtime_error("K2 & K3 value must be greater than zero.");
120  }
121 
122  K2 = config.K2;
123  K3 = config.K3;
124  configured = true;
125  }
126 
127  virtual Motion2D& update(double speed, double distanceError, double angleError, double curvature, double variationOfCurvature);
128  virtual void reset() { };
129 
130 private:
131  double K2, K3;
132 };
133 
139 {
140 public:
143 
149  TrajectoryFollower(const FollowerConfig& followerConfig);
150 
155  void setNewTrajectory(const SubTrajectory &trajectory, const base::Pose& robotPose);
156 
163  {
164  followerStatus = TRAJECTORY_FINISHED;
165  }
166 
171  FollowerStatus traverseTrajectory(Motion2D &motionCmd, const base::Pose &robotPose);
172 
174  void computeErrors(const base::Pose& robotPose);
175 
178  return followerData;
179  }
180 
181  bool checkTurnOnSpot();
182 
183 private:
184  bool configured;
185  ControllerType controllerType;
186  bool pointTurn;
187  double pointTurnDirection;
188  bool nearEnd;
189  double dampingCoefficient;
190  base::Pose currentPose;
191  base::Pose lastPose;
192  double lastPosError;
193  double currentCurveParameter;
194  double distanceError;
195  double angleError, lastAngleError;
196  double posError;
197  double splineReferenceErrorCoefficient;
198  FollowerData followerData;
199  FollowerStatus followerStatus, lastFollowerStatus;
200  SubTrajectory trajectory;
201  FollowerConfig followerConf;
202  Controller *controller;
203 };
204 
205 }
206 
207 #endif // TRAJECTORYFOLLOWER_HPP
NoOrientationController()
Definition: TrajectoryFollower.hpp:29
Definition: TrajectoryFollowerTypes.hpp:18
const FollowerData & getData()
Definition: TrajectoryFollower.hpp:177
Definition: TrajectoryFollower.hpp:138
Definition: TrajectoryFollowerTypes.hpp:65
Definition: TrajectoryFollowerTypes.hpp:51
Motion2D motionCommand
Definition: TrajectoryFollower.hpp:24
double l1
Position of reference point P(l1,0) on the robot chassis such that l1u1 > 0.
Definition: TrajectoryFollowerTypes.hpp:37
Definition: TrajectoryFollowerTypes.hpp:78
Definition: TrajectoryFollower.hpp:61
Controller()
Definition: TrajectoryFollower.hpp:12
void removeTrajectory()
Definition: TrajectoryFollower.hpp:162
bool configured
Definition: TrajectoryFollower.hpp:23
SamsonController(const SamsonControllerConfig &config)
Definition: TrajectoryFollower.hpp:114
double K2
Controller constant.
Definition: TrajectoryFollowerTypes.hpp:54
ChainedController(const ChainedControllerConfig &config)
Definition: TrajectoryFollower.hpp:71
Definition: TrajectoryFollower.hpp:10
Definition: Motion2D.hpp:8
virtual void reset()
Definition: TrajectoryFollower.hpp:128
virtual void reset()
Definition: TrajectoryFollower.hpp:96
SamsonController()
Definition: TrajectoryFollower.hpp:107
Definition: SubTrajectory.hpp:13
virtual Motion2D & update(double speed, double distanceError, double angleError, double curvature, double variationOfCurvature)=0
double K2
Definition: TrajectoryFollowerTypes.hpp:67
Definition: TrajectoryFollower.hpp:105
ChainedController()
Definition: TrajectoryFollower.hpp:63
Definition: TrajectoryFollower.hpp:27
virtual ~Controller()
Definition: TrajectoryFollower.cpp:8
Definition: Motion2D.hpp:17
double K0
Integrator constant.
Definition: TrajectoryFollowerTypes.hpp:53
double K3
Controller constant.
Definition: TrajectoryFollowerTypes.hpp:55
Definition: TrajectoryFollowerTypes.hpp:124
ControllerType
Definition: TrajectoryFollowerTypes.hpp:26
double K3
Definition: TrajectoryFollowerTypes.hpp:68
FollowerStatus
Definition: TrajectoryFollowerTypes.hpp:15
double K0
Constant for the calculation of k(d, theta_e)
Definition: TrajectoryFollowerTypes.hpp:38
Definition: TrajectoryFollowerTypes.hpp:35
NoOrientationController(const NoOrientationControllerConfig &config)
Definition: TrajectoryFollower.hpp:36
virtual void reset()
Definition: TrajectoryFollower.hpp:55