Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
control.hpp
Go to the documentation of this file.
1 #ifndef _CONTROL_HPP_
2 #define _CONTROL_HPP_
3 
4 #include "utils/logger.hpp"
5 #include "utils/poly.hpp"
6 #include "utils/clock.hpp"
7 #include "pose.hpp"
8 
9 #include <exception>
10 #include <memory>
11 #include <math.h>
12 #include <vector>
13 
14 #include <Eigen/Dense>
15 
16 constexpr float MATH_PI = 3.141592653f;
17 constexpr double MATH_PI_DOUBLE = 3.141592653589793238;
18 
19 using namespace galaxis;
20 using namespace galaxis::utils;
21 using namespace galaxis::control;
22 
23 namespace galaxis {
24  namespace control {
25 
26  std::shared_ptr<CarPose> get_new_pose(std::shared_ptr<CarPose> const p_currentPoseSPtr, float p_carWheelbase, float p_distance, float p_yawDiff);
27 
29  private:
30  int m_horizon;
32  std::shared_ptr<std::vector<float>> const m_yawStepsSPtr;
33 
34  float m_crossAngleErrorWeight = 0;
35  float m_crossLineMarkingErrorWeight = 0;
36 
37  float m_carWheelbase = 0.205f;
38  float m_errorIncraseFactor = 5;
39 
40  float m_lastYawRate = 0;
41  float m_currentVelocity = 0;
42  float m_horizonStepTimeSec = 0.5f; // 800 milliseconds
43 
44  // debug
46  std::shared_ptr<CarPoseSeries> m_lastFirstPoseSeries;
47  std::shared_ptr<CarPoseSeries> m_lastSecondPoseSeries;
48 
49  public:
50  // TwoAndAHalfCarrots() = delete;
51  TwoAndAHalfCarrots(std::shared_ptr<std::vector<float>> const p_yawStepsSPtr, float p_horizonStepTimeSec = 0.5, int p_horizon = 2, int p_errorAccuracyStepsPerHorizon = 4, float p_carWheelbase = 0.205f, float p_errorIncraseFactor = 3);
52  void set_horizon(int p_horizon);
53  bool set_horizon_step_time(float valueSec);
54  bool set_error_factor_first_horizon(float factor);
55  bool set_error_accuracy_steps_per_horizon(int value);
56  void set_cross_angle_error_weight(float val);
57  void set_cross_line_marking_error_weight(float val);
58 
59 
60  // calulates the best drive trajectory compared with reference trajectory and returns yaw rate (bzw. lenkwinkel)
61  // -> all trajectories are relative to the car
62  // -> Velocity must be in m/s
63  // -> assuming yaw rate is steering angle
64  // TODO: implement other horizons
65  float calculate_best_yaw_rate(std::shared_ptr<PolySpline> p_referenceTrajectorySPtr,
66  std::shared_ptr<line_markings_reference_t> p_lineMarkings,
67  float p_currentVelocity, CarPose p_pose = CarPose());
68 
69  // based on single-track model
70  // distance in m, yawrate in radians
71  std::shared_ptr<CarPoseSeries> get_pose_series(std::shared_ptr<CarPose> const p_currentPoseSPtr, float p_distance, float p_yawRate, int p_steps);
72 
73  std::shared_ptr<CarPoseSeries const> get_last_first_poseseries() const;
74  std::shared_ptr<CarPoseSeries const> get_last_second_poseseries() const;
75  float get_last_best_yaw_rate() const;
76  };
77  } // namespace control
78 } // namespace galaxis
79 
80 #endif // _CONTROL_HPP_
galaxis::control::TwoAndAHalfCarrots::m_lastFirstPoseSeries
std::shared_ptr< CarPoseSeries > m_lastFirstPoseSeries
Definition: control.hpp:46
clock.hpp
pose.hpp
galaxis::control::TwoAndAHalfCarrots::m_lastSecondPoseSeries
std::shared_ptr< CarPoseSeries > m_lastSecondPoseSeries
Definition: control.hpp:47
galaxis::control::TwoAndAHalfCarrots::m_yawStepsSPtr
const std::shared_ptr< std::vector< float > > m_yawStepsSPtr
Definition: control.hpp:32
poly.hpp
galaxis::control::TwoAndAHalfCarrots::m_debugStopwatch
MicroStopwatch m_debugStopwatch
Definition: control.hpp:45
galaxis::control::TwoAndAHalfCarrots
Definition: control.hpp:28
galaxis::control::TwoAndAHalfCarrots::m_errorAccuracyStepsPerHorizon
int m_errorAccuracyStepsPerHorizon
Definition: control.hpp:31
MATH_PI_DOUBLE
constexpr double MATH_PI_DOUBLE
Definition: control.hpp:17
galaxis
Definition: MapClasses.hpp:10
galaxis::control
Definition: control.hpp:24
logger.hpp
galaxis::utils
Definition: clock.hpp:5
galaxis::control::CarPose
Definition: pose.hpp:11
MATH_PI
constexpr float MATH_PI
Definition: control.hpp:16
galaxis::utils::MicroStopwatch
Definition: clock.hpp:10
galaxis::control::get_new_pose
std::shared_ptr< CarPose > get_new_pose(std::shared_ptr< CarPose > const p_currentPoseSPtr, float p_carWheelbase, float p_distance, float p_yawDiff)
Definition: control.cpp:168
galaxis::control::TwoAndAHalfCarrots::m_horizon
int m_horizon
Definition: control.hpp:30