Skip to content

Commit

Permalink
Create new URConfigurationController
Browse files Browse the repository at this point in the history
And moved the get_robot_software_version service in to it.
  • Loading branch information
URJala committed Jul 11, 2024
1 parent bac64ae commit 2d70a9b
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 315 deletions.
9 changes: 8 additions & 1 deletion ur_controllers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ generate_parameter_library(
src/scaled_joint_trajectory_controller_parameters.yaml
)

generate_parameter_library(
ur_configuration_controller_parameters
src/ur_configuration_controller_parameters.yaml
)

add_library(${PROJECT_NAME} SHARED
src/scaled_joint_trajectory_controller.cpp
src/speed_scaling_state_broadcaster.cpp
src/gpio_controller.cpp)
src/gpio_controller.cpp
src/ur_configuration_controller.cpp)

target_include_directories(${PROJECT_NAME} PRIVATE
include
Expand All @@ -66,6 +72,7 @@ target_link_libraries(${PROJECT_NAME}
gpio_controller_parameters
speed_scaling_state_broadcaster_parameters
scaled_joint_trajectory_controller_parameters
ur_configuration_controller_parameters
)
ament_target_dependencies(${PROJECT_NAME}
${THIS_PACKAGE_INCLUDE_DEPENDS}
Expand Down
5 changes: 5 additions & 0 deletions ur_controllers/controller_plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
This controller publishes the Tool IO.
</description>
</class>
<class name="ur_controllers/URConfigurationController" type="ur_controllers::URConfigurationController" base_class_type="controller_interface::ControllerInterface">
<description>
Controller used to get and change the configuration of the robot
</description>
</class>
</library>
11 changes: 0 additions & 11 deletions ur_controllers/include/ur_controllers/gpio_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#include "rclcpp/duration.hpp"
#include "std_msgs/msg/bool.hpp"
#include "gpio_controller_parameters.hpp"
#include "ur_msgs/srv/get_robot_software_version.hpp"

namespace ur_controllers
{
Expand All @@ -80,8 +79,6 @@ enum CommandInterfaces
ZERO_FTSENSOR_ASYNC_SUCCESS = 32,
HAND_BACK_CONTROL_CMD = 33,
HAND_BACK_CONTROL_ASYNC_SUCCESS = 34,
GET_VERSION_CMD = 35,
GET_VERSION_ASYNC_SUCCESS = 36
};

enum StateInterfaces
Expand All @@ -103,10 +100,6 @@ enum StateInterfaces
SAFETY_STATUS_BITS = 58,
INITIALIZED_FLAG = 69,
PROGRAM_RUNNING = 70,
GET_VERSION_MAJOR = 71,
GET_VERSION_MINOR = 72,
GET_VERSION_BUGFIX = 73,
GET_VERSION_BUILD = 74
};

class GPIOController : public controller_interface::ControllerInterface
Expand Down Expand Up @@ -143,9 +136,6 @@ class GPIOController : public controller_interface::ControllerInterface

bool zeroFTSensor(std_srvs::srv::Trigger::Request::SharedPtr req, std_srvs::srv::Trigger::Response::SharedPtr resp);

bool getRobotSoftwareVersion(ur_msgs::srv::GetRobotSoftwareVersion::Request::SharedPtr req,
ur_msgs::srv::GetRobotSoftwareVersion::Response::SharedPtr resp);

void publishIO();

void publishToolData();
Expand Down Expand Up @@ -173,7 +163,6 @@ class GPIOController : public controller_interface::ControllerInterface
rclcpp::Service<ur_msgs::srv::SetIO>::SharedPtr set_io_srv_;
rclcpp::Service<ur_msgs::srv::SetPayload>::SharedPtr set_payload_srv_;
rclcpp::Service<std_srvs::srv::Trigger>::SharedPtr tare_sensor_srv_;
rclcpp::Service<ur_msgs::srv::GetRobotSoftwareVersion>::SharedPtr get_robot_software_version_srv_;

std::shared_ptr<rclcpp::Publisher<ur_msgs::msg::IOStates>> io_pub_;
std::shared_ptr<rclcpp::Publisher<ur_msgs::msg::ToolDataMsg>> tool_data_pub_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2024, Universal Robots A/S
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the {copyright_holder} nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

//----------------------------------------------------------------------
/*!\file
*
* \author Jacob Larsen jala@universal-robots.com
* \date 2024-07-11
*
*
*
*
*/
//----------------------------------------------------------------------

#ifndef UR_CONTROLLERS__UR_CONFIGURATION_CONTROLLER_HPP_
#define UR_CONTROLLERS__UR_CONFIGURATION_CONTROLLER_HPP_

#include <memory>

#include <controller_interface/controller_interface.hpp>

#include "ur_msgs/srv/get_robot_software_version.hpp"
#include "ur_configuration_controller_parameters.hpp"

namespace ur_controllers
{

enum StateInterfaces
{
ROBOT_VERSION_MAJOR,
ROBOT_VERSION_MINOR,
ROBOT_VERSION_BUILD,
ROBOT_VERSION_BUGFIX
};

class URConfigurationController : public controller_interface::ControllerInterface
{
public:
controller_interface::InterfaceConfiguration command_interface_configuration() const override;

controller_interface::InterfaceConfiguration state_interface_configuration() const override;

controller_interface::return_type update(const rclcpp::Time& time, const rclcpp::Duration& period) override;

CallbackReturn on_configure(const rclcpp_lifecycle::State& previous_state) override;

CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override;

CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override;

CallbackReturn on_init() override;

private:
rclcpp::Service<ur_msgs::srv::GetRobotSoftwareVersion>::SharedPtr get_robot_software_version_srv_;
bool getRobotSoftwareVersion(ur_msgs::srv::GetRobotSoftwareVersion::Request::SharedPtr req,
ur_msgs::srv::GetRobotSoftwareVersion::Response::SharedPtr resp);

std::shared_ptr<ur_configuration_controller::ParamListener> param_listener_;
ur_configuration_controller::Params params_;
};
} // namespace ur_controllers

#endif // UR_CONTROLLERS__UR_CONFIGURATION_CONTROLLER_HPP_
30 changes: 0 additions & 30 deletions ur_controllers/src/gpio_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ controller_interface::InterfaceConfiguration GPIOController::command_interface_c
config.names.emplace_back(tf_prefix + "hand_back_control/hand_back_control_cmd");
config.names.emplace_back(tf_prefix + "hand_back_control/hand_back_control_async_success");

// Robot software version service
config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_cmd");
config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_async_success");

return config;
}

Expand Down Expand Up @@ -322,10 +318,6 @@ ur_controllers::GPIOController::on_activate(const rclcpp_lifecycle::State& /*pre
tare_sensor_srv_ = get_node()->create_service<std_srvs::srv::Trigger>(
"~/zero_ftsensor",
std::bind(&GPIOController::zeroFTSensor, this, std::placeholders::_1, std::placeholders::_2));

get_robot_software_version_srv_ = get_node()->create_service<ur_msgs::srv::GetRobotSoftwareVersion>(
"~/get_robot_software_version",
std::bind(&GPIOController::getRobotSoftwareVersion, this, std::placeholders::_1, std::placeholders::_2));
} catch (...) {
return LifecycleNodeInterface::CallbackReturn::ERROR;
}
Expand Down Expand Up @@ -534,28 +526,6 @@ bool GPIOController::zeroFTSensor(std_srvs::srv::Trigger::Request::SharedPtr /*r
return true;
}

bool GPIOController::getRobotSoftwareVersion(ur_msgs::srv::GetRobotSoftwareVersion::Request::SharedPtr /*req*/,
ur_msgs::srv::GetRobotSoftwareVersion::Response::SharedPtr resp)
{
// reset success flag
command_interfaces_[CommandInterfaces::GET_VERSION_ASYNC_SUCCESS].set_value(ASYNC_WAITING);

// call the service in the hardware
command_interfaces_[CommandInterfaces::GET_VERSION_CMD].set_value(1.0);

if (!waitForAsyncCommand(
[&]() { return command_interfaces_[CommandInterfaces::GET_VERSION_ASYNC_SUCCESS].get_value(); })) {
RCLCPP_WARN(get_node()->get_logger(), "Could not verify software version of robot.");
}

resp->major = static_cast<uint32_t>(state_interfaces_[StateInterfaces::GET_VERSION_MAJOR].get_value());
resp->minor = static_cast<uint32_t>(state_interfaces_[StateInterfaces::GET_VERSION_MINOR].get_value());
resp->bugfix = static_cast<uint32_t>(state_interfaces_[StateInterfaces::GET_VERSION_BUGFIX].get_value());
resp->build = static_cast<uint32_t>(state_interfaces_[StateInterfaces::GET_VERSION_BUILD].get_value());

return true;
}

void GPIOController::initMsgs()
{
io_msg_.digital_in_states.resize(standard_digital_output_cmd_.size());
Expand Down
122 changes: 122 additions & 0 deletions ur_controllers/src/ur_configuration_controller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2024, Universal Robots A/S
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the {copyright_holder} nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

//----------------------------------------------------------------------
/*!\file
*
* \author Jacob Larsen jala@universal-robots.com
* \date 2024-07-11
*
*
*
*
*/
//----------------------------------------------------------------------

#include <ur_controllers/ur_configuration_controller.hpp>
namespace ur_controllers
{

controller_interface::CallbackReturn URConfigurationController::on_init()
{
param_listener_ = std::make_shared<ur_configuration_controller::ParamListener>(get_node());
params_ = param_listener_->get_params();
return controller_interface::CallbackReturn::SUCCESS;
}

controller_interface::CallbackReturn
URConfigurationController::on_configure(const rclcpp_lifecycle::State& /* previous_state */)
{
return controller_interface::CallbackReturn::SUCCESS;
}

controller_interface::InterfaceConfiguration URConfigurationController::command_interface_configuration() const
{
// No command interfaces currently
controller_interface::InterfaceConfiguration config;
config.type = controller_interface::interface_configuration_type::INDIVIDUAL;

const std::string tf_prefix = params_.tf_prefix;

return config;
}

controller_interface::InterfaceConfiguration URConfigurationController::state_interface_configuration() const
{
controller_interface::InterfaceConfiguration config;
config.type = controller_interface::interface_configuration_type::INDIVIDUAL;

const std::string tf_prefix = params_.tf_prefix;

config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_major");
config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_minor");
config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_build");
config.names.emplace_back(tf_prefix + "get_robot_software_version/get_version_bugfix");

return config;
}

controller_interface::return_type URConfigurationController::update(const rclcpp::Time& /* time */,
const rclcpp::Duration& /* period */)
{
return controller_interface::return_type::OK;
}

controller_interface::CallbackReturn
URConfigurationController::on_activate(const rclcpp_lifecycle::State& /* previous_state */)
{
get_robot_software_version_srv_ = get_node()->create_service<ur_msgs::srv::GetRobotSoftwareVersion>(
"~/get_robot_software_version", std::bind(&URConfigurationController::getRobotSoftwareVersion, this,
std::placeholders::_1, std::placeholders::_2));

return controller_interface::CallbackReturn::SUCCESS;
}

controller_interface::CallbackReturn
URConfigurationController::on_deactivate(const rclcpp_lifecycle::State& /* previous_state */)
{
get_robot_software_version_srv_.reset();
return controller_interface::CallbackReturn::SUCCESS;
}

bool URConfigurationController::getRobotSoftwareVersion(
ur_msgs::srv::GetRobotSoftwareVersion::Request::SharedPtr /*req*/,
ur_msgs::srv::GetRobotSoftwareVersion::Response::SharedPtr resp)
{
resp->major = static_cast<uint32_t>(state_interfaces_[StateInterfaces::ROBOT_VERSION_MAJOR].get_value());
resp->minor = static_cast<uint32_t>(state_interfaces_[StateInterfaces::ROBOT_VERSION_MINOR].get_value());
resp->bugfix = static_cast<uint32_t>(state_interfaces_[StateInterfaces::ROBOT_VERSION_BUGFIX].get_value());
resp->build = static_cast<uint32_t>(state_interfaces_[StateInterfaces::ROBOT_VERSION_BUILD].get_value());

return true;
}
} // namespace ur_controllers

#include "pluginlib/class_list_macros.hpp"

PLUGINLIB_EXPORT_CLASS(ur_controllers::URConfigurationController, controller_interface::ControllerInterface)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ur_configuration_controller:
tf_prefix: {
type: string,
default_value: "",
description: "Urdf prefix of the corresponding arm"
}
Loading

0 comments on commit 2d70a9b

Please sign in to comment.