@@ -30,51 +30,42 @@ LandmarkServerNode::LandmarkServerNode(const rclcpp::NodeOptions& options)
3030
3131}
3232
33- void  LandmarkServerNode::landmarksRecievedCallback  (
33+ void  LandmarkServerNode::landmarksReceivedCallback  (
3434    const  vortex_msgs::msg::LandmarkArray::SharedPtr msg)
3535{
36-     if  (!storedLandmarks_) {
37-         storedLandmarks_ = std::make_shared<vortex_msgs::msg::LandmarkArray>();
38-     }
36+     std::lock_guard<std::mutex> lock (storedLandmarksMutex_);
3937
40-     for  (const   auto  &new_landmark  : msg->landmarks )
38+     for  (auto  &landmark  : msg->landmarks )
4139    {
42-         vortex_msgs::msg::Landmark  landmark_with_id = new_landmark ;
40+         auto  landmark_with_id = landmark ;
4341
44-        // Filtrering function that assigns an  ID to the landmarkArray,  logic not implemented yet
45-         uint32_t  id = assignID (landmark_with_id);   
42+          //  Assign unique  ID ( logic not implemented yet) 
43+         uint32_t  id = assignID (landmark_with_id);
4644        landmark_with_id.id  = id;
4745
48-         //  Check if the ID is already stored, in that case just update position
49-         bool  found = false ;
50-         for  (auto  &stored : storedLandmarks_->landmarks )
51-         {
52-             if  (stored.id  == id)
53-             {
54-                 
55-                 stored.pose  = landmark_with_id.pose ;
56-                 found = true ;
57-                 RCLCPP_INFO (this ->get_logger (),
58-                             " Updated landmark #%u (type=%u, subtype=%u)" 
59-                             id,
60-                             landmark_with_id.type ,
61-                             landmark_with_id.subtype );
62-                 break ;
63-             }
64-         }
46+         //  Check if already stored
47+         auto  it = std::find_if (
48+             storedLandmarks_->landmarks .begin (),
49+             storedLandmarks_->landmarks .end (),
50+             [id](const  auto  &stored) { return  stored.id  == id; });
51+ 
52+         if  (it != storedLandmarks_->landmarks .end ()) {
53+             it->pose  = landmark_with_id.pose ;
54+             RCLCPP_INFO (this ->get_logger (),
55+                         " Updated landmark #%u (type=%u, subtype=%u)" 
56+                         id, landmark_with_id.type , landmark_with_id.subtype );
6557
66-          // If the ID is new 
67-          if  (!found) 
68-         {
58+ 
59+ 
60+         }  else   {
6961            storedLandmarks_->landmarks .push_back (landmark_with_id);
7062            RCLCPP_INFO (this ->get_logger (),
7163                        " Added new landmark #%u (type=%u, subtype=%u)" 
72-                         id,
73-                         landmark_with_id.type ,
74-                         landmark_with_id.subtype );
64+                         id, landmark_with_id.type , landmark_with_id.subtype );
7565        }
7666    }
7767
68+     
7869    RCLCPP_INFO (this ->get_logger (),
7970                " Total stored landmarks: %zu" 
8071                storedLandmarks_->landmarks .size ());
@@ -83,6 +74,7 @@ void LandmarkServerNode::landmarksRecievedCallback(
8374
8475
8576
77+ 
8678void  LandmarkServerNode::publishStoredLandmarks ()
8779{
8880    if  (!storedLandmarks_ || storedLandmarks_->landmarks .empty ()) {
0 commit comments