test_octomap_ros.cpp
Go to the documentation of this file.
1 
2 #include <octomap/octomap.h>
3 #include <octomap_ros/OctomapROS.h>
6 
7 using namespace octomap;
8 using namespace std;
9 
10 #define _1DEG 0.01745329251994329577
11 
12 int main(int argc, char** argv) {
13 
14 
15  //##############################################################
16 
17  OcTreeROS tree (0.05);
18 
19  // point3d origin (10.01, 10.01, 10.02);
20  point3d origin (0.01, 0.01, 0.02);
21  geometry_msgs::Point originPt = pointOctomapToMsg(origin);
22 
23  point3d point_on_surface (2.01,0.01,0.01);
24 
25  cout << "generating sphere at " << origin << " ..." << endl;
26 
27  for (int i=0; i<360; i++) {
28  for (int j=0; j<360; j++) {
29  geometry_msgs::Point endPt = pointOctomapToMsg(origin+point_on_surface);
30  if (!tree.insertRay(originPt, endPt)) {
31  cout << "ERROR while inserting ray from " << origin << " to " << point_on_surface << endl;
32  }
33  point_on_surface.rotate_IP (0,0,_1DEG);
34  }
35  point_on_surface.rotate_IP (0,_1DEG,0);
36  }
37 
38 
39  cout << "done.\n\n";
40  tf::Point pointTf(0.0, 0.0, 0.0);
41  OcTreeROS::NodeType* treeNode = tree.search(pointTf);
42  if (treeNode)
43  cout << "Occupancy of node at (0, 0, 0) = " << treeNode->getOccupancy() << " (should be free)\n";
44  else
45  cerr << "ERROR: OcTreeNode not found (NULL)\n";
46 
47  treeNode = tree.search(tf::Point(10.01, 2.01, 0.01));
48  if (treeNode)
49  cout << "Occupancy of node at (0.01, 2.01, 0.01) = " << treeNode->getOccupancy() << " (should be occupied)\n";
50  else
51  cerr << "ERROR: OcTreeNode not found (NULL)\n";
52 
53  cout << "writing to sphere.bt..." << endl;
54  tree.octree.writeBinary("sphere.bt");
55 
56  // -----------------------------------------------
57 
58  cout << "\ncasting rays ..." << endl;
59 
60  OcTreeROS sampled_surface(0.05);
61 
62  point3d direction = point3d (1.0,0.0,0.0);
63  point3d obstacle(0,0,0);
64 
65  unsigned int hit (0);
66  unsigned int miss (0);
67  double mean_dist(0);
68 
69  for (int i=0; i<360; i++) {
70  for (int j=0; j<360; j++) {
71  geometry_msgs::Point directionPt = pointOctomapToMsg(direction);
72  geometry_msgs::Point obstaclePt;
73  if (!tree.castRay(originPt, directionPt, obstaclePt, true, 3.)) {
74  miss++;
75  }
76  else {
77  hit++;
78  point3d obstacle = pointMsgToOctomap(obstaclePt);
79  mean_dist += (obstacle - origin).norm();
80  sampled_surface.octree.updateNode(obstacle, true);
81  }
82  direction.rotate_IP (0,0,_1DEG);
83  }
84  direction.rotate_IP (0,_1DEG,0);
85  }
86  cout << "done." << endl;
87 
88  mean_dist /= (double) hit;
89  std::cout << " hits / misses: " << hit << " / " << miss << std::endl;
90  std::cout << " mean obstacle dist: " << mean_dist << std::endl;
91 
92  cout << "writing sampled_surface.bt" << endl;
93  sampled_surface.octree.writeBinary("sampled_surface.bt");
94 
95 
96  // -----------------------------------------------
97  cout << "\ngenerating single rays..." << endl;
98  OcTreeROS single_beams(0.03333);
99  int num_beams = 17;
100  double beamLength = 10.0;
101  point3d single_origin (1.0, 0.45, 0.45);
102  geometry_msgs::Point single_originPt = pointOctomapToMsg(single_origin);
103  point3d single_end(beamLength, 0.0, 0.0);
104 
105 
106  for (int i=0; i<num_beams; i++) {
107  geometry_msgs::Point single_endPt = pointOctomapToMsg(single_origin+single_end);
108  if (!single_beams.insertRay(single_originPt, single_endPt)) {
109  cout << "ERROR while inserting ray from " << single_origin << " to " << single_end << endl;
110  }
111  single_end.rotate_IP (0,0,2.0*M_PI/num_beams);
112  }
113 
114  cout << "done." << endl;
115  cout << "writing to beams.bt..." << endl;
116  single_beams.octree.writeBinary("beams.bt");
117 
118 }
#define _1DEG
static octomap::point3d pointMsgToOctomap(const geometry_msgs::Point &ptMsg)
Conversion from geometry_msgs::Point to octomap::point3d.
Definition: conversions.h:76
#define M_PI
int main(int argc, char **argv)
Vector3 & rotate_IP(double roll, double pitch, double yaw)
std::ostream & writeBinary(std::ostream &s) const
static geometry_msgs::Point pointOctomapToMsg(const point3d &octomapPt)
Conversion from octomap::point3d to geometry_msgs::Point.
Definition: conversions.h:66
octomath::Vector3 point3d


octomap_ros
Author(s): Armin Hornung
autogenerated on Fri Jun 7 2019 22:01:31