Skip to content

Commit d30cb71

Browse files
committed
Add twist to hardware interface
1 parent a3390ff commit d30cb71

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ enum StoppingInterface
8383
STOP_FREEDRIVE,
8484
STOP_TOOL_CONTACT,
8585
STOP_TORQUE,
86+
STOP_TWIST,
8687
};
8788

8889
// We define our own quaternion to use it as a buffer, since we need to pass pointers to the state
@@ -179,6 +180,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
179180
urcl::vector6d_t urcl_position_commands_old_;
180181
urcl::vector6d_t urcl_velocity_commands_;
181182
urcl::vector6d_t urcl_torque_commands_;
183+
urcl::vector6d_t urcl_twist_commands_;
182184
urcl::vector6d_t urcl_joint_positions_;
183185
urcl::vector6d_t urcl_joint_velocities_;
184186
urcl::vector6d_t urcl_joint_efforts_;
@@ -260,6 +262,8 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
260262
urcl::vector6d_t passthrough_trajectory_accelerations_;
261263
double passthrough_trajectory_time_from_start_;
262264

265+
bool twist_controller_running_;
266+
263267
// payload stuff
264268
urcl::vector3d_t payload_center_of_gravity_;
265269
double payload_mass_;
@@ -322,6 +326,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
322326
const std::string FORCE_MODE_GPIO = "force_mode";
323327
const std::string FREEDRIVE_MODE_GPIO = "freedrive_mode";
324328
const std::string TOOL_CONTACT_GPIO = "tool_contact";
329+
const std::string TWIST_GPIO = "twist";
325330

326331
std::unordered_map<std::string, std::unordered_map<std::string, bool>> mode_compatibility_;
327332
};

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ URPositionHardwareInterface::URPositionHardwareInterface()
6565
mode_compatibility_[hardware_interface::HW_IF_POSITION][PASSTHROUGH_GPIO] = false;
6666
mode_compatibility_[hardware_interface::HW_IF_POSITION][FREEDRIVE_MODE_GPIO] = false;
6767
mode_compatibility_[hardware_interface::HW_IF_POSITION][TOOL_CONTACT_GPIO] = true;
68+
mode_compatibility_[hardware_interface::HW_IF_POSITION][TWIST_GPIO] = false;
6869

6970
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][hardware_interface::HW_IF_POSITION] = false;
7071
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][hardware_interface::HW_IF_EFFORT] = false;
7172
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][FORCE_MODE_GPIO] = false;
7273
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][PASSTHROUGH_GPIO] = false;
7374
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][FREEDRIVE_MODE_GPIO] = false;
7475
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][TOOL_CONTACT_GPIO] = true;
76+
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][TWIST_GPIO] = true;
7577

7678
mode_compatibility_[hardware_interface::HW_IF_EFFORT][hardware_interface::HW_IF_POSITION] = false;
7779
mode_compatibility_[hardware_interface::HW_IF_EFFORT][hardware_interface::HW_IF_VELOCITY] = false;
@@ -86,27 +88,38 @@ URPositionHardwareInterface::URPositionHardwareInterface()
8688
mode_compatibility_[FORCE_MODE_GPIO][PASSTHROUGH_GPIO] = true;
8789
mode_compatibility_[FORCE_MODE_GPIO][FREEDRIVE_MODE_GPIO] = false;
8890
mode_compatibility_[FORCE_MODE_GPIO][TOOL_CONTACT_GPIO] = false;
91+
mode_compatibility_[FORCE_MODE_GPIO][TWIST_GPIO] = false;
8992

9093
mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_POSITION] = false;
9194
mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_VELOCITY] = false;
9295
mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_EFFORT] = false;
9396
mode_compatibility_[PASSTHROUGH_GPIO][FORCE_MODE_GPIO] = true;
9497
mode_compatibility_[PASSTHROUGH_GPIO][FREEDRIVE_MODE_GPIO] = false;
9598
mode_compatibility_[PASSTHROUGH_GPIO][TOOL_CONTACT_GPIO] = true;
99+
mode_compatibility_[PASSTHROUGH_GPIO][TWIST_GPIO] = false;
96100

97101
mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_POSITION] = false;
98102
mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_VELOCITY] = false;
99103
mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_EFFORT] = false;
100104
mode_compatibility_[FREEDRIVE_MODE_GPIO][FORCE_MODE_GPIO] = false;
101105
mode_compatibility_[FREEDRIVE_MODE_GPIO][PASSTHROUGH_GPIO] = false;
102106
mode_compatibility_[FREEDRIVE_MODE_GPIO][TOOL_CONTACT_GPIO] = false;
107+
mode_compatibility_[FREEDRIVE_MODE_GPIO][TWIST_GPIO] = false;
103108

104109
mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_POSITION] = true;
105110
mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_VELOCITY] = true;
106111
mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_EFFORT] = true;
107112
mode_compatibility_[TOOL_CONTACT_GPIO][FORCE_MODE_GPIO] = false;
108113
mode_compatibility_[TOOL_CONTACT_GPIO][PASSTHROUGH_GPIO] = true;
109114
mode_compatibility_[TOOL_CONTACT_GPIO][FREEDRIVE_MODE_GPIO] = false;
115+
mode_compatibility_[TOOL_CONTACT_GPIO][TWIST_GPIO] = true;
116+
117+
mode_compatibility_[TWIST_GPIO][hardware_interface::HW_IF_POSITION] = false;
118+
mode_compatibility_[TWIST_GPIO][hardware_interface::HW_IF_VELOCITY] = false;
119+
mode_compatibility_[TWIST_GPIO][FORCE_MODE_GPIO] = false;
120+
mode_compatibility_[TWIST_GPIO][PASSTHROUGH_GPIO] = false;
121+
mode_compatibility_[TWIST_GPIO][FREEDRIVE_MODE_GPIO] = false;
122+
mode_compatibility_[TWIST_GPIO][TOOL_CONTACT_GPIO] = true;
110123
}
111124

112125
URPositionHardwareInterface::~URPositionHardwareInterface()
@@ -131,12 +144,14 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareComponent
131144
urcl_position_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
132145
urcl_position_commands_old_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
133146
urcl_velocity_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
147+
urcl_twist_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
134148
position_controller_running_ = false;
135149
velocity_controller_running_ = false;
136150
torque_controller_running_ = false;
137151
freedrive_mode_controller_running_ = false;
138152
passthrough_trajectory_controller_running_ = false;
139153
tool_contact_controller_running_ = false;
154+
twist_controller_running_ = false;
140155
runtime_state_ = static_cast<uint32_t>(rtde::RUNTIME_STATE::STOPPED);
141156
pausing_state_ = PausingState::RUNNING;
142157
pausing_ramp_up_increment_ = 0.01;
@@ -482,6 +497,19 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
482497
&passthrough_trajectory_accelerations_[i]));
483498
}
484499

500+
command_interfaces.emplace_back(
501+
hardware_interface::CommandInterface(tf_prefix + TWIST_GPIO, "linear_velocity_x", &urcl_twist_commands_[0]));
502+
command_interfaces.emplace_back(
503+
hardware_interface::CommandInterface(tf_prefix + TWIST_GPIO, "linear_velocity_y", &urcl_twist_commands_[1]));
504+
command_interfaces.emplace_back(
505+
hardware_interface::CommandInterface(tf_prefix + TWIST_GPIO, "linear_velocity_z", &urcl_twist_commands_[2]));
506+
command_interfaces.emplace_back(
507+
hardware_interface::CommandInterface(tf_prefix + TWIST_GPIO, "angular_velocity_x", &urcl_twist_commands_[3]));
508+
command_interfaces.emplace_back(
509+
hardware_interface::CommandInterface(tf_prefix + TWIST_GPIO, "angular_velocity_y", &urcl_twist_commands_[4]));
510+
command_interfaces.emplace_back(
511+
hardware_interface::CommandInterface(tf_prefix + TWIST_GPIO, "angular_velocity_z", &urcl_twist_commands_[5]));
512+
485513
command_interfaces.emplace_back(hardware_interface::CommandInterface(
486514
tf_prefix + TOOL_CONTACT_GPIO, "tool_contact_set_state", &tool_contact_set_state_));
487515

@@ -884,6 +912,8 @@ hardware_interface::return_type URPositionHardwareInterface::write(const rclcpp:
884912
urcl::control::TrajectoryControlMessage::TRAJECTORY_NOOP, 0,
885913
urcl::RobotReceiveTimeout::millisec(1000 * 5.0 / static_cast<double>(info_.rw_rate)));
886914
check_passthrough_trajectory_controller();
915+
} else if (twist_controller_running_) {
916+
ur_driver_->writeJointCommand(urcl_twist_commands_, urcl::comm::ControlMode::MODE_SPEEDL, receive_timeout_);
887917
} else {
888918
ur_driver_->writeKeepalive();
889919
}
@@ -1170,6 +1200,9 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
11701200
if (tool_contact_controller_running_) {
11711201
control_modes[i].push_back(TOOL_CONTACT_GPIO);
11721202
}
1203+
if (twist_controller_running_) {
1204+
control_modes[i].push_back(TWIST_GPIO);
1205+
}
11731206
}
11741207

11751208
auto is_mode_compatible = [this](const std::string& mode, const std::vector<std::string>& other_modes) {
@@ -1197,7 +1230,8 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
11971230
{ tf_prefix + FORCE_MODE_GPIO + "/type", FORCE_MODE_GPIO },
11981231
{ tf_prefix + PASSTHROUGH_GPIO + "/setpoint_positions_" + std::to_string(i), PASSTHROUGH_GPIO },
11991232
{ tf_prefix + FREEDRIVE_MODE_GPIO + "/async_success", FREEDRIVE_MODE_GPIO },
1200-
{ tf_prefix + TOOL_CONTACT_GPIO + "/tool_contact_set_state", TOOL_CONTACT_GPIO }
1233+
{ tf_prefix + TOOL_CONTACT_GPIO + "/tool_contact_set_state", TOOL_CONTACT_GPIO },
1234+
{ tf_prefix + TWIST_GPIO + "/linear_velocity_x", TWIST_GPIO }
12011235
};
12021236

12031237
for (auto& item : start_modes_to_check) {
@@ -1247,7 +1281,8 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
12471281
StoppingInterface::STOP_PASSTHROUGH },
12481282
{ tf_prefix + FREEDRIVE_MODE_GPIO + "/async_success", FREEDRIVE_MODE_GPIO, StoppingInterface::STOP_FREEDRIVE },
12491283
{ tf_prefix + TOOL_CONTACT_GPIO + "/tool_contact_set_state", TOOL_CONTACT_GPIO,
1250-
StoppingInterface::STOP_TOOL_CONTACT }
1284+
StoppingInterface::STOP_TOOL_CONTACT },
1285+
{ tf_prefix + TWIST_GPIO + "/linear_velocity_x", TWIST_GPIO, StoppingInterface::STOP_TWIST }
12511286
};
12521287
for (auto& item : stop_modes_to_check) {
12531288
if (key == std::get<0>(item)) {
@@ -1312,13 +1347,20 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
13121347
freedrive_activated_ = false;
13131348
freedrive_mode_abort_ = 1.0;
13141349
}
1350+
13151351
if (stop_modes_.size() != 0 && std::find(stop_modes_[0].begin(), stop_modes_[0].end(),
13161352
StoppingInterface::STOP_TOOL_CONTACT) != stop_modes_[0].end()) {
13171353
tool_contact_controller_running_ = false;
13181354
tool_contact_result_ = 3.0;
13191355
ur_driver_->endToolContact();
13201356
}
13211357

1358+
if (stop_modes_.size() != 0 &&
1359+
std::find(stop_modes_[0].begin(), stop_modes_[0].end(), StoppingInterface::STOP_TWIST) != stop_modes_[0].end()) {
1360+
twist_controller_running_ = false;
1361+
urcl_twist_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
1362+
}
1363+
13221364
if (start_modes_.size() != 0 && std::find(start_modes_[0].begin(), start_modes_[0].end(),
13231365
hardware_interface::HW_IF_POSITION) != start_modes_[0].end()) {
13241366
velocity_controller_running_ = false;
@@ -1366,6 +1408,12 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
13661408
std::find(start_modes_[0].begin(), start_modes_[0].end(), TOOL_CONTACT_GPIO) != start_modes_[0].end()) {
13671409
tool_contact_controller_running_ = true;
13681410
}
1411+
if (start_modes_[0].size() != 0 &&
1412+
std::find(start_modes_[0].begin(), start_modes_[0].end(), TWIST_GPIO) != start_modes_[0].end()) {
1413+
velocity_controller_running_ = false;
1414+
position_controller_running_ = false;
1415+
twist_controller_running_ = true;
1416+
}
13691417
start_modes_.clear();
13701418
stop_modes_.clear();
13711419

ur_robot_driver/urdf/ur.ros2_control.xacro

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@
298298
<command_interface name="trajectory_size"/>
299299
</gpio>
300300

301+
<gpio name="${tf_prefix}twist">
302+
<command_interface name="linear_velocity_x"/>
303+
<command_interface name="linear_velocity_y"/>
304+
<command_interface name="linear_velocity_z"/>
305+
<command_interface name="angular_velocity_x"/>
306+
<command_interface name="angular_velocity_y"/>
307+
<command_interface name="angular_velocity_z"/>
308+
</gpio>
301309

302310
<gpio name="${tf_prefix}get_robot_software_version">
303311
<state_interface name="get_version_major">

0 commit comments

Comments
 (0)