Skip to content

Commit 1305057

Browse files
committed
Fix JTC crashes
1 parent 94abd56 commit 1305057

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

joint_trajectory_controller/src/trajectory.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ bool Trajectory::sample(
143143
const rclcpp::Time t0 = trajectory_start_time_ + point.time_from_start;
144144
const rclcpp::Time t1 = trajectory_start_time_ + next_point.time_from_start;
145145

146-
if (sample_time >= t0 && sample_time < t1)
146+
if (sample_time >= t0 && sample_time <= t1)
147147
{
148148
// If interpolation is disabled, just forward the next waypoint
149149
if (interpolation_method == interpolation_methods::InterpolationMethod::NONE)
@@ -174,10 +174,6 @@ bool Trajectory::sample(
174174
auto & last_point = trajectory_msg_->points[trajectory_msg_->points.size() - 1];
175175

176176
// FIXME(destogl): this is from backport - check if needed
177-
// // whole animation has played out
178-
// start_segment_itr = --end();
179-
// end_segment_itr = end();
180-
// expected_state = (*start_segment_itr);
181177
//
182178
// // TODO: Add and test enforceJointLimits? Unsure if needed for end of animation
183179
// // Yes, call enforceJointLimits to handle halting in servo, which has time_from_start == 1ns
@@ -235,9 +231,15 @@ bool Trajectory::sample(
235231
}
236232
else
237233
{
238-
const rclcpp::Time t0 = trajectory_start_time_ + last_point.time_from_start;
239-
// do not do splines when trajectory has finished because the time is achieved
240-
interpolate_between_points(t0, last_point, t0, last_point, sample_time, output_state);
234+
// OLD: the following 3 lines --> maybe to delete
235+
// const rclcpp::Time t0 = trajectory_start_time_ + last_point.time_from_start;
236+
// // do not do splines when trajectory has finished because the time is achieved
237+
// interpolate_between_points(t0, last_point, t0, last_point, sample_time, output_state);
238+
239+
// whole animation has played out
240+
start_segment_itr = --end();
241+
end_segment_itr = end();
242+
output_state = (*start_segment_itr);
241243
}
242244

243245
return true;

joint_trajectory_controller/test/test_trajectory.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ TEST(TestTrajectory, sample_trajectory_positions)
196196
start, end, rclcpp::Duration::from_seconds(0.1), joint_limiter_);
197197
ASSERT_EQ((--traj.end()), start);
198198
ASSERT_EQ(traj.end(), end);
199+
std::cout << "Expected state size: " << expected_state.positions.size() << std::endl;
199200
EXPECT_NEAR(p3.positions[0], expected_state.positions[0], EPS);
200201
}
201202

@@ -477,17 +478,17 @@ TEST(TestTrajectory, sample_trajectory_velocity_with_interpolation)
477478
EXPECT_NEAR(position_third_seg, expected_state.positions[0], EPS);
478479
EXPECT_NEAR(p3.velocities[0], expected_state.velocities[0], EPS);
479480
// the goal is reached so no acceleration anymore
480-
EXPECT_NEAR(0, expected_state.accelerations[0], EPS);
481+
EXPECT_NEAR(0.0, expected_state.accelerations[0], EPS);
481482
}
482483

483-
// sample past given points - movement virtually stops
484+
// sample past given points - if there is velocity continue sampling
484485
{
485486
traj.sample(
486487
time_now + rclcpp::Duration::from_seconds(3.125), DEFAULT_INTERPOLATION, expected_state,
487488
start, end, rclcpp::Duration::from_seconds(0.1), joint_limiter_);
488489
EXPECT_EQ((--traj.end()), start);
489490
EXPECT_EQ(traj.end(), end);
490-
EXPECT_NEAR(position_third_seg, expected_state.positions[0], EPS);
491+
EXPECT_NEAR(position_third_seg + p3.velocities[0] * 0.1, expected_state.positions[0], EPS);
491492
EXPECT_NEAR(p3.velocities[0], expected_state.velocities[0], EPS);
492493
EXPECT_NEAR(0.0, expected_state.accelerations[0], EPS);
493494
}

0 commit comments

Comments
 (0)