Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

significantly improve execution time and cpu use of "sample" for large trajectories #474

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class Trajectory
rclcpp::Time time_before_traj_msg_;
trajectory_msgs::msg::JointTrajectoryPoint state_before_traj_msg_;

size_t prev_start_idx_;
jodle001 marked this conversation as resolved.
Show resolved Hide resolved
bool sampled_already_ = false;
};

Expand Down
5 changes: 4 additions & 1 deletion joint_trajectory_controller/src/trajectory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void Trajectory::update(std::shared_ptr<trajectory_msgs::msg::JointTrajectory> j
trajectory_msg_ = joint_trajectory;
trajectory_start_time_ = static_cast<rclcpp::Time>(joint_trajectory->header.stamp);
sampled_already_ = false;
prev_start_idx_ = 0;
}

bool Trajectory::sample(
Expand All @@ -80,6 +81,7 @@ bool Trajectory::sample(
trajectory_start_time_ = sample_time;
}

prev_start_idx_ = 0;
sampled_already_ = true;
}

Expand Down Expand Up @@ -120,7 +122,7 @@ bool Trajectory::sample(

// time_from_start + trajectory time is the expected arrival time of trajectory
const auto last_idx = trajectory_msg_->points.size() - 1;
for (size_t i = 0; i < last_idx; ++i)
for (size_t i = prev_start_idx_; i < last_idx; ++i)
{
auto & point = trajectory_msg_->points[i];
auto & next_point = trajectory_msg_->points[i + 1];
Expand All @@ -146,6 +148,7 @@ bool Trajectory::sample(
}
start_segment_itr = begin() + i;
end_segment_itr = begin() + (i + 1);
prev_start_idx_ = i;
return true;
}
}
Expand Down
Loading