1+ #ifndef  LANDMARK_SERVER_HPP
2+ #define  LANDMARK_SERVER_HPP 
3+ 
4+ #include  < rclcpp/rclcpp.hpp> 
5+ #include  < rclcpp_action/rclcpp_action.hpp> 
6+ #include  < sstream> 
7+ #include  < thread> 
8+ 
9+ #include  < geometry_msgs/msg/pose_array.hpp> 
10+ #include  < vortex_msgs/action/filtered_landmarks.hpp> 
11+ #include  < vortex_msgs/msg/landmark.hpp> 
12+ #include  < vortex_msgs/msg/landmark_array.hpp> 
13+ #include  < vortex_msgs/msg/odometry_array.hpp> 
14+ 
15+ #include  < tf2_ros/buffer.h> 
16+ #include  < tf2_ros/transform_listener.h> 
17+ 
18+ #include  < tf2/transform_datatypes.h> 
19+ #include  < tf2_geometry_msgs/tf2_geometry_msgs.hpp> 
20+ 
21+ namespace  landmark_server  {
22+ 
23+ /* *
24+  * @class LandmarkServerNode 
25+  * @brief A class representing a node for handling landmarks in a ROS 2 system. 
26+  * 
27+  * This class inherits from rclcpp::Node and provides functionality for 
28+  * receiving landmark array messages, publishing the poses of the landmarks, 
29+  * handling filtered landmarks using an action server, and calculating the 
30+  * distance between the poses and the drone. 
31+  */  
32+ class  LandmarkServerNode  : public  rclcpp ::Node {
33+    public: 
34+     /* *
35+      * @brief Constructor for the LandmarkServerNode class. 
36+      * 
37+      * @param options The options for configuring the node. 
38+      */  
39+     explicit  LandmarkServerNode (
40+         const  rclcpp::NodeOptions& options = rclcpp::NodeOptions());
41+ 
42+     /* *
43+      * @brief Destructor for the LandmarkServerNode class. 
44+      */  
45+     ~LandmarkServerNode () {};
46+ 
47+    protected: 
48+     /* *
49+      * @brief A shared pointer to a subscription object for receiving 
50+      * vortex_msgs::msg::LandmarkArray messages. 
51+      */  
52+     rclcpp::Subscription<vortex_msgs::msg::LandmarkArray>::SharedPtr
53+         landmark_sub_;
54+ 
55+     /* *
56+      * @brief Callback function for receiving landmark array messages. 
57+      * 
58+      * This function is called when a landmark array message of type 
59+      * vortex_msgs::msg::LandmarkArray::SharedPtr is received. 
60+      * 
61+      * @param msg The shared pointer to the received landmark array message. 
62+      */  
63+     void  landmarksRecievedCallback (
64+         const  vortex_msgs::msg::LandmarkArray::SharedPtr msg);
65+ 
66+     /* *
67+      * @brief A shared pointer to a publisher for the LandmarkArray message 
68+      * type. Publishes all landmarks currently stored in the server. 
69+      */  
70+     rclcpp::Publisher<vortex_msgs::msg::LandmarkArray>::SharedPtr
71+         landmarkPublisher_;
72+ 
73+     /* *
74+      * @brief A shared pointer to a publisher for geometry_msgs::msg::PoseArray. 
75+      * Publishes the pose of all landmarks currently stored in the server. 
76+      */  
77+     rclcpp::Publisher<geometry_msgs::msg::PoseArray>::SharedPtr posePublisher_;
78+ 
79+     /* *
80+      * @brief A shared pointer to a LandmarkArray message. 
81+      * The array contains all landmarks currently stored by the server. 
82+      */  
83+     std::shared_ptr<vortex_msgs::msg::LandmarkArray> storedLandmarks_;
84+ 
85+     /* *
86+      * @brief A shared pointer to an rclcpp_action server for handling filtered 
87+      * landmarks. 
88+      */  
89+     rclcpp_action::Server<vortex_msgs::action::FilteredLandmarks>::SharedPtr
90+         action_server_;
91+ 
92+     /* *
93+      * @brief Handles the goal request for the `handle_goal` function. 
94+      * 
95+      * This function is responsible for processing the goal request for the 
96+      * `handle_goal` action. 
97+      * 
98+      * @param uuid The unique identifier of the goal request. 
99+      * @param goal A shared pointer to the goal message containing the requested 
100+      * goal. 
101+      * @return The response to the goal request. 
102+      */  
103+     rclcpp_action::GoalResponse handle_goal (
104+         const  rclcpp_action::GoalUUID& uuid,
105+         std::shared_ptr<const  vortex_msgs::action::FilteredLandmarks::Goal>
106+             goal);
107+ 
108+     /* *
109+      * @brief Handles the cancellation of a goal. 
110+      * 
111+      * This function is called when a goal is cancelled by the client. 
112+      * 
113+      * @param goal_handle The goal handle associated with the cancelled goal. 
114+      * @return The response indicating the result of the cancellation. 
115+      */  
116+     rclcpp_action::CancelResponse handle_cancel (
117+         const  std::shared_ptr<rclcpp_action::ServerGoalHandle<
118+             vortex_msgs::action::FilteredLandmarks>> goal_handle);
119+ 
120+     /* *
121+      * @brief Handles the accepted goal for the FilteredLandmarks action server. 
122+      * 
123+      * This function is called when a goal is accepted by the action server. 
124+      * 
125+      * @param goal_handle The goal handle for the accepted goal. 
126+      */  
127+     void  handle_accepted (
128+         const  std::shared_ptr<rclcpp_action::ServerGoalHandle<
129+             vortex_msgs::action::FilteredLandmarks>> goal_handle);
130+ 
131+     /* *
132+      * @brief Executes the action server goal handle for the FilteredLandmarks 
133+      * action. 
134+      * 
135+      * @param goal_handle The goal handle for the FilteredLandmarks action. 
136+      */  
137+     void  execute (const  std::shared_ptr<rclcpp_action::ServerGoalHandle<
138+                      vortex_msgs::action::FilteredLandmarks>> goal_handle);
139+ 
140+     /* *
141+      * @brief Logs messages based on request. 
142+      * 
143+      * This function is responsible for logging messages based on the request 
144+      * 
145+      * @param goal_handle A shared pointer to the goal handle. 
146+      */  
147+     void  requestLogger (
148+         const  std::shared_ptr<rclcpp_action::ServerGoalHandle<
149+             vortex_msgs::action::FilteredLandmarks>> goal_handle);
150+ 
151+     /* *
152+      * Calculates the distance between a landmark and the drone. 
153+      * 
154+      * @param point The point to calculate the distance from. 
155+      * @param header The header to calculate the distance to. 
156+      * @return The distance between the landmark and the drone. 
157+      */  
158+     double  calculateDistance (const  geometry_msgs::msg::Point& point,
159+                              const  std_msgs::msg::Header& header);
160+ 
161+     /* *
162+      * @brief Creates a pose array from a landmark array. 
163+      * @param landmarks The landmark array. 
164+      * @return The pose array. 
165+      */  
166+     geometry_msgs::msg::PoseArray poseArrayCreater (
167+         vortex_msgs::msg::LandmarkArray landmarks);
168+ 
169+     //  Declare tf_buffer_ and tf_listener_ as class members
170+     std::shared_ptr<tf2_ros::Buffer> tf2_buffer_;
171+     std::shared_ptr<tf2_ros::TransformListener> tf2_listener_;
172+ 
173+     vortex_msgs::msg::OdometryArray filterLandmarks (
174+         const  std::shared_ptr<rclcpp_action::ServerGoalHandle<
175+             vortex_msgs::action::FilteredLandmarks>> goal_handle);
176+ 
177+ private: 
178+     rclcpp::TimerBase::SharedPtr timer_;
179+ 
180+     void  publishStoredLandmarks ();
181+ };
182+ 
183+ }  //  namespace landmark_server
184+ 
185+ #endif   //  LANDMARK_SERVER_HPP
0 commit comments