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)
00050 {
00051 Eigen::Vector2d start_position = fun_position( *path_start );
00052 Eigen::Vector2d goal_position = fun_position( *boost::prior(path_end) );
00053
00054 double start_orient, goal_orient;
00055 if (start_orientation)
00056 {
00057 start_orient = *start_orientation;
00058 }
00059 else
00060 {
00061 Eigen::Vector2d start2goal = goal_position - start_position;
00062 start_orient = atan2(start2goal[1],start2goal[0]);
00063 }
00064 double timestep = 1;
00065
00066
00067 if (goal_orientation)
00068 {
00069 goal_orient = *goal_orientation;
00070 }
00071 else
00072 {
00073 goal_orient = start_orient;
00074 }
00075
00076 if (!isInit())
00077 {
00078 addPose(start_position, start_orient, true);
00079
00080
00081 std::advance(path_start,1);
00082 std::advance(path_end,-1);
00083 unsigned int idx=0;
00084 for (; path_start != path_end; ++path_start)
00085 {
00086
00087
00088
00089 Eigen::Vector2d curr_point = fun_position(*path_start);
00090 Eigen::Vector2d diff_last = curr_point - Pose(idx).position();
00091
00092 double diff_norm = diff_last.norm();
00093
00094 double timestep_vel = diff_norm/max_vel_x;
00095 double timestep_acc;
00096 if (max_acc_x)
00097 {
00098 timestep_acc = sqrt(2*diff_norm/(*max_acc_x));
00099 if (timestep_vel < timestep_acc && max_acc_x) timestep = timestep_acc;
00100 else timestep = timestep_vel;
00101 }
00102 else timestep = timestep_vel;
00103
00104 if (timestep<0) timestep=0.2;
00105
00106 addPoseAndTimeDiff(curr_point, atan2(diff_last[1],diff_last[0]) ,timestep);
00107
00108 Eigen::Vector2d diff_next = fun_position(*boost::next(path_start))-curr_point;
00109 double ang_diff = std::abs( g2o::normalize_theta( atan2(diff_next[1],diff_next[0])
00110 -atan2(diff_last[1],diff_last[0]) ) );
00111
00112 timestep_vel = ang_diff/max_vel_theta;
00113 if (max_acc_theta)
00114 {
00115 timestep_acc = sqrt(2*ang_diff/(*max_acc_theta));
00116 if (timestep_vel < timestep_acc) timestep = timestep_acc;
00117 else timestep = timestep_vel;
00118 }
00119 else timestep = timestep_vel;
00120
00121 if (timestep<0) timestep=0.2;
00122
00123 addPoseAndTimeDiff(curr_point, atan2(diff_last[1],diff_last[0]) ,timestep);
00124
00125 ++idx;
00126 }
00127 Eigen::Vector2d diff = goal_position-Pose(idx).position();
00128 double diff_norm = diff.norm();
00129 double timestep_vel = diff_norm/max_vel_x;
00130 if (max_acc_x)
00131 {
00132 double timestep_acc = sqrt(2*diff_norm/(*max_acc_x));
00133 if (timestep_vel < timestep_acc) timestep = timestep_acc;
00134 else timestep = timestep_vel;
00135 }
00136 else timestep = timestep_vel;
00137
00138
00139 PoseSE2 goal(goal_position, goal_orient);
00140
00141
00142 if ( (int)sizePoses() < min_samples-1 )
00143 {
00144 ROS_DEBUG("initTEBtoGoal(): number of generated samples is less than specified by min_samples. Forcing the insertion of more samples...");
00145 while ((int)sizePoses() < min_samples-1)
00146 {
00147
00148 addPoseAndTimeDiff( PoseSE2::average(BackPose(), goal), timestep );
00149 }
00150 }
00151
00152
00153 addPoseAndTimeDiff(goal, timestep);
00154 setPoseVertexFixed(sizePoses()-1,true);
00155 }
00156 else
00157 {
00158 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)!");
00159 ROS_WARN("Number of TEB configurations: %d, Number of TEB timediffs: %d",(unsigned int) sizePoses(),(unsigned int) sizeTimeDiffs());
00160 return false;
00161 }
00162 return true;
00163 }
00164
00165
00166 }
00167
00168
00169