Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class URConfigurationController : public controller_interface::ControllerInterfa
realtime_tools::RealtimeBox<std::shared_ptr<VersionInformation>> robot_software_version_{
std::make_shared<VersionInformation>()
};
std::atomic<bool> robot_software_version_set_{ false };

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

Expand Down
20 changes: 13 additions & 7 deletions ur_controllers/src/ur_configuration_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,21 @@ controller_interface::InterfaceConfiguration URConfigurationController::state_in
controller_interface::return_type URConfigurationController::update(const rclcpp::Time& /* time */,
const rclcpp::Duration& /* period */)
{
if (!robot_software_version_set_) {
robot_software_version_set_ =
robot_software_version_.try_set([this](const std::shared_ptr<VersionInformation>& ptr) {
ptr->major = state_interfaces_[StateInterfaces::ROBOT_VERSION_MAJOR].get_optional().value_or(0.0);
ptr->minor = state_interfaces_[StateInterfaces::ROBOT_VERSION_MINOR].get_optional().value_or(0.0);
ptr->build = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUILD].get_optional().value_or(0.0);
ptr->bugfix = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUGFIX].get_optional().value_or(0.0);
});
}
return controller_interface::return_type::OK;
}

controller_interface::CallbackReturn
URConfigurationController::on_activate(const rclcpp_lifecycle::State& /* previous_state */)
{
robot_software_version_.set([this](const std::shared_ptr<VersionInformation> ptr) {
ptr->major = state_interfaces_[StateInterfaces::ROBOT_VERSION_MAJOR].get_optional().value_or(0.0);
ptr->minor = state_interfaces_[StateInterfaces::ROBOT_VERSION_MINOR].get_optional().value_or(0.0);
ptr->build = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUILD].get_optional().value_or(0.0);
ptr->bugfix = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUGFIX].get_optional().value_or(0.0);
});
return controller_interface::CallbackReturn::SUCCESS;
}

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