Skip to content

Commit cc55afa

Browse files
urmarpURJala
authored andcommitted
Added service to set force mode through ROS
1 parent 497af25 commit cc55afa

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <ur_msgs/SetIO.h>
5555
#include <ur_msgs/SetSpeedSliderFraction.h>
5656
#include <ur_msgs/SetPayload.h>
57+
#include <ur_msgs/SetForceMode.h>
5758

5859
#include <cartesian_interface/cartesian_command_interface.h>
5960
#include <cartesian_interface/cartesian_state_handle.h>
@@ -215,6 +216,7 @@ class HardwareInterface : public hardware_interface::RobotHW
215216
void commandCallback(const std_msgs::StringConstPtr& msg);
216217
bool setPayload(ur_msgs::SetPayloadRequest& req, ur_msgs::SetPayloadResponse& res);
217218
bool activateSplineInterpolation(std_srvs::SetBoolRequest& req, std_srvs::SetBoolResponse& res);
219+
bool setForceMode(ur_msgs::SetForceModeRequest& req, ur_msgs::SetForceModeResponse& res);
218220

219221
std::unique_ptr<urcl::UrDriver> ur_driver_;
220222
std::unique_ptr<DashboardClientROS> dashboard_client_;
@@ -239,6 +241,7 @@ class HardwareInterface : public hardware_interface::RobotHW
239241
ros::ServiceServer tare_sensor_srv_;
240242
ros::ServiceServer set_payload_srv_;
241243
ros::ServiceServer activate_spline_interpolation_srv_;
244+
ros::ServiceServer set_force_mode_srv_;
242245

243246
hardware_interface::JointStateInterface js_interface_;
244247
scaled_controllers::ScaledPositionJointInterface spj_interface_;

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ bool HardwareInterface::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_hw
455455
// Setup the mounted payload through a ROS service
456456
set_payload_srv_ = robot_hw_nh.advertiseService("set_payload", &HardwareInterface::setPayload, this);
457457

458+
// Calling this service will set the robot in force mode
459+
set_force_mode_srv_ = robot_hw_nh.advertiseService("set_force_mode", &HardwareInterface::setForceMode, this);
460+
458461
// Call this to activate or deactivate using spline interpolation locally on the UR controller, when forwarding
459462
// trajectories to the UR robot.
460463
activate_spline_interpolation_srv_ = robot_hw_nh.advertiseService(
@@ -1175,6 +1178,31 @@ bool HardwareInterface::setPayload(ur_msgs::SetPayloadRequest& req, ur_msgs::Set
11751178
return true;
11761179
}
11771180

1181+
bool HardwareInterface::setForceMode(ur_msgs::SetForceModeRequest& req, ur_msgs::SetForceModeResponse& res)
1182+
{
1183+
if (req.task_frame.size() != 6 || req.selection_vector.size() != 6 || req.wrench.size() != 6 ||
1184+
req.limits.size() != 6)
1185+
{
1186+
URCL_LOG_WARN("Size of received SetForceMode message is wrong");
1187+
res.success = false;
1188+
return false;
1189+
}
1190+
urcl::vector6d_t task_frame;
1191+
urcl::vector6uint32_t selection_vector;
1192+
urcl::vector6d_t wrench;
1193+
urcl::vector6d_t limits;
1194+
for (size_t i = 0; i < 6; i++)
1195+
{
1196+
task_frame[i] = req.task_frame[i];
1197+
selection_vector[i] = req.selection_vector[i];
1198+
wrench[i] = req.wrench[i];
1199+
limits[i] = req.limits[i];
1200+
}
1201+
unsigned int type = req.type;
1202+
res.success = this->ur_driver_->startForceMode(task_frame, selection_vector, wrench, type, limits);
1203+
return res.success;
1204+
}
1205+
11781206
void HardwareInterface::commandCallback(const std_msgs::StringConstPtr& msg)
11791207
{
11801208
std::string str = msg->data;

0 commit comments

Comments
 (0)