Go to the documentation of this file.00001 #include <trajectory_planner/c_trajectory.h>
00009 t_func_output c_trajectory::generate(vector<double> alpha_in, vector<double> arc_in, vector<double> speed_in, t_vehicle_description& vd)
00010 {
00011
00012
00013
00014
00015 if((alpha_in.size()==arc_in.size()) && (arc_in.size()==speed_in.size()))
00016 {
00017
00018
00019 double arc_sum=0;
00020 for(size_t i=0; i<alpha_in.size(); ++i)
00021 {
00022 if(abs(alpha_in[i])<=M_PI/2)
00023 {
00024 alpha.push_back(alpha_in[i]);
00025 arc.push_back(arc_in[i]);
00026 speed.push_back(speed_in[i]);
00027 arc_sum=arc_sum+arc[i];
00028 total_arc.push_back(arc_sum);
00029 }
00030 else
00031 {
00032 ROS_ERROR("Detected alpha bigger than pi/2");
00033 return FAILURE;
00034 }
00035 }
00036
00037
00038
00039
00040
00041 for(size_t i=0; i<alpha.size(); ++i)
00042 {
00043 lx.push_back((D/tan(alpha[i]))*sin(arc[i]/(D/tan(alpha[i]))));
00044 ly.push_back((D/tan(alpha[i]))-(D/tan(alpha[i]))*cos(arc[i]/(D/tan(alpha[i]))));
00045 }
00046
00047 for(size_t i=0; i<alpha.size(); ++i)
00048 {
00049
00050 double lcx = 0;
00051 double lcy = D/tan(alpha[i]);
00052
00053 if (alpha[i]>0)
00054 {
00055 ltheta.push_back (M_PI/2 + atan2(ly[i]- lcy, lx[i]- lcx));
00056 }
00057 else
00058 {
00059 ltheta.push_back (-M_PI/2 + atan2(ly[i]- lcy, lx[i]- lcx));
00060 }
00061 }
00062
00063
00064
00065
00066
00067
00068 compute_transformation();
00069
00070
00071
00072
00073
00074
00075 for(size_t i=0; i<alpha.size(); ++i)
00076 {
00077 std::vector<t_lines> v;
00078 t_lines line1;
00079
00080 line1.x[0]=x[i]-vd.lenght_back*cos(theta[i])-(vd.width/2.0)*sin(theta[i]);
00081 line1.y[0]=y[i]-vd.lenght_back*sin(theta[i])+(vd.width/2.0)*cos(theta[i]);
00082 line1.x[1]=x[i]+vd.lenght_front*cos(theta[i])-(vd.width/2.0)*sin(theta[i]);
00083 line1.y[1]=y[i]+vd.lenght_front*sin(theta[i])+(vd.width/2.0)*cos(theta[i]);
00084 v.push_back(line1);
00085
00086 line1.x[0]=x[i]+vd.lenght_front*cos(theta[i])-(vd.width/2.0)*sin(theta[i]);;
00087 line1.y[0]=y[i]+vd.lenght_front*sin(theta[i])+(vd.width/2.0)*cos(theta[i]);
00088 line1.x[1]=x[i]+vd.lenght_front*cos(theta[i])+(vd.width/2.0)*sin(theta[i]);;
00089 line1.y[1]=y[i]+vd.lenght_front*sin(theta[i])-(vd.width/2.0)*cos(theta[i]);
00090 v.push_back(line1);
00091
00092 line1.x[0]=x[i]+vd.lenght_front*cos(theta[i])+(vd.width/2.0)*sin(theta[i]);;
00093 line1.y[0]=y[i]+vd.lenght_front*sin(theta[i])-(vd.width/2.0)*cos(theta[i]);
00094 line1.x[1]=x[i]-vd.lenght_back*cos(theta[i])+(vd.width/2.0)*sin(theta[i]);;
00095 line1.y[1]=y[i]-vd.lenght_back*sin(theta[i])-(vd.width/2.0)*cos(theta[i]);
00096 v.push_back(line1);
00097
00098 line1.x[0]=x[i]-vd.lenght_back*cos(theta[i])+(vd.width/2.0)*sin(theta[i]);;
00099 line1.y[0]=y[i]-vd.lenght_back*sin(theta[i])-(vd.width/2.0)*cos(theta[i]);
00100 line1.x[1]=x[i]-vd.lenght_back*cos(theta[i])-(vd.width/2.0)*sin(theta[i]);;
00101 line1.y[1]=y[i]-vd.lenght_back*sin(theta[i])+(vd.width/2.0)*cos(theta[i]);
00102 v.push_back(line1);
00103
00104 v_lines.push_back(v);
00105 }
00106
00107 return SUCCESS;
00108 }
00109 else
00110 {
00111 ROS_ERROR("Input vector dimensions mismatch");
00112 return FAILURE;
00113 }
00114 }
00115
00116
00122 t_func_output c_trajectory::compute_transformation()
00123 {
00124
00125 pcl::PointCloud<pcl::PointXYZ> ponto_teste, ponto_result;
00126 ltrans.clear();
00127 theta.push_back(ltheta[0]);
00128 for(size_t i=0; i<alpha.size(); ++i)
00129 {
00130 tf::Transform transform;
00131 transform.setOrigin(tf::Vector3(lx[i], ly[i], 0));
00132 transform.setRotation(tf::createQuaternionFromRPY(0, 0, ltheta[i]));
00133 ltrans.push_back(transform);
00134
00135 pcl::PointXYZ pt1(0,0,0);
00136 ponto_teste.points.push_back(pt1);
00137
00138 for(int j=i;j>=0;--j)
00139 {
00140 pcl_ros::transformPointCloud(ponto_teste, ponto_result, ltrans[j]);
00141
00142 if(j==0)
00143 {
00144 x.push_back(ponto_result.points[0].x);
00145 y.push_back(ponto_result.points[0].y);
00146 ponto_result.clear();
00147 ponto_teste.clear();
00148 }
00149 else
00150 {
00151 ponto_teste.clear();
00152 ponto_teste.points.push_back(ponto_result.points[0]);
00153 ponto_result.clear();
00154 }
00155 }
00156
00157 if(i!=0)
00158 {
00159 double theta_provi=theta[i-1]+ltheta[i];
00160 while(theta_provi<-M_PI)
00161 {
00162 theta_provi=2*M_PI-abs(theta_provi);
00163 }
00164 while(theta_provi>M_PI)
00165 {
00166 theta_provi=theta_provi-2*M_PI;
00167 }
00168 theta.push_back(theta_provi);
00169 }
00170
00171 }
00172 return SUCCESS;
00173 }
00174
00175
00183 void c_trajectory::create_markers(std::vector<visualization_msgs::Marker>* marker_vec, int* marker_count, int num_traj)
00184 {
00185
00186 visualization_msgs::Marker marker,marker2;
00187 geometry_msgs::Point p,pp;
00188 std_msgs::ColorRGBA color;
00189
00190
00191
00192
00193
00194
00195
00196 marker.header.frame_id = "/parking_frame";
00197 marker.header.stamp = ros::Time::now();
00198 marker.ns = "lines";
00199 marker.id = num_traj;
00200 marker.action = visualization_msgs::Marker::ADD;
00201 marker.type = visualization_msgs::Marker::LINE_LIST;
00202 marker.scale.x = 0.01;
00203 marker.color.r = 0.0;
00204 marker.color.g = 0.7;
00205 marker.color.b = 0.0;
00206 marker.color.a = 1.0;
00207 int first_step=1;
00208 for(size_t i=0; i<alpha.size(); ++i)
00209 {
00210 if(first_step==1)
00211 {
00212 p.x = 0;
00213 p.y = 0;
00214 p.z = 0;
00215 marker.points.push_back(p);
00216 p.x = x[i];
00217 p.y = y[i];
00218 p.z = 0;
00219 marker.points.push_back(p);
00220 first_step=0;
00221 }
00222 else
00223 {
00224 p.x = x[i-1];
00225 p.y = y[i-1];
00226 p.z = 0;
00227 marker.points.push_back(p);
00228 p.x = x[i];
00229 p.y = y[i];
00230 p.z = 0;
00231 marker.points.push_back(p);
00232 }
00233 }
00234 marker_vec->push_back(marker);
00235
00236
00237
00238
00239
00240
00241 marker.header.frame_id = "/parking_frame";
00242 marker.header.stamp = ros::Time::now();
00243 marker.ns = "nodes";
00244 marker.action = visualization_msgs::Marker::ADD;
00245 marker.type = visualization_msgs::Marker::CUBE;
00246 marker.pose.orientation.x = 0.0;
00247 marker.pose.orientation.y = 0.0;
00248 marker.pose.orientation.z = 0.0;
00249 marker.pose.orientation.w = 1.0;
00250 marker.scale.x = 0.03;
00251 marker.scale.y = 0.03;
00252 marker.scale.z = 0.03;
00253 marker.color.r = 0.0;
00254 marker.color.g = 0.0;
00255 marker.color.b = 1.0;
00256 marker.color.a = 1.0;
00257 for(size_t i=0; i<alpha.size(); ++i)
00258 {
00259 marker.id = (*marker_count)++;
00260 marker.pose.position.x = x[i];
00261 marker.pose.position.y = y[i];
00262 marker.pose.position.z = 0;
00263 marker_vec->push_back(marker);
00264 }
00265
00266
00267
00268
00269
00270
00271 marker.header.frame_id = "/parking_frame";
00272 marker.header.stamp = ros::Time::now();
00273 marker.ns = "node_number";
00274 marker.action = visualization_msgs::Marker::ADD;
00275 marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00276 marker.pose.orientation.x = 0.0;
00277 marker.pose.orientation.y = 0.0;
00278 marker.pose.orientation.z = 0.0;
00279 marker.pose.orientation.w = 1.0;
00280 marker.scale.z = 0.15;
00281 marker.color.r = 0.0;
00282 marker.color.g = 0.0;
00283 marker.color.b = 0.2;
00284 marker.color.a = 1.0;
00285 for(size_t i=0; i<alpha.size(); ++i)
00286 {
00287 marker.id = (*marker_count)++;
00288 marker.pose.position.x = x[i];
00289 marker.pose.position.y = y[i];
00290 marker.pose.position.z = 0.075;
00291 char str[1024];
00292 sprintf(str,"%ld",i);
00293 marker.text = str;
00294 marker_vec->push_back(marker);
00295 }
00296
00297
00298
00299
00300
00301
00302 marker.header.frame_id = "/parking_frame";
00303 marker.header.stamp = ros::Time::now();
00304 marker.ns = "trajectory_number";
00305 marker.action = visualization_msgs::Marker::ADD;
00306 marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
00307 marker.pose.orientation.x = 0.0;
00308 marker.pose.orientation.y = 0.0;
00309 marker.pose.orientation.z = 0.0;
00310 marker.pose.orientation.w = 1.0;
00311 marker.scale.z = 0.2;
00312 marker.color.r = 0.0;
00313 marker.color.g = 0.0;
00314 marker.color.b = 1.0;
00315 marker.color.a = 1.0;
00316 marker.id = (*marker_count)++;
00317 marker.pose.position.x = x[x.size()-1];
00318 marker.pose.position.y = y[y.size()-1];
00319 marker.pose.position.z = 0.2;
00320 marker.text = "Traj " + str( boost::format("%d") % (num_traj));
00321 marker_vec->push_back(marker);
00322
00323
00324
00325
00326
00327
00328 marker.header.frame_id = "/parking_frame";
00329 marker.header.stamp = ros::Time::now();
00330 marker.ns = "Orientation arrow";
00331 marker.action = visualization_msgs::Marker::ADD;
00332 marker.type = visualization_msgs::Marker::ARROW;
00333 marker.color.r = 1.0;
00334 marker.color.g = 0.0;
00335 marker.color.b = 0.0;
00336 marker.color.a = 1.0;
00337 marker.scale.x=0.3;
00338 marker.scale.y=0.3;
00339 marker.scale.z=0.3;
00340 for(size_t i=0; i<alpha.size(); ++i)
00341 {
00342 marker.id = (*marker_count)++;
00343 marker.pose.position.x = x[i];
00344 marker.pose.position.y = y[i];
00345 marker.pose.position.z = 0;
00346 marker.pose.orientation.z = sin(theta[i]/2);
00347 marker.pose.orientation.w = cos(theta[i]/2);
00348 marker_vec->push_back(marker);
00349 }
00350
00351
00352
00353
00354
00355
00356 marker.header.frame_id = "/parking_frame";
00357 marker.header.stamp = ros::Time::now();
00358 marker.ns = "car shadow";
00359 marker.action = visualization_msgs::Marker::ADD;
00360 marker.type = visualization_msgs::Marker::CUBE;
00361 marker.scale.x = 0.8;
00362 marker.scale.y = 0.42;
00363 marker.scale.z = 0.05;
00364 marker.color.r = 0.25;
00365 marker.color.g = 0.41;
00366 marker.color.b = 0.88;
00367 marker.color.a = 0.1;
00368 for(size_t i=0; i<alpha.size(); ++i)
00369 {
00370 marker.id = (*marker_count)++;
00371 marker.pose.position.x = x[i]+0.2*cos(theta[i]);
00372 marker.pose.position.y = y[i]+0.2*sin(theta[i]);
00373 marker.pose.position.z = 0;
00374 marker.pose.orientation.z = sin(theta[i]/2);
00375 marker.pose.orientation.w = cos(theta[i]/2);
00376 marker_vec->push_back(marker);
00377 }
00378
00379
00380
00381
00382
00383
00384
00385 marker2.header.frame_id = "/parking_frame";
00386 marker2.header.stamp = ros::Time::now();
00387 marker2.ns = "car contour";
00388 marker2.id = (*marker_count)++;
00389 marker2.action = visualization_msgs::Marker::ADD;
00390 marker2.type = visualization_msgs::Marker::LINE_LIST;
00391 marker2.scale.x = 0.01;
00392 marker2.color.r = 0.5;
00393 marker2.color.g = 0.5;
00394 marker2.color.b = 1.0;
00395 marker2.color.a = 0.5;
00396 for(size_t i=0; i<alpha.size(); ++i)
00397 {
00398 for(size_t l=0;l<v_lines[i].size();l++)
00399 {
00400 pp.x = v_lines[i][l].x[0];
00401 pp.y = v_lines[i][l].y[0];
00402 pp.z = 0;
00403 marker2.points.push_back(pp);
00404
00405 pp.x = v_lines[i][l].x[1];
00406 pp.y = v_lines[i][l].y[1];
00407 pp.z = 0;
00408 marker2.points.push_back(pp);
00409 }
00410 marker_vec->push_back(marker2);
00411 }
00412 }