Skip to content

Added a service to setup the active payload #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ur_robot_driver/doc/ROS_INTERFACE.md
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,10 @@ Service to set any of the robot's IOs
##### set_speed_slider (ur_msgs/SetSpeedSliderFraction)

Set the speed slider fraction used by the robot's execution. Values should be between 0 and 1. Only set this smaller than 1 if you are using the scaled controllers (as by default) or you know what you're doing. Using this with other controllers might lead to unexpected behaviors.

#### set_payload (ur_msgs/SetPayload)

Setup the mounted payload through a ROS service

##### zero_ftsensor ([std_srvs/Trigger](http://docs.ros.org/api/std_srvs/html/srv/Trigger.html))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class HardwareInterface : public hardware_interface::RobotHW

ros::ServiceServer deactivate_srv_;
ros::ServiceServer tare_sensor_srv_;
ros::ServiceServer set_payload_srv_;

hardware_interface::JointStateInterface js_interface_;
ur_controllers::ScaledPositionJointInterface spj_interface_;
Expand Down
15 changes: 15 additions & 0 deletions ur_robot_driver/src/ros/hardware_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "ur_robot_driver/ur/tool_communication.h"
#include <ur_robot_driver/exceptions.h>

#include <ur_msgs/SetPayload.h>

#include <Eigen/Geometry>

using industrial_robot_status_interface::RobotMode;
Expand Down Expand Up @@ -383,6 +385,19 @@ bool HardwareInterface::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_hw
ur_driver_->startRTDECommunication();
ROS_INFO_STREAM_NAMED("hardware_interface", "Loaded ur_robot_driver hardware_interface");

// Setup the mounted payload through a ROS service
set_payload_srv_ = robot_hw_nh.advertiseService<ur_msgs::SetPayload::Request, ur_msgs::SetPayload::Response>(
"set_payload", [&](ur_msgs::SetPayload::Request& req, ur_msgs::SetPayload::Response& resp) {
std::stringstream cmd;
cmd.imbue(std::locale::classic()); // Make sure, decimal divider is actually '.'
cmd << "sec setup():" << std::endl
<< " set_payload(" << req.payload << ", [" << req.center_of_gravity.x << ", " << req.center_of_gravity.y
<< ", " << req.center_of_gravity.z << "])" << std::endl
Comment on lines +394 to +395
Copy link
Contributor

@gavanderhoorn gavanderhoorn Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is relying on << to convert floats/doubles to string locale -safe?

Could end up with multiple commas in the string, which would probably upset UR's parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not think about that. I would never have though about the stream operator using locales in the background.

In a quick example I could not get a stream into locale-like formatting without explicitly setting the locale of the stream. However, to make sure, we could set the string's locale explicitly to classic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to avoid another ros/urdfdom_headers#41.

If stream io doesn't suffer from this, all the better.

<< "end";
resp.success = this->ur_driver_->sendScript(cmd.str());
return true;
});

return true;
}

Expand Down