@@ -455,6 +455,9 @@ bool HardwareInterface::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_hw
455
455
// Setup the mounted payload through a ROS service
456
456
set_payload_srv_ = robot_hw_nh.advertiseService (" set_payload" , &HardwareInterface::setPayload, this );
457
457
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
+
458
461
// Call this to activate or deactivate using spline interpolation locally on the UR controller, when forwarding
459
462
// trajectories to the UR robot.
460
463
activate_spline_interpolation_srv_ = robot_hw_nh.advertiseService (
@@ -1175,6 +1178,31 @@ bool HardwareInterface::setPayload(ur_msgs::SetPayloadRequest& req, ur_msgs::Set
1175
1178
return true ;
1176
1179
}
1177
1180
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
+
1178
1206
void HardwareInterface::commandCallback (const std_msgs::StringConstPtr& msg)
1179
1207
{
1180
1208
std::string str = msg->data ;
0 commit comments