@@ -457,7 +457,10 @@ bool HardwareInterface::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_hw
457457 set_payload_srv_ = robot_hw_nh.advertiseService (" set_payload" , &HardwareInterface::setPayload, this );
458458
459459 // Calling this service will set the robot in force mode
460- set_force_mode_srv_ = robot_hw_nh.advertiseService (" set_force_mode" , &HardwareInterface::setForceMode, this );
460+ start_force_mode_srv_ = robot_hw_nh.advertiseService (" start_force_mode" , &HardwareInterface::startForceMode, this );
461+
462+ // Calling this service will stop the robot from being in force mode
463+ end_force_mode_srv_ = robot_hw_nh.advertiseService (" end_force_mode" , &HardwareInterface::endForceMode, this );
461464
462465 // Call this to activate or deactivate using spline interpolation locally on the UR controller, when forwarding
463466 // trajectories to the UR robot.
@@ -1217,18 +1220,48 @@ bool HardwareInterface::setForceMode(ur_msgs::SetForceModeRequest& req, ur_msgs:
12171220 urcl::vector6uint32_t selection_vector;
12181221 urcl::vector6d_t wrench;
12191222 urcl::vector6d_t limits;
1220- for (size_t i = 0 ; i < 6 ; i++)
1221- {
1222- task_frame[i] = req.task_frame [i];
1223- selection_vector[i] = req.selection_vector [i];
1224- wrench[i] = req.wrench [i];
1225- limits[i] = req.limits [i];
1226- }
1223+
1224+ task_frame[0 ] = req.task_frame .pose .position .x ;
1225+ task_frame[1 ] = req.task_frame .pose .position .x ;
1226+ task_frame[2 ] = req.task_frame .pose .position .x ;
1227+ KDL::Rotation rot = KDL::Rotation::Quaternion (req.task_frame .pose .orientation .x , req.task_frame .pose .orientation .y ,
1228+ req.task_frame .pose .orientation .z , req.task_frame .pose .orientation .w );
1229+ task_frame[3 ] = rot.GetRot ().x ();
1230+ task_frame[4 ] = rot.GetRot ().y ();
1231+ task_frame[5 ] = rot.GetRot ().z ();
1232+
1233+ selection_vector[0 ] = req.selection_vector_x ;
1234+ selection_vector[1 ] = req.selection_vector_y ;
1235+ selection_vector[2 ] = req.selection_vector_z ;
1236+ selection_vector[3 ] = req.selection_vector_rx ;
1237+ selection_vector[4 ] = req.selection_vector_ry ;
1238+ selection_vector[5 ] = req.selection_vector_rz ;
1239+
1240+ wrench[0 ] = req.wrench .wrench .force .x ;
1241+ wrench[1 ] = req.wrench .wrench .force .y ;
1242+ wrench[2 ] = req.wrench .wrench .force .z ;
1243+ wrench[3 ] = req.wrench .wrench .torque .x ;
1244+ wrench[4 ] = req.wrench .wrench .torque .y ;
1245+ wrench[5 ] = req.wrench .wrench .torque .z ;
1246+
1247+ limits[0 ] = req.limits .twist .linear .x ;
1248+ limits[1 ] = req.limits .twist .linear .y ;
1249+ limits[2 ] = req.limits .twist .linear .z ;
1250+ limits[3 ] = req.limits .twist .angular .x ;
1251+ limits[4 ] = req.limits .twist .angular .y ;
1252+ limits[5 ] = req.limits .twist .angular .z ;
1253+
12271254 unsigned int type = req.type ;
12281255 res.success = this ->ur_driver_ ->startForceMode (task_frame, selection_vector, wrench, type, limits);
12291256 return res.success ;
12301257}
12311258
1259+ bool HardwareInterface::endForceMode (std_srvs::TriggerRequest& req, std_srvs::TriggerResponse& res)
1260+ {
1261+ res.success = this ->ur_driver_ ->endForceMode ();
1262+ return res.success ;
1263+ }
1264+
12321265void HardwareInterface::commandCallback (const std_msgs::StringConstPtr& msg)
12331266{
12341267 std::string str = msg->data ;
0 commit comments