Skip to content

Commit

Permalink
Reject old trajectories
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Lopez committed Jul 7, 2020
1 parent a923054 commit 666a79d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion joint_trajectory_controller/src/joint_trajectory_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ void JointTrajectoryController::publish_state(

if (state_publisher_ && state_publisher_->trylock()) {
last_state_publish_time_ = lifecycle_node_->now();

state_publisher_->msg_.header.stamp = last_state_publish_time_;
state_publisher_->msg_.desired.positions = desired_state.positions;
state_publisher_->msg_.desired.velocities = desired_state.velocities;
Expand Down Expand Up @@ -713,6 +712,21 @@ bool JointTrajectoryController::validate_trajectory_msg(
return false;
}

const auto trajectory_start_time = static_cast<rclcpp::Time>(trajectory.header.stamp);
if (trajectory_start_time.seconds() != 0.0) {
auto trajectory_end_time = trajectory_start_time;
for (const auto & p : trajectory.points) {
trajectory_end_time += p.time_from_start;
}
if (trajectory_end_time < lifecycle_node_->now()) {
RCLCPP_ERROR(
lifecycle_node_->get_logger(),
"Received trajectory with non zero time start time (%f) that ends on the past (%f)",
trajectory_start_time.seconds(), trajectory_end_time.seconds());
return false;
}
}

for (auto i = 0ul; i < trajectory.joint_names.size(); ++i) {
const std::string & incoming_joint_name = trajectory.joint_names[i];

Expand Down

0 comments on commit 666a79d

Please sign in to comment.