Skip to content

Commit b48415b

Browse files
committed
Catch two faulty cases and print an error instead
1 parent a5f3e63 commit b48415b

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

ur_robot_driver/include/ur_robot_driver/hardware_interface.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ class URPositionHardwareInterface : public hardware_interface::SystemInterface
167167
void stop_force_mode();
168168
void check_passthrough_trajectory_controller();
169169
void trajectory_done_callback(urcl::control::TrajectoryResult result);
170-
bool has_accelerations(std::vector<std::array<double, 6>> accelerations);
171-
bool has_velocities(std::vector<std::array<double, 6>> velocities);
170+
bool is_valid_joint_information(std::vector<std::array<double, 6>> data);
172171

173172
urcl::vector6d_t urcl_position_commands_;
174173
urcl::vector6d_t urcl_position_commands_old_;

ur_robot_driver/src/hardware_interface.cpp

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,20 +1392,42 @@ void URPositionHardwareInterface::check_passthrough_trajectory_controller()
13921392
// already received down to the hardware.
13931393
if (trajectory_started && point_index_sent <= trajectory_joint_positions_.size() &&
13941394
point_index_sent < point_index_received) {
1395+
bool error = false;
13951396
/* Write the appropriate type of point depending on the combination of positions, velocities and accelerations. */
13961397
for (size_t i = point_index_sent; i < point_index_received; i++) {
1397-
if (!has_velocities(trajectory_joint_velocities_) && !has_accelerations(trajectory_joint_accelerations_)) {
1398-
ur_driver_->writeTrajectorySplinePoint(trajectory_joint_positions_[i], urcl::vector6d_t{ 0, 0, 0, 0, 0, 0 },
1399-
trajectory_times_[i]);
1400-
} else if (has_velocities(trajectory_joint_velocities_) && !has_accelerations(trajectory_joint_accelerations_)) {
1401-
ur_driver_->writeTrajectorySplinePoint(trajectory_joint_positions_[i], trajectory_joint_velocities_[i],
1402-
trajectory_times_[i]);
1403-
} else if (has_velocities(trajectory_joint_velocities_) && has_accelerations(trajectory_joint_accelerations_)) {
1404-
ur_driver_->writeTrajectorySplinePoint(trajectory_joint_positions_[i], trajectory_joint_velocities_[i],
1405-
trajectory_joint_accelerations_[i], trajectory_times_[i]);
1398+
if (is_valid_joint_information(trajectory_joint_positions_)) {
1399+
if (!is_valid_joint_information(trajectory_joint_velocities_) &&
1400+
!is_valid_joint_information(trajectory_joint_accelerations_)) {
1401+
ur_driver_->writeTrajectorySplinePoint(trajectory_joint_positions_[i], urcl::vector6d_t{ 0, 0, 0, 0, 0, 0 },
1402+
trajectory_times_[i]);
1403+
} else if (is_valid_joint_information(trajectory_joint_velocities_) &&
1404+
!is_valid_joint_information(trajectory_joint_accelerations_)) {
1405+
ur_driver_->writeTrajectorySplinePoint(trajectory_joint_positions_[i], trajectory_joint_velocities_[i],
1406+
trajectory_times_[i]);
1407+
} else if (!is_valid_joint_information(trajectory_joint_velocities_) &&
1408+
is_valid_joint_information(trajectory_joint_accelerations_)) {
1409+
RCLCPP_ERROR(get_logger(), "Accelerations but no velocities given. If you want to specify accelerations with "
1410+
"a 0 velocity, please do that explicitly.");
1411+
error = true;
1412+
break;
1413+
1414+
} else if (is_valid_joint_information(trajectory_joint_velocities_) &&
1415+
is_valid_joint_information(trajectory_joint_accelerations_)) {
1416+
ur_driver_->writeTrajectorySplinePoint(trajectory_joint_positions_[i], trajectory_joint_velocities_[i],
1417+
trajectory_joint_accelerations_[i], trajectory_times_[i]);
1418+
}
1419+
} else {
1420+
RCLCPP_ERROR(get_logger(), "Trajectory points without position information are not supported.");
1421+
error = true;
1422+
break;
14061423
}
14071424
point_index_sent++;
14081425
}
1426+
if (error) {
1427+
passthrough_trajectory_abort_ = 1.0;
1428+
passthrough_trajectory_transfer_state_ = 5.0;
1429+
return;
1430+
}
14091431
}
14101432
}
14111433

@@ -1420,14 +1442,9 @@ void URPositionHardwareInterface::trajectory_done_callback(urcl::control::Trajec
14201442
return;
14211443
}
14221444

1423-
bool URPositionHardwareInterface::has_velocities(std::vector<std::array<double, 6>> velocities)
1424-
{
1425-
return (velocities.size() > 0 && !std::isnan(velocities[0][0]));
1426-
}
1427-
1428-
bool URPositionHardwareInterface::has_accelerations(std::vector<std::array<double, 6>> accelerations)
1445+
bool URPositionHardwareInterface::is_valid_joint_information(std::vector<std::array<double, 6>> data)
14291446
{
1430-
return (accelerations.size() > 0 && !std::isnan(accelerations[0][0]));
1447+
return (data.size() > 0 && !std::isnan(data[0][0]));
14311448
}
14321449

14331450
} // namespace ur_robot_driver

0 commit comments

Comments
 (0)