Skip to content

Commit e910c15

Browse files
committed
Add effort command interface to hardware interface
1 parent effc0a0 commit e910c15

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

ur_robot_driver/config/ur_controllers.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ controller_manager:
2121
forward_velocity_controller:
2222
type: velocity_controllers/JointGroupVelocityController
2323

24+
forward_effort_controller:
25+
type: effort_controllers/JointGroupEffortController
26+
2427
forward_position_controller:
2528
type: position_controllers/JointGroupPositionController
2629

@@ -159,6 +162,17 @@ forward_velocity_controller:
159162
- $(var tf_prefix)wrist_3_joint
160163
interface_name: velocity
161164

165+
forward_effort_controller:
166+
ros__parameters:
167+
joints:
168+
- $(var tf_prefix)shoulder_pan_joint
169+
- $(var tf_prefix)shoulder_lift_joint
170+
- $(var tf_prefix)elbow_joint
171+
- $(var tf_prefix)wrist_1_joint
172+
- $(var tf_prefix)wrist_2_joint
173+
- $(var tf_prefix)wrist_3_joint
174+
interface_name: effort
175+
162176
forward_position_controller:
163177
ros__parameters:
164178
joints:

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ enum StoppingInterface
8282
STOP_FORCE_MODE,
8383
STOP_FREEDRIVE,
8484
STOP_TOOL_CONTACT,
85+
STOP_TORQUE,
8586
};
8687

8788
// We define our own quaternion to use it as a buffer, since we need to pass pointers to the state
@@ -177,6 +178,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
177178
urcl::vector6d_t urcl_position_commands_;
178179
urcl::vector6d_t urcl_position_commands_old_;
179180
urcl::vector6d_t urcl_velocity_commands_;
181+
urcl::vector6d_t urcl_torque_commands_;
180182
urcl::vector6d_t urcl_joint_positions_;
181183
urcl::vector6d_t urcl_joint_velocities_;
182184
urcl::vector6d_t urcl_joint_efforts_;
@@ -305,6 +307,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
305307
std::vector<std::vector<std::string>> start_modes_;
306308
bool position_controller_running_;
307309
bool velocity_controller_running_;
310+
bool torque_controller_running_;
308311
bool force_mode_controller_running_ = false;
309312

310313
std::unique_ptr<urcl::UrDriver> ur_driver_;

ur_robot_driver/launch/ur_control.launch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def controller_spawner(controllers, active=True):
187187
"joint_trajectory_controller",
188188
"forward_velocity_controller",
189189
"forward_position_controller",
190+
"forward_effort_controller",
190191
"force_mode_controller",
191192
"passthrough_trajectory_controller",
192193
"freedrive_mode_controller",

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,37 +60,50 @@ namespace ur_robot_driver
6060
URPositionHardwareInterface::URPositionHardwareInterface()
6161
{
6262
mode_compatibility_[hardware_interface::HW_IF_POSITION][hardware_interface::HW_IF_VELOCITY] = false;
63+
mode_compatibility_[hardware_interface::HW_IF_POSITION][hardware_interface::HW_IF_EFFORT] = false;
6364
mode_compatibility_[hardware_interface::HW_IF_POSITION][FORCE_MODE_GPIO] = false;
6465
mode_compatibility_[hardware_interface::HW_IF_POSITION][PASSTHROUGH_GPIO] = false;
6566
mode_compatibility_[hardware_interface::HW_IF_POSITION][FREEDRIVE_MODE_GPIO] = false;
6667
mode_compatibility_[hardware_interface::HW_IF_POSITION][TOOL_CONTACT_GPIO] = true;
6768

6869
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][hardware_interface::HW_IF_POSITION] = false;
70+
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][hardware_interface::HW_IF_EFFORT] = false;
6971
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][FORCE_MODE_GPIO] = false;
7072
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][PASSTHROUGH_GPIO] = false;
7173
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][FREEDRIVE_MODE_GPIO] = false;
7274
mode_compatibility_[hardware_interface::HW_IF_VELOCITY][TOOL_CONTACT_GPIO] = true;
7375

76+
mode_compatibility_[hardware_interface::HW_IF_EFFORT][hardware_interface::HW_IF_POSITION] = false;
77+
mode_compatibility_[hardware_interface::HW_IF_EFFORT][hardware_interface::HW_IF_VELOCITY] = false;
78+
mode_compatibility_[hardware_interface::HW_IF_EFFORT][FORCE_MODE_GPIO] = false;
79+
mode_compatibility_[hardware_interface::HW_IF_EFFORT][PASSTHROUGH_GPIO] = false;
80+
mode_compatibility_[hardware_interface::HW_IF_EFFORT][FREEDRIVE_MODE_GPIO] = false;
81+
mode_compatibility_[hardware_interface::HW_IF_EFFORT][TOOL_CONTACT_GPIO] = true;
82+
7483
mode_compatibility_[FORCE_MODE_GPIO][hardware_interface::HW_IF_POSITION] = false;
7584
mode_compatibility_[FORCE_MODE_GPIO][hardware_interface::HW_IF_VELOCITY] = false;
85+
mode_compatibility_[FORCE_MODE_GPIO][hardware_interface::HW_IF_EFFORT] = false;
7686
mode_compatibility_[FORCE_MODE_GPIO][PASSTHROUGH_GPIO] = true;
7787
mode_compatibility_[FORCE_MODE_GPIO][FREEDRIVE_MODE_GPIO] = false;
7888
mode_compatibility_[FORCE_MODE_GPIO][TOOL_CONTACT_GPIO] = false;
7989

8090
mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_POSITION] = false;
8191
mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_VELOCITY] = false;
92+
mode_compatibility_[PASSTHROUGH_GPIO][hardware_interface::HW_IF_EFFORT] = false;
8293
mode_compatibility_[PASSTHROUGH_GPIO][FORCE_MODE_GPIO] = true;
8394
mode_compatibility_[PASSTHROUGH_GPIO][FREEDRIVE_MODE_GPIO] = false;
8495
mode_compatibility_[PASSTHROUGH_GPIO][TOOL_CONTACT_GPIO] = true;
8596

8697
mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_POSITION] = false;
8798
mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_VELOCITY] = false;
99+
mode_compatibility_[FREEDRIVE_MODE_GPIO][hardware_interface::HW_IF_EFFORT] = false;
88100
mode_compatibility_[FREEDRIVE_MODE_GPIO][FORCE_MODE_GPIO] = false;
89101
mode_compatibility_[FREEDRIVE_MODE_GPIO][PASSTHROUGH_GPIO] = false;
90102
mode_compatibility_[FREEDRIVE_MODE_GPIO][TOOL_CONTACT_GPIO] = false;
91103

92104
mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_POSITION] = true;
93105
mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_VELOCITY] = true;
106+
mode_compatibility_[TOOL_CONTACT_GPIO][hardware_interface::HW_IF_EFFORT] = true;
94107
mode_compatibility_[TOOL_CONTACT_GPIO][FORCE_MODE_GPIO] = false;
95108
mode_compatibility_[TOOL_CONTACT_GPIO][PASSTHROUGH_GPIO] = true;
96109
mode_compatibility_[TOOL_CONTACT_GPIO][FREEDRIVE_MODE_GPIO] = false;
@@ -120,6 +133,7 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
120133
urcl_velocity_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
121134
position_controller_running_ = false;
122135
velocity_controller_running_ = false;
136+
torque_controller_running_ = false;
123137
freedrive_mode_controller_running_ = false;
124138
passthrough_trajectory_controller_running_ = false;
125139
tool_contact_controller_running_ = false;
@@ -143,9 +157,9 @@ URPositionHardwareInterface::on_init(const hardware_interface::HardwareInfo& sys
143157
trajectory_joint_accelerations_.reserve(32768);
144158

145159
for (const hardware_interface::ComponentInfo& joint : info_.joints) {
146-
if (joint.command_interfaces.size() != 2) {
160+
if (joint.command_interfaces.size() != 3) {
147161
RCLCPP_FATAL(rclcpp::get_logger("URPositionHardwareInterface"),
148-
"Joint '%s' has %zu command interfaces found. 2 expected.", joint.name.c_str(),
162+
"Joint '%s' has %zu command interfaces found. 3 expected.", joint.name.c_str(),
149163
joint.command_interfaces.size());
150164
return hardware_interface::CallbackReturn::ERROR;
151165
}
@@ -328,6 +342,9 @@ std::vector<hardware_interface::CommandInterface> URPositionHardwareInterface::e
328342

329343
command_interfaces.emplace_back(hardware_interface::CommandInterface(
330344
info_.joints[i].name, hardware_interface::HW_IF_VELOCITY, &urcl_velocity_commands_[i]));
345+
346+
command_interfaces.emplace_back(hardware_interface::CommandInterface(
347+
info_.joints[i].name, hardware_interface::HW_IF_EFFORT, &urcl_torque_commands_[i]));
331348
}
332349
// Obtain the tf_prefix from the urdf so that we can have the general interface multiple times
333350
// NOTE using the tf_prefix at this point is some kind of workaround. One should actually go through the list of gpio
@@ -810,6 +827,7 @@ hardware_interface::return_type URPositionHardwareInterface::read(const rclcpp::
810827
// initialize commands
811828
urcl_position_commands_ = urcl_position_commands_old_ = urcl_joint_positions_;
812829
urcl_velocity_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
830+
urcl_torque_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
813831
target_speed_fraction_cmd_ = NO_NEW_CMD_;
814832
resend_robot_program_cmd_ = NO_NEW_CMD_;
815833
zero_ftsensor_cmd_ = NO_NEW_CMD_;
@@ -844,7 +862,8 @@ hardware_interface::return_type URPositionHardwareInterface::write(const rclcpp:
844862

845863
} else if (velocity_controller_running_) {
846864
ur_driver_->writeJointCommand(urcl_velocity_commands_, urcl::comm::ControlMode::MODE_SPEEDJ, receive_timeout_);
847-
865+
} else if (torque_controller_running_) {
866+
ur_driver_->writeJointCommand(urcl_torque_commands_, urcl::comm::ControlMode::MODE_TORQUE, receive_timeout_);
848867
} else if (freedrive_mode_controller_running_ && freedrive_activated_) {
849868
ur_driver_->writeFreedriveControlMessage(urcl::control::FreedriveControlMessage::FREEDRIVE_NOOP);
850869

@@ -1124,6 +1143,9 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
11241143
if (velocity_controller_running_) {
11251144
control_modes[i] = { hardware_interface::HW_IF_VELOCITY };
11261145
}
1146+
if (torque_controller_running_) {
1147+
control_modes[i] = { hardware_interface::HW_IF_EFFORT };
1148+
}
11271149
if (force_mode_controller_running_) {
11281150
control_modes[i].push_back(FORCE_MODE_GPIO);
11291151
}
@@ -1159,6 +1181,7 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
11591181
const std::vector<std::pair<std::string, std::string>> start_modes_to_check{
11601182
{ info_.joints[i].name + "/" + hardware_interface::HW_IF_POSITION, hardware_interface::HW_IF_POSITION },
11611183
{ info_.joints[i].name + "/" + hardware_interface::HW_IF_VELOCITY, hardware_interface::HW_IF_VELOCITY },
1184+
{ info_.joints[i].name + "/" + hardware_interface::HW_IF_EFFORT, hardware_interface::HW_IF_EFFORT },
11621185
{ tf_prefix + FORCE_MODE_GPIO + "/type", FORCE_MODE_GPIO },
11631186
{ tf_prefix + PASSTHROUGH_GPIO + "/setpoint_positions_" + std::to_string(i), PASSTHROUGH_GPIO },
11641187
{ tf_prefix + FREEDRIVE_MODE_GPIO + "/async_success", FREEDRIVE_MODE_GPIO },
@@ -1192,6 +1215,8 @@ hardware_interface::return_type URPositionHardwareInterface::prepare_command_mod
11921215
StoppingInterface::STOP_POSITION },
11931216
{ info_.joints[i].name + "/" + hardware_interface::HW_IF_VELOCITY, hardware_interface::HW_IF_VELOCITY,
11941217
StoppingInterface::STOP_VELOCITY },
1218+
{ info_.joints[i].name + "/" + hardware_interface::HW_IF_EFFORT, hardware_interface::HW_IF_EFFORT,
1219+
StoppingInterface::STOP_TORQUE },
11951220
{ tf_prefix + FORCE_MODE_GPIO + "/disable_cmd", FORCE_MODE_GPIO, StoppingInterface::STOP_FORCE_MODE },
11961221
{ tf_prefix + PASSTHROUGH_GPIO + "/setpoint_positions_" + std::to_string(i), PASSTHROUGH_GPIO,
11971222
StoppingInterface::STOP_PASSTHROUGH },
@@ -1237,6 +1262,11 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
12371262
velocity_controller_running_ = false;
12381263
urcl_velocity_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
12391264
}
1265+
if (stop_modes_[0].size() != 0 &&
1266+
std::find(stop_modes_[0].begin(), stop_modes_[0].end(), StoppingInterface::STOP_TORQUE) != stop_modes_[0].end()) {
1267+
torque_controller_running_ = false;
1268+
urcl_torque_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
1269+
}
12401270
if (stop_modes_[0].size() != 0 && std::find(stop_modes_[0].begin(), stop_modes_[0].end(),
12411271
StoppingInterface::STOP_FORCE_MODE) != stop_modes_[0].end()) {
12421272
force_mode_controller_running_ = false;
@@ -1267,16 +1297,25 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
12671297
if (start_modes_.size() != 0 && std::find(start_modes_[0].begin(), start_modes_[0].end(),
12681298
hardware_interface::HW_IF_POSITION) != start_modes_[0].end()) {
12691299
velocity_controller_running_ = false;
1300+
torque_controller_running_ = false;
12701301
passthrough_trajectory_controller_running_ = false;
12711302
urcl_position_commands_ = urcl_position_commands_old_ = urcl_joint_positions_;
12721303
position_controller_running_ = true;
12731304

12741305
} else if (start_modes_[0].size() != 0 && std::find(start_modes_[0].begin(), start_modes_[0].end(),
12751306
hardware_interface::HW_IF_VELOCITY) != start_modes_[0].end()) {
12761307
position_controller_running_ = false;
1308+
torque_controller_running_ = false;
12771309
passthrough_trajectory_controller_running_ = false;
12781310
urcl_velocity_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
12791311
velocity_controller_running_ = true;
1312+
} else if (start_modes_[0].size() != 0 && std::find(start_modes_[0].begin(), start_modes_[0].end(),
1313+
hardware_interface::HW_IF_EFFORT) != start_modes_[0].end()) {
1314+
position_controller_running_ = false;
1315+
velocity_controller_running_ = false;
1316+
torque_controller_running_ = true;
1317+
passthrough_trajectory_controller_running_ = false;
1318+
urcl_torque_commands_ = { { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 } };
12801319
}
12811320
if (start_modes_[0].size() != 0 &&
12821321
std::find(start_modes_[0].begin(), start_modes_[0].end(), FORCE_MODE_GPIO) != start_modes_[0].end()) {
@@ -1286,13 +1325,15 @@ hardware_interface::return_type URPositionHardwareInterface::perform_command_mod
12861325
std::find(start_modes_[0].begin(), start_modes_[0].end(), PASSTHROUGH_GPIO) != start_modes_[0].end()) {
12871326
velocity_controller_running_ = false;
12881327
position_controller_running_ = false;
1328+
torque_controller_running_ = false;
12891329
passthrough_trajectory_controller_running_ = true;
12901330
passthrough_trajectory_abort_ = 0.0;
12911331
}
12921332
if (start_modes_[0].size() != 0 &&
12931333
std::find(start_modes_[0].begin(), start_modes_[0].end(), FREEDRIVE_MODE_GPIO) != start_modes_[0].end()) {
12941334
velocity_controller_running_ = false;
12951335
position_controller_running_ = false;
1336+
torque_controller_running_ = false;
12961337
freedrive_mode_controller_running_ = true;
12971338
freedrive_activated_ = false;
12981339
}

0 commit comments

Comments
 (0)