60 ROS_WARN_STREAM(
"UniformSampleFilter, params has no attribute sample_duration.");
71 size_t size_in = trajectory_in.request.trajectory.points.size();
72 double duration_in = trajectory_in.request.trajectory.points.back().time_from_start.toSec();
73 double interpolated_time = 0.0;
76 trajectory_msgs::JointTrajectoryPoint p1, p2, interp_pt;
78 trajectory_out = trajectory_in;
81 trajectory_out.request.trajectory.points.clear();
83 while (interpolated_time < duration_in)
87 while (interpolated_time > trajectory_in.request.trajectory.points[index_in + 1].time_from_start.toSec())
90 "Interpolated time: " << interpolated_time <<
", next point time: " << (trajectory_in.request.trajectory.points[index_in + 1].time_from_start.toSec()));
93 if (index_in >= size_in)
96 "Programming error, index: " << index_in <<
", greater(or equal) to size: " << size_in <<
" input duration: " << duration_in <<
" interpolated time:)" << interpolated_time);
100 p1 = trajectory_in.request.trajectory.points[index_in];
101 p2 = trajectory_in.request.trajectory.points[index_in + 1];
107 trajectory_out.request.trajectory.points.push_back(interp_pt);
114 "Interpolated time exceeds original trajectory (quitting), original: " << duration_in <<
" final interpolated time: " << interpolated_time);
115 p2 = trajectory_in.request.trajectory.points.back();
120 trajectory_out.request.trajectory.points.push_back(p2);
123 "Uniform sampling, resample duraction: " <<
sample_duration_ <<
" input traj. size: " << trajectory_in.request.trajectory.points.size() <<
" output traj. size: " << trajectory_out.request.trajectory.points.size());
130 trajectory_msgs::JointTrajectoryPoint & p2,
double time_from_start,
131 trajectory_msgs::JointTrajectoryPoint & interp_pt)
134 double p1_time_from_start = p1.time_from_start.toSec();
135 double p2_time_from_start = p2.time_from_start.toSec();
139 if (time_from_start >= p1_time_from_start && time_from_start <= p2_time_from_start)
141 if (p1.positions.size() == p1.velocities.size() && p1.positions.size() == p1.accelerations.size())
143 if (p1.positions.size() == p2.positions.size() && p1.velocities.size() == p2.velocities.size()
144 && p1.accelerations.size() == p2.accelerations.size())
148 ROS_DEBUG_STREAM(
"---------------Begin interpolating joint point---------------");
150 for (
size_t i = 0; i < p1.positions.size(); ++i)
152 double time_from_p1 = time_from_start - p1.time_from_start.toSec();
153 double time_from_p1_to_p2 = p2_time_from_start - p1_time_from_start;
161 interp_pt.time_from_start = time_from_start_dur;
162 interp_pt.velocities[i] = p1.velocities[i] + (p2.velocities[i] - p1.velocities[i]) / time_from_p1_to_p2 * time_from_p1;
163 double acc = (p2.velocities[i] - p1.velocities[i]) / time_from_p1_to_p2;
164 interp_pt.positions[i] = p1.positions[i] + p1.velocities[i] * time_from_p1 + acc * time_from_p1 * time_from_p1 / 2.0;
165 interp_pt.accelerations[i] = p1.accelerations[i];
168 "p1.pos: " << p1.positions[i] <<
", vel: " << p1.velocities[i] <<
", acc: " << p1.accelerations[i] <<
", tfs: " << p1.time_from_start);
171 "p2.pos: " << p2.positions[i] <<
", vel: " << p2.velocities[i] <<
", acc: " << p2.accelerations[i] <<
", tfs: " << p2.time_from_start);
174 "interp_pt.pos: " << interp_pt.positions[i] <<
", vel: " << interp_pt.velocities[i] <<
", acc: " << interp_pt.accelerations[i] <<
", tfs: " << interp_pt.time_from_start);
176 ROS_DEBUG_STREAM(
"---------------End interpolating joint point---------------");
183 "Trajectory point 1, pos: " << p1.positions.size() <<
" vel: " << p1.velocities.size() <<
" acc: " << p1.accelerations.size());
185 "Trajectory point 2, pos: " << p2.positions.size() <<
" vel: " << p2.velocities.size() <<
" acc: " << p2.accelerations.size());
193 "Trajectory point not fully defined, pos: " << p1.positions.size() <<
" vel: " << p1.velocities.size() <<
" acc: " << p1.accelerations.size());
200 "Time: " << time_from_start <<
" not between interpolation point times[" << p1.time_from_start.toSec() <<
"," << p2.time_from_start.toSec() <<
"]");
SimpleResampleFilter()
Default constructor.
~SimpleResampleFilter()
Default destructor.
bool update(const T &trajectory_in, T &trajectory_out)
ros::NodeHandle nh_
Internal node handle (used for parameter lookup)
std::string filter_name_
filter name
CLASS_LOADER_REGISTER_CLASS(fsrobo_r_trajectory_filters::SimpleResampleFilterAdapter, planning_request_adapter::PlanningRequestAdapter)
double sample_duration_
uniform sample duration (sec)
This version of the FilterBase<T> can be used to encapsulate the functionality from an arm navigation...
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
virtual bool configure()
FilterBase method for the sub class to configure the filter This function must be implemented in the ...
This is a simple filter which performs a uniforming sampling of a trajectory using linear interpolati...
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
bool interpolatePt(trajectory_msgs::JointTrajectoryPoint &p1, trajectory_msgs::JointTrajectoryPoint &p2, double time_from_start, trajectory_msgs::JointTrajectoryPoint &interp_pt)
Perform interpolation between p1 and p2. Time from start must be in between p1 and p2 times...
const double DEFAULT_SAMPLE_DURATION
#define ROS_ERROR_STREAM(args)