@@ -96,8 +96,8 @@ class PointPublisher : public rclcpp::Node
9696 }
9797
9898private:
99- rclcpp::Publisher<geometry_msgs::msg::Point>::SharedPtr publisher_; // !< The publisher
100- double frequency_{10.0 }; // !< The publish rate frequency
99+ rclcpp::Publisher<geometry_msgs::msg::Point>::SharedPtr publisher_; // !< The publisher
100+ double frequency_{10.0 }; // !< The publish rate frequency
101101};
102102
103103/* *
@@ -127,7 +127,7 @@ class PointSensorModel : public rclcpp::Node
127127 subscription_ = this ->create_subscription <geometry_msgs::msg::Point>(
128128 " point" , 10 ,
129129 std::bind (
130- &PointThrottledCallback::callback<const geometry_msgs::msg::Point::ConstSharedPtr &>,
130+ &PointThrottledCallback::callback<const geometry_msgs::msg::Point &>,
131131 &throttled_callback_, std::placeholders::_1)
132132 );
133133 }
@@ -167,7 +167,7 @@ class PointSensorModel : public rclcpp::Node
167167 *
168168 * @return The last message kept. It would be nullptr if no message has been kept so far
169169 */
170- const geometry_msgs::msg::Point::ConstSharedPtr getLastKeptMessage () const
170+ const geometry_msgs::msg::Point::SharedPtr getLastKeptMessage () const
171171 {
172172 return last_kept_message_;
173173 }
@@ -179,19 +179,26 @@ class PointSensorModel : public rclcpp::Node
179179 *
180180 * @param[in] msg A geometry_msgs::msg::Point message
181181 */
182- void keepCallback (const geometry_msgs::msg::Point::ConstSharedPtr & msg)
182+ void keepCallback (const geometry_msgs::msg::Point & msg)
183183 {
184184 ++kept_messages_;
185- last_kept_message_ = std::move (msg);
185+
186+ if (!last_kept_message_) {
187+ last_kept_message_ = std::make_shared<geometry_msgs::msg::Point>();
188+ }
189+
190+ last_kept_message_->x = msg.x ;
191+ last_kept_message_->y = msg.y ;
192+ last_kept_message_->z = msg.z ;
186193 }
187194
188195 /* *
189196 * @brief Drop callback, that counts the number of times it has been called
190197 *
191198 * @param[in] msg A geometry_msgs::msg::Point message (not used)
192199 */
193- // NOTE(CH3): The ConstSharedPtr here is necessary to allow binding the throttled callback
194- void dropCallback (const geometry_msgs::msg::Point::ConstSharedPtr & /* msg*/ )
200+ // NOTE(CH3): The msg arg here is necessary to allow binding the throttled callback
201+ void dropCallback (const geometry_msgs::msg::Point & /* msg*/ )
195202 {
196203 ++dropped_messages_;
197204 }
@@ -203,7 +210,9 @@ class PointSensorModel : public rclcpp::Node
203210
204211 size_t kept_messages_{0 }; // !< Messages kept
205212 size_t dropped_messages_{0 }; // !< Messages dropped
206- geometry_msgs::msg::Point::ConstSharedPtr last_kept_message_; // !< The last message kept
213+
214+ // We use a SharedPtr to check for nullptr just for this test
215+ geometry_msgs::msg::Point::SharedPtr last_kept_message_; // !< The last message kept
207216};
208217
209218class TestThrottledCallback : public ::testing::Test
0 commit comments