test_filter.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
37 #include <cstdio>
38 
39 #include <ros/ros.h>
40 #include <visualization_msgs/Marker.h>
42 
44 {
45 public:
46 
48  {
49  id_ = 1;
50  vmPub_ = nodeHandle_.advertise<visualization_msgs::Marker>("visualization_marker", 10240);
51  std::vector<robot_self_filter::LinkInfo> links;
53  li.name="base_link";
54  li.padding = .05;
55  li.scale = 1.0;
56  links.push_back(li);
58  }
59 
61  {
62  delete sf_;
63  }
64 
65  void gotIntersection(const tf::Vector3 &pt)
66  {
67  sendPoint(pt.x(), pt.y(), pt.z());
68  }
69 
70  void sendPoint(double x, double y, double z)
71  {
72  visualization_msgs::Marker mk;
73 
74  mk.header.stamp = ros::Time::now();
75 
76  mk.header.frame_id = "base_link";
77 
78  mk.ns = "test_self_filter";
79  mk.id = id_++;
81  mk.action = visualization_msgs::Marker::ADD;
82  mk.pose.position.x = x;
83  mk.pose.position.y = y;
84  mk.pose.position.z = z;
85  mk.pose.orientation.w = 1.0;
86 
87  mk.scale.x = mk.scale.y = mk.scale.z = 0.01;
88 
89  mk.color.a = 1.0;
90  mk.color.r = 1.0;
91  mk.color.g = 0.04;
92  mk.color.b = 0.04;
93 
94  mk.lifetime = ros::Duration(10);
95 
96  vmPub_.publish(mk);
97  }
98 
99  void run(void)
100  {
101  pcl::PointCloud<pcl::PointXYZ> in;
102 
103  in.header.stamp = ros::Time::now().toNSec();
104  in.header.frame_id = "base_link";
105 
106  const unsigned int N = 500000;
107  in.points.resize(N);
108  for (unsigned int i = 0 ; i < N ; ++i)
109  {
110  in.points[i].x = uniform(1.5);
111  in.points[i].y = uniform(1.5);
112  in.points[i].z = uniform(1.5);
113  }
114 
115  for (unsigned int i = 0 ; i < 1000 ; ++i)
116  {
117  ros::Duration(0.001).sleep();
118  ros::spinOnce();
119  }
120 
122  std::vector<int> mask;
123  sf_->maskIntersection(in, "laser_tilt_mount_link", 0.01, mask, boost::bind(&TestSelfFilter::gotIntersection, this, _1) );
124  // sf_->maskContainment(in, mask);
125  printf("%f points per second\n", (double)N/(ros::WallTime::now() - tm).toSec());
126 
127 
128  int k = 0;
129  for (unsigned int i = 0 ; i < mask.size() ; ++i)
130  {
131  // bool v = sf_->getMaskContainment(in.points[i].x, in.points[i].y, in.points[i].z);
132  // if (v != mask[i])
133  // ROS_ERROR("Mask does not match");
134  if (mask[i] != robot_self_filter::INSIDE) continue;
135  // sendPoint(in.points[i].x, in.points[i].y, in.points[i].z);
136  k++;
137  }
138 
139  ros::spin();
140  }
141 
142 protected:
143 
144  double uniform(double magnitude)
145  {
146  return (2.0 * drand48() - 1.0) * magnitude;
147  }
148 
153  int id_;
154 };
155 
156 int main(int argc, char **argv)
157 {
158  ros::init(argc, argv, "robot_self_filter");
159 
160  TestSelfFilter t;
161  sleep(1);
162  t.run();
163 
164  return 0;
165 }
166 
167 
168 
void sendPoint(double x, double y, double z)
Definition: test_filter.cpp:70
void publish(const boost::shared_ptr< M > &message) const
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void maskIntersection(const PointCloud &data_in, const std::string &sensor_frame, const double min_sensor_dist, std::vector< int > &mask, const boost::function< void(const tf::Vector3 &)> &intersectionCallback=NULL)
Compute the intersection mask for a given pointcloud. If a mask element can have one of the values IN...
Definition: self_mask.h:213
ROSCPP_DECL void spin(Spinner &spinner)
double uniform(double magnitude)
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
void gotIntersection(const tf::Vector3 &pt)
Definition: test_filter.cpp:65
TFSIMD_FORCE_INLINE const tfScalar & y() const
uint64_t toNSec() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TestSelfFilter(void)
Definition: test_filter.cpp:47
robot_self_filter::SelfMask< pcl::PointXYZ > * sf_
ros::NodeHandle nodeHandle_
void run(void)
Definition: test_filter.cpp:99
ros::Publisher vmPub_
static WallTime now()
int main(int argc, char **argv)
static Time now()
tf::TransformListener tf_
~TestSelfFilter(void)
Definition: test_filter.cpp:60
ROSCPP_DECL void spinOnce()


pr2_navigation_self_filter
Author(s): Eitan Marder-Eppstein
autogenerated on Mon Jun 10 2019 14:28:54