1
0
mirror of https://gitlab.com/obbart/universal_robots_ros_driver.git synced 2026-04-12 19:10:47 +02:00

Added a subscriber to send custom script commands to the robot

This commit is contained in:
Felix Mauch
2019-08-07 12:24:25 +02:00
parent fc53734bb3
commit 4a0dba2e03
4 changed files with 62 additions and 3 deletions

View File

@@ -77,6 +77,7 @@ bool HardwareInterface ::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_h
std::string tf_prefix = robot_hw_nh.param<std::string>("tf_prefix", "");
program_state_pub_ = robot_hw_nh.advertise<std_msgs::Bool>("robot_program_running", 10, true);
command_sub_ = robot_hw_nh.subscribe("script_command", 1, &HardwareInterface::commandCallback, this);
tcp_transform_.header.frame_id = "base";
tcp_transform_.child_frame_id = "tool0_controller";
@@ -579,4 +580,24 @@ bool HardwareInterface::setIO(ur_msgs::SetIORequest& req, ur_msgs::SetIOResponse
return true;
}
void HardwareInterface::commandCallback(const std_msgs::StringConstPtr& msg)
{
std::string str = msg->data;
if (str.back() != '\n')
{
str.append("\n");
}
// TODO: Check whether we can currently send code
if (ur_driver_->sendScript(str))
{
ROS_DEBUG_STREAM("Sent script to robot");
}
else
{
ROS_ERROR_STREAM("Error sending script to robot");
}
}
} // namespace ur_driver