From: Walter Fetter Lages Date: Thu, 10 Sep 2026 03:35:53 +0000 (-0300) Subject: Replace RealtimeBuffer with RealtimeThreadSafeBox. X-Git-Url: http://git.ece.ufrgs.br/?a=commitdiff_plain;ds=inline;p=pid_plus_gravity_controller.git Replace RealtimeBuffer with RealtimeThreadSafeBox. --- diff --git a/include/pid_plus_gravity_controller/pid_plus_gravity_controller.hpp b/include/pid_plus_gravity_controller/pid_plus_gravity_controller.hpp index c61223e..f585acc 100644 --- a/include/pid_plus_gravity_controller/pid_plus_gravity_controller.hpp +++ b/include/pid_plus_gravity_controller/pid_plus_gravity_controller.hpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include @@ -44,6 +44,7 @@ namespace pid_plus_gravity_controller unsigned int nJoints_; rclcpp::Subscription::SharedPtr sub_command_; + realtime_tools::RealtimeThreadSafeBox referencePoint_; std::string robotDescription_; KDL::Chain chain_; @@ -54,8 +55,6 @@ namespace pid_plus_gravity_controller KDL::JntArray gravity_; std::vector> pid_; - - 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/pid_plus_gravity_controller.cpp b/src/pid_plus_gravity_controller.cpp index 158f500..ed5dd7b 100644 --- a/src/pid_plus_gravity_controller.cpp +++ b/src/pid_plus_gravity_controller.cpp @@ -29,7 +29,7 @@ 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) { - 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)); @@ -203,7 +203,7 @@ namespace pid_plus_gravity_controller 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) @@ -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