Skip to content

Commit 363f275

Browse files
committed
Ignore first point when time is 0
1 parent 7dd61ae commit 363f275

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

ur_controllers/src/passthrough_trajectory_controller.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,21 @@ controller_interface::return_type PassthroughTrajectoryController::update(const
265265
active_joint_traj_ = active_goal->gh_->get_goal()->trajectory;
266266

267267
if (current_index_ == 0 && current_transfer_state == TRANSFER_STATE_IDLE) {
268+
size_t traj_size = active_joint_traj_.points.size();
269+
if (active_joint_traj_.points[0].time_from_start.sec == 0 &&
270+
active_joint_traj_.points[0].time_from_start.nanosec == 0) {
271+
RCLCPP_WARN(get_node()->get_logger(),
272+
"First point of trajectory has time_from_start set to 0. This is not recommended, as it may lead "
273+
"to unexpected behavior. Removing the first point");
274+
current_index_++;
275+
traj_size--;
276+
}
268277
active_trajectory_elapsed_time_ = rclcpp::Duration(0, 0);
269278
max_trajectory_time_ =
270279
rclcpp::Duration::from_seconds(duration_to_double(active_joint_traj_.points.back().time_from_start));
271280
write_success &= transfer_command_interface_->get().set_value(TRANSFER_STATE_NEW_TRAJECTORY);
272281
write_success &=
273-
trajectory_size_command_interface_->get().set_value(static_cast<double>(active_joint_traj_.points.size()));
282+
trajectory_size_command_interface_->get().set_value(static_cast<double>(traj_size));
274283
}
275284
auto active_goal_time_tol = goal_time_tolerance_.readFromRT();
276285
auto joint_mapping = joint_trajectory_mapping_.readFromRT();
@@ -547,6 +556,17 @@ void PassthroughTrajectoryController::goal_accepted_callback(
547556
<< goal_handle->get_goal()->trajectory.points.size() << " points.");
548557
current_index_ = 0;
549558

559+
for (auto& point : goal_handle->get_goal()->trajectory.points) {
560+
std::stringstream ss;
561+
ss << "time_from_start: " << point.time_from_start.sec << "." << point.time_from_start.nanosec
562+
<< " sec, positions: " << std::setprecision(3) << std::fixed << "[";
563+
for (const auto& pos : point.positions) {
564+
ss << std::setw(8) << pos << ", ";
565+
}
566+
ss << "]";
567+
RCLCPP_INFO_STREAM(get_node()->get_logger(), ss.str());
568+
}
569+
550570
// TODO(fexner): Merge goal tolerances with default tolerances
551571

552572
joint_trajectory_mapping_.writeFromNonRT(create_joint_mapping(goal_handle->get_goal()->trajectory.joint_names));

0 commit comments

Comments
 (0)