Skip to content

Commit 7e93fb0

Browse files
committed
Revert "Cleanup rucking code and add simple joint limiter."
This reverts commit 916817d.
1 parent a887b8c commit 7e93fb0

File tree

1 file changed

+20
-37
lines changed

1 file changed

+20
-37
lines changed

joint_trajectory_controller/src/trajectory.cpp

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ bool Trajectory::sample(
9797

9898
// TODO(anyone): this shouldn't be initialized at runtime
9999
output_state = trajectory_msgs::msg::JointTrajectoryPoint();
100-
101100
auto & first_point_in_msg = trajectory_msg_->points[0];
102101
const rclcpp::Time first_point_timestamp =
103102
trajectory_start_time_ + first_point_in_msg.time_from_start;
@@ -172,6 +171,7 @@ bool Trajectory::sample(
172171

173172
// whole animation has played out - but still continue s interpolating and smoothing
174173
auto & last_point = trajectory_msg_->points[trajectory_msg_->points.size() - 1];
174+
const rclcpp::Time t0 = trajectory_start_time_ + last_point.time_from_start;
175175

176176
// FIXME(destogl): this is from backport - check if needed
177177
// // whole animation has played out
@@ -219,26 +219,10 @@ bool Trajectory::sample(
219219

220220
if (joint_limiter)
221221
{
222-
// When running Joint Limiter we might not get to the last_point in time - so SplineIt!
223-
interpolate_between_points(
224-
sample_time - period, previous_state_, sample_time, last_point, sample_time, output_state);
225-
226-
// if limits are enforced time of the second point is in the future
227-
if (joint_limiter->enforce(previous_state_, output_state, period))
228-
{
229-
// TODO(destogl): spline it again to avoid oscillations in output from the filter
230-
// interpolate_between_points(
231-
// sample_time-period, previous_state_, sample_time + period, output_state,
232-
// sample_time, output_state);
233-
}
234-
previous_state_ = output_state;
235-
}
236-
else
237-
{
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);
222+
// TODO(destogl): use here output state
223+
joint_limiter->enforce(previous_state_, output_state, period);
241224
}
225+
previous_state_ = output_state;
242226

243227
return true;
244228
}
@@ -252,7 +236,6 @@ void Trajectory::interpolate_between_points(
252236
rclcpp::Duration duration_btwn_points = time_b - time_a;
253237

254238
const size_t dim = state_a.positions.size();
255-
// TODO(anyone): this shouldn't be resized at runtime
256239
output.positions.resize(dim, 0.0);
257240
output.velocities.resize(dim, 0.0);
258241
output.accelerations.resize(dim, 0.0);
@@ -306,6 +289,7 @@ void Trajectory::interpolate_between_points(
306289
// do cubic interpolation
307290
double T[4];
308291
generate_powers(3, duration_btwn_points.seconds(), T);
292+
309293
for (size_t i = 0; i < dim; ++i)
310294
{
311295
double start_pos = state_a.positions[i];
@@ -412,24 +396,23 @@ void Trajectory::deduce_from_derivatives(
412396
{
413397
for (size_t i = 0; i < dim; ++i)
414398
{
415-
// reset velocities always to 0 if it is empty or NaN
416-
double first_state_velocity =
417-
first_state.velocities.empty() ? 0.0 : first_state.velocities[i];
418-
if (std::isnan(first_state_velocity))
419-
{
420-
first_state.velocities[i] = 0.0;
421-
first_state_velocity = 0.0;
422-
}
423-
double second_state_velocity =
424-
second_state.velocities.empty() ? 0.0 : second_state.velocities[i];
425-
if (std::isnan(second_state_velocity))
426-
{
427-
second_state.velocities[i] = 0.0;
428-
second_state_velocity = 0.0;
429-
}
430-
431399
if (std::isnan(second_state.positions[i]))
432400
{
401+
double first_state_velocity =
402+
first_state.velocities.empty() ? 0.0 : first_state.velocities[i];
403+
if (std::isnan(first_state_velocity))
404+
{
405+
first_state.velocities[i] = 0.0;
406+
first_state_velocity = 0.0;
407+
}
408+
double second_state_velocity =
409+
second_state.velocities.empty() ? 0.0 : second_state.velocities[i];
410+
if (std::isnan(second_state_velocity))
411+
{
412+
second_state.velocities[i] = 0.0;
413+
second_state_velocity = 0.0;
414+
}
415+
433416
second_state.positions[i] =
434417
first_state.positions[i] + (first_state_velocity + second_state_velocity) * 0.5 * delta_t;
435418
}

0 commit comments

Comments
 (0)