Galaxis Codebase  1.0.0
Team Galaxis software stack for the Carolo Cup 2023 - ROS2 based software
MapDataLayer.hpp
Go to the documentation of this file.
1 #ifndef MAP_DATA_LAYER_HPP_SIMULATION
2 #define MAP_DATA_LAYER_HPP_SIMULATION
3 
4 #include <map>
5 #include <unordered_map>
6 #include <array>
7 #include <memory>
8 #include <mutex>
9 
10 #include <galaxis/linatypes.hpp>
11 #include <galaxis/messages.hpp>
13 #include <visualization_msgs/msg/marker.hpp>
14 #include <geometry_msgs/msg/point.hpp>
15 
16 #include "MapClasses.hpp"
17 
18 // ThreadPool: https://www.boost.org/doc/libs/1_74_0/doc/html/boost_asio/reference/thread_pool.html
19 #include <boost/asio.hpp>
20 #include <boost/asio/thread_pool.hpp>
21 
22 using namespace galaxis::lina;
23 using namespace galaxis::map::data;
24 
25 struct MapCell {
26  bool leftLine = false;
27  bool centerLine = false;
28  bool rightLine = false;
29 };
30 
31 constexpr int MAP_SIZE = 20000; // 20 x 20m with cell size of 1cm^2
32 
33 class MapDataLayer {
34  typedef std::array<MapCell, MAP_SIZE> ColumnMapArray;
35  typedef std::array<ColumnMapArray, MAP_SIZE> MapArray;
36 
37 private:
38  int m_amountOfThreads;
39  boost::asio::thread_pool m_threadPool;
40 
41  MapArray m_data; // [X][Y] // (0,0) - (left,bottom)
42  Vector2f m_mapSize;
43  std::mutex m_mapMutex;
44 
45  Vector2f m_absoluteCarPositionOffset;
46 
47  geometry_msgs::msg::Point m_lastPointLeftLane;
48  bool m_lastPointLeftLaneUsable = false;
49  geometry_msgs::msg::Point m_lastPointCenterLane;
50  bool m_lastPointCenterLaneUsable = false;
51  geometry_msgs::msg::Point m_lastPointRightLane;
52  bool m_lastPointRightLaneUsable = false;
53 
54  std::shared_ptr<LinesObject<int16_t>> m_linesObjectSPtr;
55 
56 public:
57  MapDataLayer();
58  MapDataLayer(int amountOfThreads);
59  ~MapDataLayer();
60  void init();
61  void clear();
62 
63  void updateMap(visualization_msgs::msg::Marker::SharedPtr laneDetectionSPtr, char laneType);
64  std::shared_ptr<LinesObject<int16_t>> getLineObject(Vector2f absolutePositionCM, float absoluteOrientation, Vector2i windowSize, Vector2i& effectiveWindowSize);
65 
66 private:
67  void updateCell(Vector2i position, char laneType);
68  void iterateThroughMap(int arrayStartX, int arrayEndX, int arrayStartY, int arrayEndY, Vector2i const& absoluteCarPosition);
69 };
70 
71 #endif // MAP_DATA_LAYER_HPP_SIMULATION
MapDataLayer::m_lastPointCenterLane
geometry_msgs::msg::Point m_lastPointCenterLane
Definition: MapDataLayer.hpp:49
MapClasses.hpp
MapDataLayer
Definition: MapDataLayer.hpp:55
galaxis::lina
Definition: linatypes.hpp:11
MapDataLayer::m_lastPointRightLane
geometry_msgs::msg::Point m_lastPointRightLane
Definition: MapDataLayer.hpp:51
MapDataLayer::MapArray
std::array< ColumnMapArray, MAP_SIZE > MapArray
Definition: MapDataLayer.hpp:35
MapCell
Definition: MapDataLayer.hpp:45
MAP_SIZE
constexpr int MAP_SIZE
Definition: MapDataLayer.hpp:53
galaxis::lina::Vector2f
Eigen::Vector2f Vector2f
Definition: linatypes.hpp:14
linatypes.hpp
MapDataLayer::m_lastPointLeftLane
geometry_msgs::msg::Point m_lastPointLeftLane
Definition: MapDataLayer.hpp:47
galaxis::map::data
Definition: MapClasses.hpp:11
MapDataLayer::ColumnMapArray
std::array< MapCell, MAP_SIZE > ColumnMapArray
Definition: MapDataLayer.hpp:34
galaxis::lina::Vector2i
Eigen::Vector2i Vector2i
Definition: linatypes.hpp:13
AutopilotSettings.hpp
messages.hpp