From b70c5b29514ff8a622189e22ce6b2ad817dc5b17 Mon Sep 17 00:00:00 2001 From: "Felix Exner (fexner)" Date: Mon, 30 Sep 2024 13:41:25 +0200 Subject: [PATCH] Add a set_analog_output service (#714) * Add a set_analog_output service This service allows setting an analog output with an output domain. * Fix formatting --- .../include/ur_robot_driver/hardware_interface.h | 3 +++ ur_robot_driver/src/hardware_interface.cpp | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ur_robot_driver/include/ur_robot_driver/hardware_interface.h b/ur_robot_driver/include/ur_robot_driver/hardware_interface.h index 172f436d..a7eeeb3e 100644 --- a/ur_robot_driver/include/ur_robot_driver/hardware_interface.h +++ b/ur_robot_driver/include/ur_robot_driver/hardware_interface.h @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -211,6 +212,7 @@ class HardwareInterface : public hardware_interface::RobotHW bool setSpeedSlider(ur_msgs::SetSpeedSliderFractionRequest& req, ur_msgs::SetSpeedSliderFractionResponse& res); bool setIO(ur_msgs::SetIORequest& req, ur_msgs::SetIOResponse& res); + bool setAnalogOutput(ur_msgs::SetAnalogOutputRequest& req, ur_msgs::SetAnalogOutputResponse& res); bool resendRobotProgram(std_srvs::TriggerRequest& req, std_srvs::TriggerResponse& res); bool zeroFTSensor(std_srvs::TriggerRequest& req, std_srvs::TriggerResponse& res); void commandCallback(const std_msgs::StringConstPtr& msg); @@ -319,6 +321,7 @@ class HardwareInterface : public hardware_interface::RobotHW ros::ServiceServer set_speed_slider_srv_; ros::ServiceServer set_io_srv_; + ros::ServiceServer set_analog_output_srv_; ros::ServiceServer resend_robot_program_srv_; ros::Subscriber command_sub_; diff --git a/ur_robot_driver/src/hardware_interface.cpp b/ur_robot_driver/src/hardware_interface.cpp index 59c6d893..c27a36ea 100644 --- a/ur_robot_driver/src/hardware_interface.cpp +++ b/ur_robot_driver/src/hardware_interface.cpp @@ -435,8 +435,9 @@ bool HardwareInterface::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_hw // doing. Using this with other controllers might lead to unexpected behaviors. set_speed_slider_srv_ = robot_hw_nh.advertiseService("set_speed_slider", &HardwareInterface::setSpeedSlider, this); - // Service to set any of the robot's IOs + // Services to set any of the robot's IOs set_io_srv_ = robot_hw_nh.advertiseService("set_io", &HardwareInterface::setIO, this); + set_analog_output_srv_ = robot_hw_nh.advertiseService("set_analog_output", &HardwareInterface::setAnalogOutput, this); if (headless_mode) { @@ -1135,6 +1136,16 @@ bool HardwareInterface::setIO(ur_msgs::SetIORequest& req, ur_msgs::SetIOResponse return true; } +bool HardwareInterface::setAnalogOutput(ur_msgs::SetAnalogOutputRequest& req, ur_msgs::SetAnalogOutputResponse& res) +{ + if (ur_driver_) + { + res.success = ur_driver_->getRTDEWriter().sendStandardAnalogOutput( + req.data.pin, req.data.state, static_cast(req.data.domain)); + } + return true; +} + bool HardwareInterface::resendRobotProgram(std_srvs::TriggerRequest& req, std_srvs::TriggerResponse& res) { res.success = ur_driver_->sendRobotProgram();