utest.cpp
Go to the documentation of this file.
00001 #include <cmath>
00002 #include <limits>
00003 #include <fstream>
00004 #include <iostream>
00005 #include <sstream>
00006 #include <stdexcept> // std::invalid_argument
00007 #include <vector>
00008 
00009 #include <gtest/gtest.h>
00010 #include <rosbag/bag.h>
00011 
00012 #include <angles/angles.h>
00013 #include <geometry_msgs/Point32.h>
00014 #include <sensor_msgs/LaserScan.h>
00015 
00016 #include <lama_common/place_profile_conversions.h>
00017 
00018 #include <crossing_detector/laser_crossing_detector.h>
00019 
00020 PlaceProfile loadFromString(std::stringstream& sstream)
00021 {
00022   PlaceProfile profile;
00023   
00024   sensor_msgs::LaserScan scan;
00025   scan.angle_min = std::numeric_limits<float>::max();
00026   double last_angle;
00027   do
00028   {
00029     double x;
00030     double y;
00031     sstream >> x >> y;
00032     if (!sstream.eof())
00033     {
00034       const double angle = std::atan2(y, x);
00035       if (scan.angle_min == std::numeric_limits<float>::max())
00036       {
00037         scan.angle_min = angle;
00038       }
00039       const size_t n = scan.ranges.size();
00040       if (n != 0)
00041       {
00042         const float dangle = angles::shortest_angular_distance(last_angle, angle);
00043         if (n > 1)
00044         {
00045           if (std::abs(dangle) < 0.999 * std::abs(scan.angle_increment) || std::abs(dangle) > 1.001 * std::abs(scan.angle_increment))
00046           {
00047             std::cerr << "Angles do not vary constantly.\n";
00048           }
00049         }
00050         scan.angle_increment = (scan.angle_increment * (n - 1) + dangle) / n;
00051       }
00052       
00053       const double range = std::sqrt(x * x + y * y);
00054       scan.ranges.push_back(range);
00055       last_angle = angle;
00056     }
00057   } while (!sstream.eof());
00058   scan.angle_max = scan.angle_min + scan.angle_increment * (scan.ranges.size() - 1);
00059 
00060   profile = lama_common::laserScanToPlaceProfile(scan, 4);
00061   return profile;
00062 }
00063 
00064 void saveToFile(const std::string& filename, const PlaceProfile& profile)
00065 {
00066   std::ofstream fout(filename.c_str());
00067   if (!fout.is_open())
00068   {
00069     std::cerr << "\"" << filename << "\" cannot be opened for writing";
00070     return;
00071   }
00072   std::vector<geometry_msgs::Point32>::const_iterator it = profile.polygon.points.begin();
00073   for (; it < profile.polygon.points.end(); ++it)
00074   {
00075     fout << it->x << " " << it->y << "\n";
00076   }
00077 }
00078 
00079 void saveToFile(const std::string& filename, const lama_msgs::Crossing& crossing)
00080 {
00081   rosbag::Bag bag;
00082   bag.open(filename, rosbag::bagmode::Write);
00083 
00084   bag.write("empty", ros::Time::now(), crossing);
00085 
00086   bag.close();
00087 }
00088   
00089 geometry_msgs::Point32 point(double x, double y)
00090 {
00091   geometry_msgs::Point32 point;
00092   point.x = x;
00093   point.y = y;
00094   return point;
00095 }
00096 
00097 std::vector<geometry_msgs::Point32> interpolate(const geometry_msgs::Point32& a, const geometry_msgs::Point32 b, double max_distance)
00098 {
00099   std::vector<geometry_msgs::Point32> points;
00100 
00101   const double dx = b.x - a.x;
00102   const double dy = b.y - a.y;
00103 
00104   geometry_msgs::Point32 point;
00105   const double norm = std::sqrt(dx * dx + dy * dy);
00106   if (norm == 0)
00107   {
00108     points.push_back(a);
00109     return points;
00110   }
00111 
00112   // Unit vector from a to b.
00113   const double ux = dx / norm;
00114   const double uy = dy / norm;
00115   for (double s = 0; s <= norm; s += max_distance) 
00116   {
00117     point.x = a.x + s * ux;
00118     point.y = a.y + s * uy;
00119     points.push_back(point);
00120   }
00121   return points;
00122 }
00123 
00136 PlaceProfile profileFrontierAngle(double angle, double& frontier_angle)
00137 {
00138   PlaceProfile profile;
00139 
00140   const double length_p1p2 = 1;
00141   geometry_msgs::Point32 p0 = point(2, 2);
00142   geometry_msgs::Point32 p1 = point(1, p0.y);
00143   geometry_msgs::Point32 p2;
00144   p2.x = p1.x + length_p1p2 * std::cos(angle);
00145   p2.y = p1.y + length_p1p2 * std::sin(angle);
00146   geometry_msgs::Point32 p3 = point(-1, p2.y);
00147   geometry_msgs::Point32 p4 = point(p3.x, -2);
00148   geometry_msgs::Point32 p5 = point(p0.x, p4.y);
00149 
00150   const double angle_p1 = std::atan2(p1.y, p1.x);
00151   const double angle_p2 = std::atan2(p2.y, p2.x);
00152   if (angle_p1 > angle_p2)
00153   {
00154     throw std::invalid_argument("Wrong angle");
00155   }
00156 
00157   std::vector<geometry_msgs::Point32> points;
00158   points = interpolate(p0, p1, 0.1);
00159   std::copy(points.begin(), points.end(), std::back_inserter(profile.polygon.points));
00160   points = interpolate(p2, p3, 0.1);
00161   std::copy(points.begin(), points.end(), std::back_inserter(profile.polygon.points));
00162   points = interpolate(p3, p4, 0.1);
00163   std::copy(points.begin(), points.end(), std::back_inserter(profile.polygon.points));
00164   points = interpolate(p4, p5, 0.1);
00165   std::copy(points.begin(), points.end(), std::back_inserter(profile.polygon.points));
00166   points = interpolate(p5, p0, 0.1);
00167   std::copy(points.begin(), points.end(), std::back_inserter(profile.polygon.points));
00168 
00169   // Compute the angle.
00170   // f is the frontier middle.
00171   geometry_msgs::Point32 f = point((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);
00172   const double length_Of = std::sqrt(f.x * f.x + f.y * f.y);
00173   // Unit vector corresponding to  O-f, where O is the origin
00174   geometry_msgs::Point32 f_u;
00175   f_u.x = f.x / length_Of;
00176   f_u.y = f.y / length_Of;
00177 
00178   frontier_angle = M_PI_2 - std::acos(std::abs(f_u.x * std::cos(angle) + f_u.y * std::sin(angle)));
00179   
00180   return profile;
00181 }
00182 
00183 TEST(TestSuite, TestCrossingDescriptor)
00184 {
00185   std::stringstream g_sstream;
00186   g_sstream <<
00187     "0 1.116" <<
00188     "0.019634 1.12483\n" <<
00189     "0.039925 1.1433\n" <<
00190     "0.0603957 1.15242\n" <<
00191     "0.0811965 1.16116\n" <<
00192     "0.102321 1.16953\n" <<
00193     "0.124807 1.18746\n" <<
00194     "0.147706 1.20297\n" <<
00195     "0.171044 1.21704\n" <<
00196     "0.193509 1.22177\n" <<
00197     "0.218102 1.23692\n" <<
00198     "0.243663 1.25354\n" <<
00199     "0.269246 1.2667\n" <<
00200     "0.293561 1.27155\n" <<
00201     "0.322482 1.2934\n" <<
00202     "0.347335 1.29627\n" <<
00203     "0.379277 1.3227\n" <<
00204     "0.407566 1.33309\n" <<
00205     "0.437568 1.3467\n" <<
00206     "0.453842 1.31805\n" <<
00207     "0.470278 1.29208\n" <<
00208     "0.481288 1.2538\n" <<
00209     "0.498227 1.23315\n" <<
00210     "0.513811 1.21046\n" <<
00211     "0.522657 1.17391\n" <<
00212     "0.539684 1.15736\n" <<
00213     "0.551909 1.13158\n" <<
00214     "0.578384 1.13514\n" <<
00215     "0.610783 1.14871\n" <<
00216     "0.651584 1.17549\n" <<
00217     "0.686 1.18819\n" <<
00218     "0.728264 1.21203\n" <<
00219     "0.770503 1.23306\n" <<
00220     "0.813691 1.25297\n" <<
00221     "0.85892 1.2734\n" <<
00222     "0.914854 1.30655\n" <<
00223     "0.937517 1.29038\n" <<
00224     "0.956284 1.26903\n" <<
00225     "1.0023 1.28288\n" <<
00226     "3.17366 3.91915\n" <<
00227     "3.21715 3.83405\n" <<
00228     "3.25996 3.75015\n" <<
00229     "3.30417 3.66965\n" <<
00230     "3.34043 3.58217\n" <<
00231     "3.38229 3.50247\n" <<
00232     "3.4224 3.4224\n" <<
00233     "3.49455 3.37465\n" <<
00234     "3.62166 3.37726\n" <<
00235     "3.66445 3.29948\n" <<
00236     "3.69959 3.216\n" <<
00237     "3.59888 3.01982\n" <<
00238     "3.63704 2.94522\n" <<
00239     "3.73438 2.91762\n" <<
00240     "3.70088 2.78881\n" <<
00241     "3.76031 2.73203\n" <<
00242     "3.8451 2.69237\n" <<
00243     "3.81274 2.57173\n" <<
00244     "3.87634 2.51732\n" <<
00245     "3.9553 2.47154\n" <<
00246     "3.92411 2.35784\n" <<
00247     "3.99498 2.3065\n" <<
00248     "4.06961 2.25582\n" <<
00249     "4.02712 2.14126\n" <<
00250     "4.24476 2.16281\n" <<
00251     "4.28365 2.08928\n" <<
00252     "4.31674 2.01293\n" <<
00253     "4.35487 1.93891\n" <<
00254     "1.32092 0.560699\n" <<
00255     "1.30826 0.52857\n" <<
00256     "1.32475 0.508524\n" <<
00257     "1.21032 0.440522\n" <<
00258     "1.07695 0.370822\n" <<
00259     "0.966273 0.313961\n" <<
00260     "0.969693 0.296465\n" <<
00261     "0.975681 0.279772\n" <<
00262     "0.989108 0.265031\n" <<
00263     "0.994553 0.24797\n" <<
00264     "1.00847 0.232824\n" <<
00265     "1.0114 0.214981\n" <<
00266     "1.02482 0.199205\n" <<
00267     "1.02814 0.181289\n" <<
00268     "1.04004 0.164726\n" <<
00269     "1.05166 0.147802\n" <<
00270     "1.05408 0.129425\n" <<
00271     "1.05618 0.111009\n" <<
00272     "1.06892 0.0935181\n" <<
00273     "1.07537 0.0751975\n" <<
00274     "1.04656 0.0548481\n" <<
00275     "1.01538 0.0354579\n" <<
00276     "0.977851 0.0170685\n" <<
00277     "0.938 1.14136e-08\n" <<
00278     "0.899863 -0.0157072\n" <<
00279     "0.85248 -0.0297693\n" <<
00280     "0.848835 -0.0444856\n" <<
00281     "0.854912 -0.0597813\n" <<
00282     "0.864697 -0.0756512\n" <<
00283     "0.87319 -0.091776\n" <<
00284     "0.900239 -0.110535\n" <<
00285     "0.931842 -0.130962\n" <<
00286     "0.925464 -0.146579\n" <<
00287     "0.905038 -0.159583\n" <<
00288     "0.911932 -0.177262\n" <<
00289     "0.918481 -0.195229\n" <<
00290     "0.923703 -0.213254\n" <<
00291     "0.929543 -0.231761\n" <<
00292     "0.93405 -0.250278\n" <<
00293     "0.948765 -0.272054\n" <<
00294     "0.953436 -0.291495\n" <<
00295     "0.956763 -0.310871\n" <<
00296     "0.958756 -0.330126\n" <<
00297     "0.971642 -0.353649\n" <<
00298     "0.974658 -0.374136\n" <<
00299     "0.986524 -0.398581\n" <<
00300     "0.992304 -0.421208\n" <<
00301     "0.994851 -0.442936\n" <<
00302     "1.00328 -0.467838\n" <<
00303     "1.01384 -0.494483\n" <<
00304     "1.02198 -0.520727\n" <<
00305     "1.02863 -0.546934\n" <<
00306     "1.03642 -0.574499\n" <<
00307     "1.04876 -0.6055\n" <<
00308     "1.05432 -0.633497\n" <<
00309     "1.0626 -0.663989\n" <<
00310     "1.07266 -0.696593\n" <<
00311     "1.08438 -0.731424\n" <<
00312     "1.09603 -0.767445\n" <<
00313     "1.10512 -0.802915\n" <<
00314     "1.12288 -0.846152\n" <<
00315     "1.1308 -0.883474\n" <<
00316     "1.15328 -0.933911\n" <<
00317     "1.93579 -1.62432\n" <<
00318     "1.96602 -1.70903\n" <<
00319     "1.91954 -1.72836\n" <<
00320     "1.86422 -1.73841\n" <<
00321     "1.39624 -1.34833\n" <<
00322     "1.35906 -1.35906\n" <<
00323     "2.13538 -2.21125\n" <<
00324     "2.11692 -2.27012\n" <<
00325     "2.08903 -2.3201\n" <<
00326     "2.06724 -2.37809\n" <<
00327     "2.03764 -2.42836\n" <<
00328     "2.01886 -2.49308\n" <<
00329     "1.98736 -2.5437\n" <<
00330     "1.96493 -2.60754\n" <<
00331     "1.93675 -2.66571\n" <<
00332     "1.90542 -2.72122\n" <<
00333     "1.88113 -2.78888\n" <<
00334     "1.84469 -2.84058\n" <<
00335     "1.27658 -2.04295\n" <<
00336     "1.24021 -2.06406\n" <<
00337     "1.204 -2.08539\n" <<
00338     "1.16403 -2.09996\n" <<
00339     "1.12626 -2.11819\n" <<
00340     "1.09003 -2.13931\n" <<
00341     "1.05297 -2.1589\n" <<
00342     "1.01513 -2.17695\n" <<
00343     "0.980642 -2.20256\n" <<
00344     "0.942053 -2.21934\n" <<
00345     "0.902802 -2.23451\n" <<
00346     "0.864025 -2.25086\n" <<
00347     "0.154935 -0.425681\n" <<
00348     "0.150738 -0.437775\n" <<
00349     "0.133495 -0.410856\n" <<
00350     "0.128644 -0.420774\n" <<
00351     "0.119351 -0.416226\n" <<
00352     "0.11181 -0.41728\n" <<
00353     "0.10451 -0.419168\n" <<
00354     "0.0962791 -0.41703\n" <<
00355     "0.0939761 -0.442123\n" <<
00356     "0.0862457 -0.443696\n" <<
00357     "0.078489 -0.445133\n" <<
00358     "0.0703955 -0.44446\n" <<
00359     "0.064298 -0.457504\n" <<
00360     "0.0563036 -0.458556\n" <<
00361     "0.0482922 -0.459469\n" <<
00362     "0.0400045 -0.457253\n" <<
00363     "0.032088 -0.458879\n" <<
00364     "0.0245979 -0.469356\n" <<
00365     "0.016333 -0.467715\n" <<
00366     "0.00823755 -0.471928\n" <<
00367     "7.92135e-08 -3.255\n" <<
00368     "-0.0101224 -0.579912\n" <<
00369     "-0.0205558 -0.588641\n" <<
00370     "-0.0308782 -0.589191\n" <<
00371     "-0.0417841 -0.597541\n" <<
00372     "-0.0529907 -0.605686\n" <<
00373     "-0.0644941 -0.61362\n" <<
00374     "-0.0751934 -0.612401\n" <<
00375     "-0.0883749 -0.62882\n" <<
00376     "-0.0998052 -0.630145\n" <<
00377     "-0.112177 -0.636186\n" <<
00378     "-0.124789 -0.641984\n" <<
00379     "-0.136806 -0.643621\n" <<
00380     "-0.149817 -0.64893\n" <<
00381     "-0.163055 -0.653979\n" <<
00382     "-0.176773 -0.659727\n" <<
00383     "-0.191292 -0.667116\n" <<
00384     "-0.206122 -0.674195\n" <<
00385     "-0.22311 -0.686663\n" <<
00386     "-0.241246 -0.700629\n" <<
00387     "-0.257199 -0.706649\n" <<
00388     "-0.27666 -0.720724\n" <<
00389     "-0.293692 -0.726912\n" <<
00390     "-0.314539 -0.741006\n" <<
00391     "-0.33149 -0.74454\n" <<
00392     "-0.352464 -0.755861\n" <<
00393     "-0.374369 -0.76757\n" <<
00394     "-0.396334 -0.777849\n" <<
00395     "-0.423463 -0.796419\n" <<
00396     "-0.447964 -0.808149\n" <<
00397     "-0.4755 -0.82359\n" <<
00398     "-0.499587 -0.831452\n" <<
00399     "-0.529389 -0.8472\n" <<
00400     "-0.566425 -0.872217\n" <<
00401     "-0.592185 -0.877951\n" <<
00402     "-0.630934 -0.901067\n" <<
00403     "-0.66361 -0.91338\n" <<
00404     "-0.705327 -0.936001\n" <<
00405     "-0.746182 -0.955069\n" <<
00406     "-0.78665 -0.971432\n" <<
00407     "-0.836909 -0.99739\n" <<
00408     "-0.895521 -1.03018\n" <<
00409     "-0.951504 -1.05675\n" <<
00410     "-1.01072 -1.08387\n" <<
00411     "-1.08089 -1.11929\n" <<
00412     "-1.16673 -1.16673\n" <<
00413     "-1.2164 -1.17467\n" <<
00414     "-1.22867 -1.14576\n" <<
00415     "-1.24105 -1.11745\n" <<
00416     "-1.24225 -1.07987\n" <<
00417     "-1.24865 -1.04774\n" <<
00418     "-1.2582 -1.01887\n" <<
00419     "-1.2687 -0.991215\n" <<
00420     "-1.2866 -0.969524\n" <<
00421     "-1.29443 -0.940456\n" <<
00422     "-1.31064 -0.917722\n" <<
00423     "-1.319 -0.889676\n" <<
00424     "-1.33432 -0.866521\n" <<
00425     "-1.34246 -0.838862\n" <<
00426     "-1.35775 -0.81582\n" <<
00427     "-1.36312 -0.787\n" <<
00428     "-1.37928 -0.764545\n" <<
00429     "-1.38976 -0.738948\n" <<
00430     "-1.40155 -0.714127\n" <<
00431     "-1.4156 -0.690435\n" <<
00432     "-1.42653 -0.665201\n" <<
00433     "-1.44157 -0.64183\n" <<
00434     "-1.45164 -0.616183\n" <<
00435     "-1.46959 -0.593752\n" <<
00436     "-1.47972 -0.568013\n" <<
00437     "-1.49693 -0.544838\n" <<
00438     "-1.50621 -0.51863\n" <<
00439     "-1.51408 -0.491955\n" <<
00440     "-1.53104 -0.468087\n" <<
00441     "-1.53898 -0.441295\n" <<
00442     "-1.55611 -0.416958\n" <<
00443     "-1.57285 -0.392155\n" <<
00444     "-1.57945 -0.364646\n" <<
00445     "-1.59438 -0.338896\n" <<
00446     "-1.60987 -0.312927\n" <<
00447     "-1.6466 -0.29034\n" <<
00448     "-1.67018 -0.264531\n" <<
00449     "-1.67454 -0.235342\n" <<
00450     "-1.68733 -0.207178\n" <<
00451     "-1.70063 -0.178744\n" <<
00452     "-1.72342 -0.15078\n" <<
00453     "-1.73576 -0.121376\n" <<
00454     "-1.7476 -0.091588\n" <<
00455     "-1.76692 -0.0617024\n" <<
00456     "-1.77773 -0.0310304\n" <<
00457     "-1.798 -6.5634e-08\n" <<
00458     "-1.81772 0.0317284\n" <<
00459     "-1.83788 0.0641801\n" <<
00460     "-1.85046 0.0969785\n" <<
00461     "-1.79961 0.125841\n" <<
00462     "-1.73936 0.152174\n" <<
00463     "-1.72052 0.180834\n" <<
00464     "-1.72802 0.212174\n" <<
00465     "-2.03203 0.285583\n" <<
00466     "-2.95911 0.468678\n" <<
00467     "-2.98791 0.526848\n" <<
00468     "-3.00672 0.584448\n" <<
00469     "-3.044 0.647021\n" <<
00470     "-3.13845 0.724567\n" <<
00471     "-3.16802 0.789875\n" <<
00472     "-3.19625 0.856432\n" <<
00473     "-4.17572 1.19737\n" <<
00474     "-4.0729 1.24521\n" <<
00475     "-3.98873 1.29602\n" <<
00476     "-3.00202 1.03368\n" <<
00477     "-3.08971 1.12456\n" <<
00478     "-3.21245 1.23314\n" <<
00479     "-3.34343 1.35083\n" <<
00480     "-3.51357 1.49142\n" <<
00481     "-3.48061 1.54967\n" <<
00482     "-3.4059 1.5882\n" <<
00483     "-3.33003 1.62417\n" <<
00484     "-3.26019 1.66115\n" <<
00485     "-0.979189 0.520644\n" <<
00486     "-0.958583 0.531351\n" <<
00487     "-0.943968 0.545\n" <<
00488     "-0.932598 0.560361\n" <<
00489     "-0.904867 0.565424\n" <<
00490     "-0.886475 0.575683\n" <<
00491     "-0.868002 0.585475\n" <<
00492     "-0.85028 0.595372\n" <<
00493     "-0.831669 0.604243\n" <<
00494     "-0.812212 0.612046\n" <<
00495     "-0.794315 0.620587\n" <<
00496     "-0.774037 0.626803\n" <<
00497     "-0.76298 0.640216\n" <<
00498     "-0.744144 0.646874\n" <<
00499     "-0.726796 0.65441\n" <<
00500     "-0.707219 0.659492\n" <<
00501     "-0.696321 0.672429\n" <<
00502     "-0.676701 0.676701\n" <<
00503     "-0.663399 0.68697\n" <<
00504     "-0.645852 0.692592\n" <<
00505     "-0.632998 0.703015\n" <<
00506     "-0.616696 0.709427\n" <<
00507     "-0.596507 0.710889\n" <<
00508     "-0.58338 0.720414\n" <<
00509     "-0.570103 0.729698\n" <<
00510     "-0.557883 0.740335\n" <<
00511     "-0.538411 0.74106\n" <<
00512     "-0.52597 0.751162\n" <<
00513     "-0.51278 0.760227\n" <<
00514     "-0.498345 0.767384\n" <<
00515     "-0.485406 0.776812\n" <<
00516     "-0.46611 0.775736\n" <<
00517     "-0.4535 0.785485\n" <<
00518     "-0.439722 0.79328\n" <<
00519     "-0.42628 0.801716\n" <<
00520     "-0.412223 0.809034\n" <<
00521     "-0.398479 0.817004\n" <<
00522     "-0.383737 0.822928\n" <<
00523     "-0.369724 0.830413\n" <<
00524     "-0.355175 0.836739\n" <<
00525     "-0.340517 0.84281\n" <<
00526     "-0.325757 0.848625\n" <<
00527     "-0.310896 0.854181\n" <<
00528     "-0.295616 0.858531\n" <<
00529     "-0.283369 0.872119\n" <<
00530     "-0.268105 0.876932\n" <<
00531     "-0.25276 0.881477\n" <<
00532     "-0.240184 0.896379\n" <<
00533     "-0.224504 0.900434\n" <<
00534     "-0.208755 0.904215\n" <<
00535     "-0.194605 0.915546\n" <<
00536     "-0.178979 0.920766\n" <<
00537     "-0.164619 0.933598\n" <<
00538     "-0.148143 0.935341\n" <<
00539     "-0.13305 0.946696\n" <<
00540     "-0.116507 0.948874\n" <<
00541     "-0.10087 0.959714\n" <<
00542     "-0.0848897 0.970294\n" <<
00543     "-0.0679429 0.971627\n" <<
00544     "-0.0516033 0.984649\n" <<
00545     "-0.0347599 0.995393\n" <<
00546     "-0.0175223 1.00385\n" <<
00547     "-4.94993e-08 1.017\n" <<
00548     "0.0179061 1.02584" ;
00549 
00550   crossing_detector::CrossingDetector crossing_detector(0.7);
00551   PlaceProfile profile = loadFromString(g_sstream);
00552   lama_msgs::Crossing crossing = crossing_detector.crossingDescriptor(profile);
00553 
00554   saveToFile("empty_crossing.bag", crossing);
00555 }
00556 
00557 /* Test the computation of frontier angle and the filter for maximum frontier
00558  * angle. */
00559 TEST(TestSuite, TestFrontierAngle)
00560 {
00561   crossing_detector::CrossingDetector crossing_detector(0.5);
00562 
00563   double angle;
00564   double expected_frontier_angle;
00565   PlaceProfile profile;
00566   std::vector<lama_msgs::Frontier> frontiers;
00567 
00568   angle = -2.7925268031909272; // -160 deg.
00569   profile = profileFrontierAngle(angle, expected_frontier_angle);
00570   // The expected frontier angle is obtained with FreeCAD.
00571   EXPECT_NEAR(0.63119, expected_frontier_angle, 0.001);
00572 
00573   crossing_detector.setMaxFrontierAngle(expected_frontier_angle - 0.1);
00574   frontiers = crossing_detector.frontiers(profile);
00575   EXPECT_EQ(0, frontiers.size());
00576 
00577   crossing_detector.setMaxFrontierAngle(expected_frontier_angle + 0.1);
00578   frontiers = crossing_detector.frontiers(profile);
00579   EXPECT_EQ(1, frontiers.size());
00580 
00581   angle = -2.0943; // -120 deg
00582   profile = profileFrontierAngle(angle, expected_frontier_angle);
00583   // The expected frontier angle is obtained with FreeCAD.
00584   EXPECT_NEAR(1.493, expected_frontier_angle, 0.001);
00585 
00586   crossing_detector.setMaxFrontierAngle(expected_frontier_angle - 0.1);
00587   frontiers = crossing_detector.frontiers(profile);
00588   EXPECT_EQ(0, frontiers.size());
00589 
00590   crossing_detector.setMaxFrontierAngle(expected_frontier_angle + 0.1);
00591   frontiers = crossing_detector.frontiers(profile);
00592   EXPECT_EQ(1, frontiers.size());
00593 
00594   angle = 2.9042; // 166.4 deg.
00595   profile = profileFrontierAngle(angle, expected_frontier_angle);
00596   // The expected frontier angle is obtained with FreeCAD.
00597   EXPECT_NEAR(0.00076, expected_frontier_angle, 0.0001);
00598 
00599   crossing_detector.setMaxFrontierAngle(expected_frontier_angle + 0.1);
00600   frontiers = crossing_detector.frontiers(profile);
00601   EXPECT_EQ(1, frontiers.size());
00602 
00603   angle = 1.7453292; // 100 deg.
00604   profile = profileFrontierAngle(angle, expected_frontier_angle);
00605   // The expected frontier angle is obtained with FreeCAD.
00606   EXPECT_NEAR(1.045068, expected_frontier_angle, 0.0001);
00607 
00608   crossing_detector.setMaxFrontierAngle(expected_frontier_angle - 0.1);
00609   frontiers = crossing_detector.frontiers(profile);
00610   EXPECT_EQ(0, frontiers.size());
00611 
00612   crossing_detector.setMaxFrontierAngle(expected_frontier_angle + 0.1);
00613   frontiers = crossing_detector.frontiers(profile);
00614   EXPECT_EQ(1, frontiers.size());
00615 }
00616 
00617 int main(int argc, char** argv)
00618 {
00619   // ros::init is needed because CrossingDetector uses ros::NodeHandle.
00620   ros::init(argc, argv, "test_cpp_crossing_detector");
00621   testing::InitGoogleTest(&argc, argv);
00622   return RUN_ALL_TESTS();
00623 }
00624 


crossing_detector
Author(s): Gaël Ecorchard , Karel Košnar , Vojtěch Vonásek
autogenerated on Thu Jun 6 2019 22:02:06