Skip to content

Commit 4769303

Browse files
urmarpurfeex
authored andcommitted
Changed setForce mode to startForceMode and endForceMode. Also made changes to account for changes in msg in PR (ros-industrial/ur_msgs#20)
1 parent cdf1881 commit 4769303

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ class HardwareInterface : public hardware_interface::RobotHW
221221
bool activateSplineInterpolation(std_srvs::SetBoolRequest& req, std_srvs::SetBoolResponse& res);
222222
bool getRobotSoftwareVersion(ur_msgs::GetRobotSoftwareVersionRequest& req,
223223
ur_msgs::GetRobotSoftwareVersionResponse& res);
224-
bool setForceMode(ur_msgs::SetForceModeRequest& req, ur_msgs::SetForceModeResponse& res);
224+
bool startForceMode(ur_msgs::SetForceModeRequest& req, ur_msgs::SetForceModeResponse& res);
225+
bool endForceMode(std_srvs::TriggerRequest& req, std_srvs::TriggerResponse& res);
225226

226227
std::unique_ptr<urcl::UrDriver> ur_driver_;
227228
std::unique_ptr<DashboardClientROS> dashboard_client_;
@@ -247,7 +248,8 @@ class HardwareInterface : public hardware_interface::RobotHW
247248
ros::ServiceServer set_payload_srv_;
248249
ros::ServiceServer activate_spline_interpolation_srv_;
249250
ros::ServiceServer get_robot_software_version_srv;
250-
ros::ServiceServer set_force_mode_srv_;
251+
ros::ServiceServer start_force_mode_srv_;
252+
ros::ServiceServer end_force_mode_srv_;
251253

252254
hardware_interface::JointStateInterface js_interface_;
253255
scaled_controllers::ScaledPositionJointInterface spj_interface_;

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
12321265
void HardwareInterface::commandCallback(const std_msgs::StringConstPtr& msg)
12331266
{
12341267
std::string str = msg->data;

0 commit comments

Comments
 (0)