Skip to content

Commit de22d32

Browse files
authored
ur_configuration_controller: use try_set on RTBox (#1470)
* ur_configuration_controller: use try_set on RTBox Using set could potentially block the RT thread. * Remove temp variable
1 parent 63ca679 commit de22d32

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

ur_controllers/include/ur_controllers/ur_configuration_controller.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class URConfigurationController : public controller_interface::ControllerInterfa
8888
realtime_tools::RealtimeBox<std::shared_ptr<VersionInformation>> robot_software_version_{
8989
std::make_shared<VersionInformation>()
9090
};
91+
std::atomic<bool> robot_software_version_set_{ false };
9192

9293
rclcpp::Service<ur_msgs::srv::GetRobotSoftwareVersion>::SharedPtr get_robot_software_version_srv_;
9394

ur_controllers/src/ur_configuration_controller.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,21 @@ controller_interface::InterfaceConfiguration URConfigurationController::state_in
8888
controller_interface::return_type URConfigurationController::update(const rclcpp::Time& /* time */,
8989
const rclcpp::Duration& /* period */)
9090
{
91+
if (!robot_software_version_set_) {
92+
robot_software_version_set_ =
93+
robot_software_version_.try_set([this](const std::shared_ptr<VersionInformation>& ptr) {
94+
ptr->major = state_interfaces_[StateInterfaces::ROBOT_VERSION_MAJOR].get_optional().value_or(0.0);
95+
ptr->minor = state_interfaces_[StateInterfaces::ROBOT_VERSION_MINOR].get_optional().value_or(0.0);
96+
ptr->build = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUILD].get_optional().value_or(0.0);
97+
ptr->bugfix = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUGFIX].get_optional().value_or(0.0);
98+
});
99+
}
91100
return controller_interface::return_type::OK;
92101
}
93102

94103
controller_interface::CallbackReturn
95104
URConfigurationController::on_activate(const rclcpp_lifecycle::State& /* previous_state */)
96105
{
97-
robot_software_version_.set([this](const std::shared_ptr<VersionInformation> ptr) {
98-
ptr->major = state_interfaces_[StateInterfaces::ROBOT_VERSION_MAJOR].get_optional().value_or(0.0);
99-
ptr->minor = state_interfaces_[StateInterfaces::ROBOT_VERSION_MINOR].get_optional().value_or(0.0);
100-
ptr->build = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUILD].get_optional().value_or(0.0);
101-
ptr->bugfix = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUGFIX].get_optional().value_or(0.0);
102-
});
103106
return controller_interface::CallbackReturn::SUCCESS;
104107
}
105108

@@ -113,7 +116,10 @@ bool URConfigurationController::getRobotSoftwareVersion(
113116
ur_msgs::srv::GetRobotSoftwareVersion::Request::SharedPtr /*req*/,
114117
ur_msgs::srv::GetRobotSoftwareVersion::Response::SharedPtr resp)
115118
{
116-
std::shared_ptr<VersionInformation> temp;
119+
if (!robot_software_version_set_) {
120+
RCLCPP_WARN(get_node()->get_logger(), "Robot software version not set yet.");
121+
return false;
122+
}
117123
return robot_software_version_.try_get([resp](const std::shared_ptr<VersionInformation> ptr) {
118124
resp->major = ptr->major;
119125
resp->minor = ptr->minor;

0 commit comments

Comments
 (0)