Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <arm_navigation_msgs/FilterJointTrajectoryWithConstraints.h>
00033 #include <industrial_trajectory_filters/n_point_filter.h>
00034
00035 using namespace industrial_trajectory_filters;
00036
00037 const int DEFAULT_N=2;
00038
00039
00040 template <typename T>
00041 NPointFilter<T>::NPointFilter()
00042 {
00043 ROS_INFO_STREAM("Constructing N point filter");
00044 n_points_ = DEFAULT_N;
00045 }
00046
00047 template <typename T>
00048 NPointFilter<T>::~NPointFilter()
00049 {}
00050
00051 template <typename T>
00052 bool NPointFilter<T>::configure()
00053 {
00054 if (!filters::FilterBase<T>::getParam("n_points", n_points_))
00055 {
00056 ROS_WARN_STREAM("NPointFilter, params has no attribute n_points.");
00057 }
00058 if (n_points_ < 2)
00059 {
00060 ROS_WARN_STREAM("n_points attribute less than min(2), setting to minimum");
00061 n_points_ = 2;
00062 }
00063 ROS_INFO_STREAM("Using a n_points value of " << n_points_);
00064
00065 return true;
00066 }
00067
00068
00069 template <typename T>
00070 bool NPointFilter<T>::update(const T& trajectory_in,
00071 T& trajectory_out)
00072 {
00073 bool success = false;
00074 int size_in = trajectory_in.request.trajectory.points.size();
00075
00076
00077 trajectory_out = trajectory_in;
00078
00079 trajectory_out.request.trajectory.points.clear();
00080
00081 if (size_in > n_points_)
00082 {
00083
00084 trajectory_out.request.trajectory.points.push_back(
00085 trajectory_in.request.trajectory.points.front());
00086
00087 int intermediate_points = n_points_ - 2;
00088 double int_point_increment = double(size_in)/double(intermediate_points + 1.0);
00089 ROS_INFO_STREAM("Number of intermediate points: " << intermediate_points <<
00090 ", increment: " << int_point_increment);
00091
00092
00093
00094
00095
00096
00097
00098 for (int i = 1; i <= intermediate_points; i++)
00099 {
00100 int int_point_index = int(double(i) * int_point_increment);
00101 ROS_INFO_STREAM("Intermediate point index: " << int_point_index);
00102 trajectory_out.request.trajectory.points.push_back(
00103 trajectory_in.request.trajectory.points[int_point_index]);
00104 }
00105
00106
00107 trajectory_out.request.trajectory.points.push_back(
00108 trajectory_in.request.trajectory.points.back());
00109
00110 ROS_INFO_STREAM("Filtered trajectory from: " << trajectory_in.request.trajectory.points.size()
00111 << " to: " << trajectory_out.request.trajectory.points.size());
00112
00113 success = true;
00114 }
00115 else
00116 {
00117 ROS_WARN_STREAM("Trajectory size less than n: " << n_points_ << ", pass through");
00118 trajectory_out = trajectory_in;
00119 success = true;
00120 }
00121
00122 return success;
00123 }
00124
00125
00126
00127 PLUGINLIB_DECLARE_CLASS(industrial_trajectory_filters,
00128 IndustrialNPointFilterJointTrajectoryWithConstraints,
00129 industrial_trajectory_filters::NPointFilter<arm_navigation_msgs::FilterJointTrajectoryWithConstraints>,
00130 filters::FilterBase<arm_navigation_msgs::FilterJointTrajectoryWithConstraints>);
00131