|
| 1 | +// Copyright 2024, Universal Robots A/S |
| 2 | +// |
| 3 | +// Redistribution and use in source and binary forms, with or without |
| 4 | +// modification, are permitted provided that the following conditions are met: |
| 5 | +// |
| 6 | +// * Redistributions of source code must retain the above copyright |
| 7 | +// notice, this list of conditions and the following disclaimer. |
| 8 | +// |
| 9 | +// * Redistributions in binary form must reproduce the above copyright |
| 10 | +// notice, this list of conditions and the following disclaimer in the |
| 11 | +// documentation and/or other materials provided with the distribution. |
| 12 | +// |
| 13 | +// * Neither the name of the {copyright_holder} nor the names of its |
| 14 | +// contributors may be used to endorse or promote products derived from |
| 15 | +// this software without specific prior written permission. |
| 16 | +// |
| 17 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 21 | +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | +// POSSIBILITY OF SUCH DAMAGE. |
| 28 | + |
| 29 | +//---------------------------------------------------------------------- |
| 30 | +/*!\file |
| 31 | + * |
| 32 | + * \author Jacob Larsen [email protected] |
| 33 | + * \date 2024-07-11 |
| 34 | + * |
| 35 | + * |
| 36 | + * |
| 37 | + * |
| 38 | + */ |
| 39 | +//---------------------------------------------------------------------- |
| 40 | + |
| 41 | +#include <ur_controllers/ur_configuration_controller.hpp> |
| 42 | +#include <realtime_tools/realtime_box.h> |
| 43 | +namespace ur_controllers |
| 44 | +{ |
| 45 | + |
| 46 | +controller_interface::CallbackReturn URConfigurationController::on_init() |
| 47 | +{ |
| 48 | + return controller_interface::CallbackReturn::SUCCESS; |
| 49 | +} |
| 50 | + |
| 51 | +controller_interface::CallbackReturn |
| 52 | +URConfigurationController::on_configure(const rclcpp_lifecycle::State& /* previous_state */) |
| 53 | +{ |
| 54 | + param_listener_ = std::make_shared<ur_configuration_controller::ParamListener>(get_node()); |
| 55 | + params_ = param_listener_->get_params(); |
| 56 | + |
| 57 | + get_robot_software_version_srv_ = get_node()->create_service<ur_msgs::srv::GetRobotSoftwareVersion>( |
| 58 | + "~/get_robot_software_version", std::bind(&URConfigurationController::getRobotSoftwareVersion, this, |
| 59 | + std::placeholders::_1, std::placeholders::_2)); |
| 60 | + |
| 61 | + return controller_interface::CallbackReturn::SUCCESS; |
| 62 | +} |
| 63 | + |
| 64 | +controller_interface::InterfaceConfiguration URConfigurationController::command_interface_configuration() const |
| 65 | +{ |
| 66 | + // No command interfaces currently |
| 67 | + controller_interface::InterfaceConfiguration config; |
| 68 | + config.type = controller_interface::interface_configuration_type::INDIVIDUAL; |
| 69 | + |
| 70 | + return config; |
| 71 | +} |
| 72 | + |
| 73 | +controller_interface::InterfaceConfiguration URConfigurationController::state_interface_configuration() const |
| 74 | +{ |
| 75 | + controller_interface::InterfaceConfiguration config; |
| 76 | + config.type = controller_interface::interface_configuration_type::INDIVIDUAL; |
| 77 | + |
| 78 | + const std::string tf_prefix = params_.tf_prefix; |
| 79 | + |
| 80 | + config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_major"); |
| 81 | + config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_minor"); |
| 82 | + config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_build"); |
| 83 | + config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_bugfix"); |
| 84 | + |
| 85 | + return config; |
| 86 | +} |
| 87 | + |
| 88 | +controller_interface::return_type URConfigurationController::update(const rclcpp::Time& /* time */, |
| 89 | + const rclcpp::Duration& /* period */) |
| 90 | +{ |
| 91 | + return controller_interface::return_type::OK; |
| 92 | +} |
| 93 | + |
| 94 | +controller_interface::CallbackReturn |
| 95 | +URConfigurationController::on_activate(const rclcpp_lifecycle::State& /* previous_state */) |
| 96 | +{ |
| 97 | + robot_software_version_.set([this](const std::shared_ptr<VersionInformation> ptr) { |
| 98 | + ptr->major = state_interfaces_[StateInterfaces::ROBOT_VERSION_MAJOR].get_value(); |
| 99 | + ptr->minor = state_interfaces_[StateInterfaces::ROBOT_VERSION_MINOR].get_value(); |
| 100 | + ptr->build = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUILD].get_value(); |
| 101 | + ptr->bugfix = state_interfaces_[StateInterfaces::ROBOT_VERSION_BUGFIX].get_value(); |
| 102 | + }); |
| 103 | + return controller_interface::CallbackReturn::SUCCESS; |
| 104 | +} |
| 105 | + |
| 106 | +controller_interface::CallbackReturn |
| 107 | +URConfigurationController::on_deactivate(const rclcpp_lifecycle::State& /* previous_state */) |
| 108 | +{ |
| 109 | + return controller_interface::CallbackReturn::SUCCESS; |
| 110 | +} |
| 111 | + |
| 112 | +bool URConfigurationController::getRobotSoftwareVersion( |
| 113 | + ur_msgs::srv::GetRobotSoftwareVersion::Request::SharedPtr /*req*/, |
| 114 | + ur_msgs::srv::GetRobotSoftwareVersion::Response::SharedPtr resp) |
| 115 | +{ |
| 116 | + std::shared_ptr<VersionInformation> temp; |
| 117 | + return robot_software_version_.tryGet([resp](const std::shared_ptr<VersionInformation> ptr) { |
| 118 | + resp->major = ptr->major; |
| 119 | + resp->minor = ptr->minor; |
| 120 | + resp->build = ptr->build; |
| 121 | + resp->bugfix = ptr->bugfix; |
| 122 | + }); |
| 123 | +} |
| 124 | +} // namespace ur_controllers |
| 125 | + |
| 126 | +#include "pluginlib/class_list_macros.hpp" |
| 127 | + |
| 128 | +PLUGINLIB_EXPORT_CLASS(ur_controllers::URConfigurationController, controller_interface::ControllerInterface) |
0 commit comments