Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
AutoPilot.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef AUTOPILOT_HPP
4 #define AUTOPILOT_HPP
5 
6 #include "Map/MapDataLayer.hpp"
10 
12 #include "galaxis/linatypes.hpp"
13 #include "utils/mvector.hpp"
14 
15 #include <boost/asio.hpp>
16 #include <boost/asio/thread_pool.hpp>
17 
18 #include <memory>
19 
20 using namespace galaxis;
21 
22 constexpr double MATH_PI_DOUBLE = 3.141592653589793238;
23 
26 
28  double leftPolyMax;
29  double leftPolyMin;
31  double centerPolyMax;
32  double centerPolyMin;
34  double rightPolyMax;
35  double rightPolyMin;
36 
37  float velocityReference = 1; // m/s
38  bool indicatorLeft = false;
39  bool indicatorRight = false;
42 
43  bool startParking = false;
44 };
45 
46 class AutoPilot {
47  // Member Vars
48 public:
52 
53  std::shared_ptr<LinesObject<int16_t>> m_linesObject;
54  std::unique_ptr<std::pair<std::vector<galaxis::lina::Vector2f>, std::vector<galaxis::lina::Vector2f>>> m_laneCentersPairVecUPtr;
55  std::pair<DynamicPolynom, DynamicPolynom> m_lanePolynom;
56 
57  std::shared_ptr<DriveInformation_t> m_lastDriveInformationSPtr;
58 
59  std::vector<double> m_polynomPointsXVector;
60  std::vector<double> m_polynomPointsYVector;
61 
62 private:
64 
65  boost::asio::thread_pool m_threadPool;
66  std::shared_mutex m_sharedThreadMutex;
67 
68  // Temporary Line Vector
69  std::shared_ptr<std::map<int16_t, int16_t>> m_leftLineXYTmpVecSPtr;
70  std::shared_ptr<std::map<int16_t, int16_t>> m_centerLineXYTmpVecSPtr;
71  std::shared_ptr<std::map<int16_t, int16_t>> m_rightLineXYTmpVecSPtr;
72  std::shared_ptr<std::map<int16_t, int16_t>> m_leftLineYXTmpVecSPtr;
73  std::shared_ptr<std::map<int16_t, int16_t>> m_centerLineYXTmpVecSPtr;
74  std::shared_ptr<std::map<int16_t, int16_t>> m_rightLineYXTmpVecSPtr;
75 
76  // Temporary Line Vector 2
77  std::shared_ptr<std::vector<double>> m_leftLinePolynomXVectorSPtr;
78  std::shared_ptr<std::vector<double>> m_leftLinePolynomYVectorSPtr;
79 
80  std::shared_ptr<std::vector<double>> m_centerLinePolynomXVectorSPtr;
81  std::shared_ptr<std::vector<double>> m_centerLinePolynomYVectorSPtr;
82 
83  std::shared_ptr<std::vector<double>> m_rightLinePolynomXVectorSPtr;
84  std::shared_ptr<std::vector<double>> m_rightLinePolynomYVectorSPtr;
85 
86  std::tuple<float, float, float, float> m_laneBlocked;
87 
88  double m_leftPolyMax;
89  double m_leftPolyMin;
90  std::shared_ptr<std::vector<double>> m_leftLinePoly;
93  std::shared_ptr<std::vector<double>> m_centerLinePoly;
96  std::shared_ptr<std::vector<double>> m_rightLinePoly;
97 
98  rclcpp::Time m_lastTimeLaneVisible;
99 
100 public:
101  // Settings
102  // > Obstacle
103  int m_obstacleLookupDistanceCM = 200;
104  int m_obstacleLookupDistanceStepCM = 5;
105  int m_obstacleToLaneCenterMinimumDistanceForDodge = 10;
106  // > Polynom
107  int m_polynomDegree = 3;
108  int m_polynomMinimumPointsAmount = 30;
109  // > Trajectory: append behind car a straight line
110  int m_trajPointsToAppendAmount = 5;
111  int m_trajPointsStartAppendingOffset = 20;
112  // > Postprocessing: Cluster Line
113  int m_lineClusterEps = 2;
114  int m_lineClusterMinPts = 2;
115  // > Postprocessing: Lane Center Improvement with Polynom Fitting
116  int m_linePolynomEvaluationStepCM = 1;
117  int m_linePolynomEvaluationStepSizeCM = 8;
118  int m_minNumberOfClusteredLinePoints = 20;
119 
120 
121  // Line Polynom Points for Plotting (DEBUG)
122  std::shared_ptr<std::vector<Vector2f>> m_leftLinePolynomPointsVecSPtr;
123  std::shared_ptr<std::vector<Vector2f>> m_rightLinePolynomPointsVecSPtr;
124 
125 
126 // Class Functions
127 public:
128  AutoPilot() = delete;
129  AutoPilot(GalaxisNode* p_gNodePtr);
130  ~AutoPilot();
131 
132  // ############## Settings ##############
133  void set_obstacle_lookup_distance(int value);
134  void set_obstacle_lookup_distance_step(float value);
135  void set_obstacle_to_lane_center_min_distance_for_dodge(float value);
136  void set_polynom_degree(int value);
137  void set_polynom_min_points_amount(int value);
138  void set_traj_points_to_append_amount(int value);
139  void set_traj_points_start_appending_offset(int value);
140  void set_line_cluster_eps(int value);
141  void set_line_cluster_min_pts(int value);
142  void set_line_polynom_evaluation_step(int value);
143  void set_line_polynom_evaluation_step_size(int value);
144  void set_min_number_of_clustered_line_points(int value);
145 
146  std::shared_ptr<DriveInformation_t> get_drive_information();
147 
148 private:
149  void cluster_line_object(std::map<int16_t, std::vector<int16_t>>& linePointsMapInputRef, std::shared_ptr<std::map<int16_t, int16_t>> linePointsOutVecSPtr);
150  std::unique_ptr<std::pair<std::vector<galaxis::lina::Vector2f>, std::vector<galaxis::lina::Vector2f>>> get_lane_centers(std::shared_ptr<PositionTimepoint> positionTimepoint);
151  std::unique_ptr<std::pair<std::vector<galaxis::lina::Vector2f>, std::vector<galaxis::lina::Vector2f>>> get_lane_center();
152 
153  void get_lane_centers_thread_helper(Eigen::Rotation2Df p_reverseRotationMat,
154  std::shared_ptr<std::map<int16_t, int16_t>> p_leftLinePointsMapSPtr,
155  std::shared_ptr<std::map<int16_t, int16_t>> p_centerLinePointsMapSPtr,
156  std::shared_ptr<std::map<int16_t, int16_t>> p_rightLinePointsMapSPtr,
157  std::shared_ptr<MutexedVectorPointer<galaxis::lina::Vector2f>> p_leftLaneMutexedVecSPtr,
158  std::shared_ptr<MutexedVectorPointer<galaxis::lina::Vector2f>> p_rightLaneMutexedVecSPtr,
159  bool p_yxMapping);
160  void get_lane_centers_via_polynom_thread_helper(Eigen::Rotation2Df p_reverseRotationMat,
161  std::shared_ptr<std::map<int16_t, int16_t>> p_leftLinePointsMapSPtr,
162  std::shared_ptr<std::map<int16_t, int16_t>> p_centerLinePointsMapSPtr,
163  std::shared_ptr<std::map<int16_t, int16_t>> p_rightLinePointsMapSPtr,
164  std::shared_ptr<MutexedVectorPointer<galaxis::lina::Vector2f>> p_leftLaneMutexedVecSPtr,
165  std::shared_ptr<MutexedVectorPointer<galaxis::lina::Vector2f>> p_rightLaneMutexedVecSPtr);
166 
167  inline void insert_lane_point(std::shared_ptr<MutexedVectorPointer<galaxis::lina::Vector2f>> p_mutVecPointerSPtr, float p_x, float p_y, Eigen::Rotation2Df const& p_rotationMat, bool p_reverseInsertion);
168 
169  std::tuple<float, float, float, float> get_lane_blocked(std::pair<DynamicPolynom, DynamicPolynom>& lanePolynom);
170 
171 public:
172  double eval_poly(DynamicPolynom p_polynom, double p_x);
173 };
174 
175 #endif
AutoPilot::m_threadPool
boost::asio::thread_pool m_threadPool
Definition: AutoPilot.hpp:65
DynamicPolynom
std::shared_ptr< std::vector< double > > DynamicPolynom
Definition: poly.hpp:16
AutoPilot::m_rightLinePolynomPointsVecSPtr
std::shared_ptr< std::vector< Vector2f > > m_rightLinePolynomPointsVecSPtr
Definition: AutoPilot.hpp:123
AutoPilot::m_centerPolyMax
double m_centerPolyMax
Definition: AutoPilot.hpp:91
galaxis_polyfit.h
AutoPilot
Definition: AutoPilot.hpp:46
DriveInformation_t::polynom
DynamicPolynom polynom
Definition: AutoPilot.hpp:25
DriveInformation_t::center
DynamicPolynom center
Definition: AutoPilot.hpp:30
AutoPilot::m_rightPolyMax
double m_rightPolyMax
Definition: AutoPilot.hpp:94
MutexedVectorPointer
This class holds a pointer onto a vector. Some of the std::vector functions are implemented for threa...
Definition: mvector.hpp:11
DriveInformation_t::rightPolyMax
double rightPolyMax
Definition: AutoPilot.hpp:34
AutoPilot::m_centerLineXYTmpVecSPtr
std::shared_ptr< std::map< int16_t, int16_t > > m_centerLineXYTmpVecSPtr
Definition: AutoPilot.hpp:70
mvector.hpp
AutoPilot::m_rightPolyMin
double m_rightPolyMin
Definition: AutoPilot.hpp:95
DriveInformation_t::leftPolyMin
double leftPolyMin
Definition: AutoPilot.hpp:29
AutoPilot::m_lastDriveInformationSPtr
std::shared_ptr< DriveInformation_t > m_lastDriveInformationSPtr
Definition: AutoPilot.hpp:57
DriveInformation_t::centerPolyMax
double centerPolyMax
Definition: AutoPilot.hpp:31
AutoPilot::m_centerLinePoly
std::shared_ptr< std::vector< double > > m_centerLinePoly
Definition: AutoPilot.hpp:93
AutoPilot::m_polynomPointsXVector
std::vector< double > m_polynomPointsXVector
Definition: AutoPilot.hpp:59
MapDataLayer
Definition: MapDataLayer.hpp:55
Decision
Definition: DecisionStateMachine.hpp:14
AutoPilot::m_centerPolyMin
double m_centerPolyMin
Definition: AutoPilot.hpp:92
AutoPilot::m_linesObject
std::shared_ptr< LinesObject< int16_t > > m_linesObject
Definition: AutoPilot.hpp:53
DriveInformation_t::rightPolyMin
double rightPolyMin
Definition: AutoPilot.hpp:35
AutoPilot::m_leftLinePolynomXVectorSPtr
std::shared_ptr< std::vector< double > > m_leftLinePolynomXVectorSPtr
Definition: AutoPilot.hpp:77
AutoPilot::m_localizer
Localizer m_localizer
Definition: AutoPilot.hpp:50
AutoPilot::m_lanePolynom
std::pair< DynamicPolynom, DynamicPolynom > m_lanePolynom
Definition: AutoPilot.hpp:55
GalaxisNode.hpp
Localizer
Definition: Localizer.hpp:93
AutoPilot::m_laneBlocked
std::tuple< float, float, float, float > m_laneBlocked
Definition: AutoPilot.hpp:86
DriveInformation_t::leftPolyMax
double leftPolyMax
Definition: AutoPilot.hpp:28
AutoPilot::m_leftLinePolynomPointsVecSPtr
std::shared_ptr< std::vector< Vector2f > > m_leftLinePolynomPointsVecSPtr
Definition: AutoPilot.hpp:122
AutoPilot::m_leftLineXYTmpVecSPtr
std::shared_ptr< std::map< int16_t, int16_t > > m_leftLineXYTmpVecSPtr
Definition: AutoPilot.hpp:69
AutoPilot::m_leftLineYXTmpVecSPtr
std::shared_ptr< std::map< int16_t, int16_t > > m_leftLineYXTmpVecSPtr
Definition: AutoPilot.hpp:72
galaxis
Definition: MapClasses.hpp:10
MapDataLayer.hpp
AutoPilot::m_rightLinePoly
std::shared_ptr< std::vector< double > > m_rightLinePoly
Definition: AutoPilot.hpp:96
DriveInformation_t::right
DynamicPolynom right
Definition: AutoPilot.hpp:33
AutoPilot::m_sharedThreadMutex
std::shared_mutex m_sharedThreadMutex
Definition: AutoPilot.hpp:66
AutoPilot::m_polynomPointsYVector
std::vector< double > m_polynomPointsYVector
Definition: AutoPilot.hpp:60
AutoPilot::m_leftLinePoly
std::shared_ptr< std::vector< double > > m_leftLinePoly
Definition: AutoPilot.hpp:90
linatypes.hpp
AutoPilot::m_leftLinePolynomYVectorSPtr
std::shared_ptr< std::vector< double > > m_leftLinePolynomYVectorSPtr
Definition: AutoPilot.hpp:78
MATH_PI_DOUBLE
constexpr double MATH_PI_DOUBLE
Definition: AutoPilot.hpp:22
DecisionStateMachine.hpp
DriveInformation_t::left
DynamicPolynom left
Definition: AutoPilot.hpp:27
DriveInformation_t::centerPolyMin
double centerPolyMin
Definition: AutoPilot.hpp:32
GalaxisNode
Definition: GalaxisNode.hpp:21
AutoPilot::m_lastTimeLaneVisible
rclcpp::Time m_lastTimeLaneVisible
Definition: AutoPilot.hpp:98
AutoPilot::m_centerLinePolynomYVectorSPtr
std::shared_ptr< std::vector< double > > m_centerLinePolynomYVectorSPtr
Definition: AutoPilot.hpp:81
DriveInformation_t::positionTimepoint
PositionTimepoint positionTimepoint
Definition: AutoPilot.hpp:40
DriveInformation_t::timeLastPolynomCalculated
rclcpp::Time timeLastPolynomCalculated
Definition: AutoPilot.hpp:41
AutoPilot::m_leftPolyMin
double m_leftPolyMin
Definition: AutoPilot.hpp:89
AutoPilot::m_gNodePtr
GalaxisNode * m_gNodePtr
Definition: AutoPilot.hpp:63
AutoPilot::m_laneCentersPairVecUPtr
std::unique_ptr< std::pair< std::vector< galaxis::lina::Vector2f >, std::vector< galaxis::lina::Vector2f > > > m_laneCentersPairVecUPtr
Definition: AutoPilot.hpp:54
AutoPilot::m_decision
Decision m_decision
Definition: AutoPilot.hpp:51
AutoPilot::m_rightLineYXTmpVecSPtr
std::shared_ptr< std::map< int16_t, int16_t > > m_rightLineYXTmpVecSPtr
Definition: AutoPilot.hpp:74
AutoPilot::m_centerLineYXTmpVecSPtr
std::shared_ptr< std::map< int16_t, int16_t > > m_centerLineYXTmpVecSPtr
Definition: AutoPilot.hpp:73
DriveInformation_t
Definition: AutoPilot.hpp:24
AutoPilot::m_centerLinePolynomXVectorSPtr
std::shared_ptr< std::vector< double > > m_centerLinePolynomXVectorSPtr
Definition: AutoPilot.hpp:80
AutoPilot::m_rightLinePolynomYVectorSPtr
std::shared_ptr< std::vector< double > > m_rightLinePolynomYVectorSPtr
Definition: AutoPilot.hpp:84
AutoPilot::m_rightLineXYTmpVecSPtr
std::shared_ptr< std::map< int16_t, int16_t > > m_rightLineXYTmpVecSPtr
Definition: AutoPilot.hpp:71
AutoPilot::m_leftPolyMax
double m_leftPolyMax
Definition: AutoPilot.hpp:88
PositionTimepoint
Definition: Localizer.hpp:19
AutoPilot::m_rightLinePolynomXVectorSPtr
std::shared_ptr< std::vector< double > > m_rightLinePolynomXVectorSPtr
Definition: AutoPilot.hpp:83
Localizer.hpp
AutoPilot::m_mapDataLayer
MapDataLayer m_mapDataLayer
Definition: AutoPilot.hpp:49
eval_poly
double eval_poly(DynamicPolynom p_polynom, double p_x)
Definition: main_test.cpp:32