Replace RealtimeBuffer with RealtimeThreadSafeBox. lyrical
authorWalter Fetter Lages <w.fetter@ieee.org>
Thu, 10 Sep 2026 03:35:53 +0000 (00:35 -0300)
committerWalter Fetter Lages <w.fetter@ieee.org>
Thu, 10 Sep 2026 03:35:53 +0000 (00:35 -0300)
include/pid_plus_gravity_controller/pid_plus_gravity_controller.hpp
src/pid_plus_gravity_controller.cpp

index c61223e..f585acc 100644 (file)
@@ -32,7 +32,7 @@
 #include <kdl_parser/kdl_parser.hpp>
 #include <kdl/chaindynparam.hpp>
 
 #include <kdl_parser/kdl_parser.hpp>
 #include <kdl/chaindynparam.hpp>
 
-#include <realtime_tools/realtime_buffer.hpp>
+#include <realtime_tools/realtime_thread_safe_box.hpp>
 
 #include <pid_plus_gravity_controller/visibility_control.h>
 
 
 #include <pid_plus_gravity_controller/visibility_control.h>
 
@@ -44,6 +44,7 @@ namespace pid_plus_gravity_controller
                unsigned int nJoints_;
 
                rclcpp::Subscription<trajectory_msgs::msg::JointTrajectoryPoint>::SharedPtr sub_command_;
                unsigned int nJoints_;
 
                rclcpp::Subscription<trajectory_msgs::msg::JointTrajectoryPoint>::SharedPtr sub_command_;
+               realtime_tools::RealtimeThreadSafeBox<trajectory_msgs::msg::JointTrajectoryPoint> referencePoint_;
                
                std::string robotDescription_;          
                KDL::Chain chain_;
                
                std::string robotDescription_;          
                KDL::Chain chain_;
@@ -54,8 +55,6 @@ namespace pid_plus_gravity_controller
                KDL::JntArray gravity_;
                
                std::vector<std::shared_ptr<control_toolbox::PidROS>> pid_;
                KDL::JntArray gravity_;
                
                std::vector<std::shared_ptr<control_toolbox::PidROS>> pid_;
-               
-               realtime_tools::RealtimeBuffer<std::shared_ptr<trajectory_msgs::msg::JointTrajectoryPoint>> referencePoint_;
 
                void commandCB(const trajectory_msgs::msg::JointTrajectoryPoint::SharedPtr referencePoint);
                void robotDescriptionCB(const std_msgs::msg::String::SharedPtr robotDescription);               
 
                void commandCB(const trajectory_msgs::msg::JointTrajectoryPoint::SharedPtr referencePoint);
                void robotDescriptionCB(const std_msgs::msg::String::SharedPtr robotDescription);               
index 158f500..ed5dd7b 100644 (file)
@@ -29,7 +29,7 @@
 namespace pid_plus_gravity_controller
 {      
        PidPlusGravityController::PidPlusGravityController(void):
 namespace pid_plus_gravity_controller
 {      
        PidPlusGravityController::PidPlusGravityController(void):
-               q_(0),qr_(0),gravity_(0),referencePoint_(nullptr)
+               q_(0),qr_(0),gravity_(0)
        {
        }
 
        {
        }
 
@@ -183,10 +183,10 @@ namespace pid_plus_gravity_controller
 
        controller_interface::return_type PidPlusGravityController::update(const rclcpp::Time &/*time*/,const rclcpp::Duration & period)
        {
 
        controller_interface::return_type PidPlusGravityController::update(const rclcpp::Time &/*time*/,const rclcpp::Duration & period)
        {
-               auto referencePoint=referencePoint_.readFromRT();
-               if(referencePoint && *referencePoint)
-                       if((*referencePoint)->positions.size() == nJoints_)
-                               qr_.data=Eigen::VectorXd::Map((*referencePoint)->positions.data(),nJoints_);
+               auto referencePoint=referencePoint_.try_get();
+               if(referencePoint.has_value())
+                       if(referencePoint.value().positions.size() == nJoints_)
+                               qr_.data=Eigen::VectorXd::Map(referencePoint.value().positions.data(),nJoints_);
 
                for(unsigned int i=0;i < nJoints_;i++)
                        q_(i)=state_interfaces_[i].get_optional().value_or(q_(i));
 
                for(unsigned int i=0;i < nJoints_;i++)
                        q_(i)=state_interfaces_[i].get_optional().value_or(q_(i));
@@ -203,7 +203,7 @@ namespace pid_plus_gravity_controller
 
        void PidPlusGravityController::commandCB(const trajectory_msgs::msg::JointTrajectoryPoint::SharedPtr referencePoint)
        {
 
        void PidPlusGravityController::commandCB(const trajectory_msgs::msg::JointTrajectoryPoint::SharedPtr referencePoint)
        {
-               referencePoint_.writeFromNonRT(referencePoint);
+               referencePoint_.set(*referencePoint);
        }
 
        void PidPlusGravityController::robotDescriptionCB(const std_msgs::msg::String::SharedPtr robotDescription)
        }
 
        void PidPlusGravityController::robotDescriptionCB(const std_msgs::msg::String::SharedPtr robotDescription)
@@ -212,4 +212,4 @@ namespace pid_plus_gravity_controller
        }
 }
 
        }
 }
 
-PLUGINLIB_EXPORT_CLASS(pid_plus_gravity_controller::PidPlusGravityController,controller_interface::ControllerInterface)
+PLUGINLIB_EXPORT_CLASS(pid_plus_gravity_controller::PidPlusGravityController,controller_interface::ControllerInterface)
\ No newline at end of file