From: Walter Fetter Lages Date: Thu, 10 Sep 2026 03:26:04 +0000 (-0300) Subject: Replace RealtimeBuffer with RealtimeThreadSafeBox. X-Git-Url: http://git.ece.ufrgs.br/?a=commitdiff_plain;h=HEAD;p=computed_torque_controller.git Replace RealtimeBuffer with RealtimeThreadSafeBox. --- diff --git a/include/computed_torque_controller/computed_torque_controller.hpp b/include/computed_torque_controller/computed_torque_controller.hpp index 234c723..1f03eaf 100644 --- a/include/computed_torque_controller/computed_torque_controller.hpp +++ b/include/computed_torque_controller/computed_torque_controller.hpp @@ -30,7 +30,7 @@ #include #include -#include +#include #include @@ -42,6 +42,7 @@ namespace computed_torque_controller unsigned int nJoints_; rclcpp::Subscription::SharedPtr sub_command_; + realtime_tools::RealtimeThreadSafeBox referencePoint_; std::string robotDescription_; KDL::Chain chain_; @@ -62,8 +63,6 @@ namespace computed_torque_controller Eigen::MatrixXd Kp_; Eigen::MatrixXd Kd_; - realtime_tools::RealtimeBuffer> referencePoint_; - void commandCB(const trajectory_msgs::msg::JointTrajectoryPoint::SharedPtr referencePoint); void robotDescriptionCB(const std_msgs::msg::String::SharedPtr robotDescription); diff --git a/src/computed_torque_controller.cpp b/src/computed_torque_controller.cpp index 86001ec..13a6173 100644 --- a/src/computed_torque_controller.cpp +++ b/src/computed_torque_controller.cpp @@ -29,7 +29,7 @@ namespace computed_torque_controller { ComputedTorqueController::ComputedTorqueController(void): - q_(0),dq_(0),v_(0),qr_(0),dqr_(0),ddqr_(0),torque_(0),fext_(0),referencePoint_(nullptr) + q_(0),dq_(0),v_(0),qr_(0),dqr_(0),ddqr_(0),torque_(0),fext_(0) { } @@ -201,17 +201,17 @@ namespace computed_torque_controller controller_interface::return_type ComputedTorqueController::update(const rclcpp::Time &/*time*/,const rclcpp::Duration &/*period*/) { - auto referencePoint=referencePoint_.readFromRT(); - if(referencePoint && *referencePoint) + auto referencePoint=referencePoint_.try_get(); + if(referencePoint.has_value()) { - if((*referencePoint)->positions.size() == nJoints_) - qr_.data=Eigen::VectorXd::Map((*referencePoint)->positions.data(),nJoints_); + if(referencePoint.value().positions.size() == nJoints_) + qr_.data=Eigen::VectorXd::Map(referencePoint.value().positions.data(),nJoints_); - if((*referencePoint)->velocities.size() == nJoints_) - dqr_.data=Eigen::VectorXd::Map((*referencePoint)->velocities.data(),nJoints_); + if(referencePoint.value().velocities.size() == nJoints_) + dqr_.data=Eigen::VectorXd::Map(referencePoint.value().velocities.data(),nJoints_); - if((*referencePoint)->accelerations.size() == nJoints_) - ddqr_.data=Eigen::VectorXd::Map((*referencePoint)->accelerations.data(),nJoints_); + if(referencePoint.value().accelerations.size() == nJoints_) + ddqr_.data=Eigen::VectorXd::Map(referencePoint.value().accelerations.data(),nJoints_); } for(unsigned int i=0;i < nJoints_;i++) @@ -234,7 +234,7 @@ namespace computed_torque_controller void ComputedTorqueController::commandCB(const trajectory_msgs::msg::JointTrajectoryPoint::SharedPtr referencePoint) { - referencePoint_.writeFromNonRT(referencePoint); + referencePoint_.set(*referencePoint); } void ComputedTorqueController::robotDescriptionCB(const std_msgs::msg::String::SharedPtr robotDescription)