@@ -88,18 +88,21 @@ controller_interface::InterfaceConfiguration URConfigurationController::state_in
8888controller_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
94103controller_interface::CallbackReturn
95104URConfigurationController::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