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
00033
00034
00035
00036
00037
00038
00039 #include <teb_local_planner/timed_elastic_band.h>
00040
00041 namespace teb_local_planner
00042 {
00043
00044
00045
00046 template<typename BidirIter, typename Fun>
00047 bool TimedElasticBand::initTEBtoGoal(BidirIter path_start, BidirIter path_end, Fun fun_position, double max_vel_x, double max_vel_theta,
00048 boost::optional<double> max_acc_x, boost::optional<double> max_acc_theta,
00049 boost::optional<double> start_orientation, boost::optional<double> goal_orientation, int min_samples, bool guess_backwards_motion)
00050 {
00051 Eigen::Vector2d start_position = fun_position( *path_start );
00052 Eigen::Vector2d goal_position = fun_position( *boost::prior(path_end) );
00053
00054 bool backwards = false;
00055
00056 double start_orient, goal_orient;
00057 if (start_orientation)
00058 {
00059 start_orient = *start_orientation;
00060
00061
00062 if (guess_backwards_motion && (goal_position-start_position).dot(Eigen::Vector2d(std::cos(start_orient), std::sin(start_orient))) < 0)
00063 backwards = true;
00064 }
00065 else
00066 {
00067 Eigen::Vector2d start2goal = goal_position - start_position;
00068 start_orient = atan2(start2goal[1],start2goal[0]);
00069 }
00070 double timestep = 1;
00071
00072
00073 if (goal_orientation)
00074 {
00075 goal_orient = *goal_orientation;
00076 }
00077 else
00078 {
00079 goal_orient = start_orient;
00080 }
00081
00082 if (!isInit())
00083 {
00084 addPose(start_position, start_orient, true);
00085
00086
00087 std::advance(path_start,1);
00088 std::advance(path_end,-1);
00089 int idx=0;
00090 for (; path_start != path_end; ++path_start)
00091 {
00092
00093
00094
00095 Eigen::Vector2d curr_point = fun_position(*path_start);
00096 Eigen::Vector2d diff_last = curr_point - Pose(idx).position();
00097
00098 double diff_norm = diff_last.norm();
00099
00100 double timestep_vel = diff_norm/max_vel_x;
00101 double timestep_acc;
00102 if (max_acc_x)
00103 {
00104 timestep_acc = sqrt(2*diff_norm/(*max_acc_x));
00105 if (timestep_vel < timestep_acc && max_acc_x) timestep = timestep_acc;
00106 else timestep = timestep_vel;
00107 }
00108 else timestep = timestep_vel;
00109
00110 if (timestep<0) timestep=0.2;
00111
00112 double yaw = atan2(diff_last[1],diff_last[0]);
00113 if (backwards)
00114 yaw = g2o::normalize_theta(yaw + M_PI);
00115 addPoseAndTimeDiff(curr_point, yaw ,timestep);
00116
00117 Eigen::Vector2d diff_next = fun_position(*boost::next(path_start))-curr_point;
00118 double ang_diff = std::abs( g2o::normalize_theta( atan2(diff_next[1],diff_next[0])
00119 -atan2(diff_last[1],diff_last[0]) ) );
00120
00121 timestep_vel = ang_diff/max_vel_theta;
00122 if (max_acc_theta)
00123 {
00124 timestep_acc = sqrt(2*ang_diff/(*max_acc_theta));
00125 if (timestep_vel < timestep_acc) timestep = timestep_acc;
00126 else timestep = timestep_vel;
00127 }
00128 else timestep = timestep_vel;
00129
00130 if (timestep<0) timestep=0.2;
00131
00132 yaw = atan2(diff_last[1],diff_last[0]);
00133 if (backwards)
00134 yaw = g2o::normalize_theta(yaw + M_PI);
00135 addPoseAndTimeDiff(curr_point, yaw ,timestep);
00136
00137 ++idx;
00138 }
00139 Eigen::Vector2d diff = goal_position-Pose(idx).position();
00140 double diff_norm = diff.norm();
00141 double timestep_vel = diff_norm/max_vel_x;
00142 if (max_acc_x)
00143 {
00144 double timestep_acc = sqrt(2*diff_norm/(*max_acc_x));
00145 if (timestep_vel < timestep_acc) timestep = timestep_acc;
00146 else timestep = timestep_vel;
00147 }
00148 else timestep = timestep_vel;
00149
00150
00151 PoseSE2 goal(goal_position, goal_orient);
00152
00153
00154 if ( sizePoses() < min_samples-1 )
00155 {
00156 ROS_DEBUG("initTEBtoGoal(): number of generated samples is less than specified by min_samples. Forcing the insertion of more samples...");
00157 while (sizePoses() < min_samples-1)
00158 {
00159
00160 addPoseAndTimeDiff( PoseSE2::average(BackPose(), goal), timestep );
00161 }
00162 }
00163
00164
00165 addPoseAndTimeDiff(goal, timestep);
00166 setPoseVertexFixed(sizePoses()-1,true);
00167 }
00168 else
00169 {
00170 ROS_WARN("Cannot init TEB between given configuration and goal, because TEB vectors are not empty or TEB is already initialized (call this function before adding states yourself)!");
00171 ROS_WARN("Number of TEB configurations: %d, Number of TEB timediffs: %d", sizePoses(), sizeTimeDiffs());
00172 return false;
00173 }
00174 return true;
00175 }
00176
00177
00178 }
00179
00180
00181