#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>
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_;
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);
namespace pid_plus_gravity_controller
{
PidPlusGravityController::PidPlusGravityController(void):
- q_(0),qr_(0),gravity_(0),referencePoint_(nullptr)
+ q_(0),qr_(0),gravity_(0)
{
}
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));
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)
}
}
-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