obstacle_points.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Ubiquity Robotics
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are
27  * those of the authors and should not be interpreted as representing official
28  * policies, either expressed or implied, of the FreeBSD Project.
29  *
30  */
31 
32 #ifndef OBSTACLE_POINTS_H
33 #define OBSTACLE_POINTS_H
34 
35 #include <vector>
36 #include <utility>
37 #include <mutex>
38 
39 #include <ros/ros.h>
41 #include <tf2_ros/buffer.h>
43 #include <sensor_msgs/Range.h>
44 #include <sensor_msgs/LaserScan.h>
45 
46 // lidar sensor
48 {
49 public:
50  std::string frame_id;
52  double min_range;
53  double max_range;
54  double min_angle;
55  double max_angle;
57  void reset(const std::string & _frame,
58  const int _increment,
59  const double & _min_range,
60  const double & _max_range,
61  const double & _min_angle,
62  const double & _max_angle);
63 };
64 
65 // a single sensor with current obstacles
67 {
68  tf2::Vector3 left_vec;
69  tf2::Vector3 right_vec;
70 
71 public:
72  int id;
73  std::string frame_id;
74  tf2::Vector3 origin;
75  // cone vertices from last Range message
76  tf2::Vector3 left_vertex;
77  tf2::Vector3 right_vertex;
79 
81  RangeSensor(int id, std::string frame_id,
82  const tf2::Vector3& origin,
83  const tf2::Vector3& left_vec,
84  const tf2::Vector3& right_vec);
85 
86  void update(float range, ros::Time stamp);
87 };
88 
90 {
91 private:
92  // Line in polar form
93  class PolarLine
94  {
95  public:
96  float radius;
97  float theta;
98 
99  PolarLine(float radius, float theta);
100  };
101 
102  std::mutex points_mutex;
103 
104  std::string baseFrame;
105 
107  std::map<std::string, RangeSensor> sensors;
111 
113  tf2::Vector3 lidar_origin;
114  tf2::Vector3 lidar_normal;
115  std::vector<PolarLine> lidar_points;
117 
118  // Sine / Cosine LookUp Tables
119  std::vector<float> sinLUT, cosLUT;
120 
121  // Manually added points, used for unit testing things that
122  // use ObstaclePoints without having to go through ROS messages
123  std::vector<tf2::Vector3> test_points;
124 
125 public:
127 
128  void range_callback(const sensor_msgs::Range::ConstPtr &msg);
129  void scan_callback(const sensor_msgs::LaserScan::ConstPtr &msg);
130 
131  /*
132  * Returns a vector of all the points that were detected, filtered
133  * by the maximum age.
134  *
135  */
136  std::vector<tf2::Vector3> get_points(ros::Duration max_age);
137 
138  /*
139  * Returns a vector of lines (expressed as a pair of 2 points).
140  * The lines are based on the end of the sonar cones, filtered
141  * by the the specified maximum age.
142  *
143  */
144  typedef std::pair<tf2::Vector3, tf2::Vector3> Line;
145  std::vector<Line> get_lines(ros::Duration max_age);
146 
147  // Used for unit testing things that use ObstaclePoints
148  // without having to go through ROS messages
149  void add_test_point(tf2::Vector3 p);
150  void clear_test_points();
151 
152 };
153 
154 #endif
double max_angle
ros::Subscriber sonar_sub
double max_range
tf2::Vector3 left_vertex
ros::Subscriber scan_sub
void reset(const std::string &_frame, const int _increment, const double &_min_range, const double &_max_range, const double &_min_angle, const double &_max_angle)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
ros::Time lidar_stamp
std::string baseFrame
std::vector< PolarLine > lidar_points
std::pair< tf2::Vector3, tf2::Vector3 > Line
tf2::Vector3 left_vec
tf2::Vector3 origin
std::map< std::string, RangeSensor > sensors
ros::Time stamp
tf2::Vector3 lidar_normal
LidarSensor lidar
double angle_increment
tf2_ros::Buffer & tf_buffer
double min_range
std::vector< float > sinLUT
double min_angle
tf2::Vector3 right_vec
std::string frame_id
tf2::Vector3 right_vertex
tf2::Vector3 lidar_origin
std::string frame_id
std::vector< tf2::Vector3 > test_points
std::mutex points_mutex


move_basic
Author(s): Jim Vaughan
autogenerated on Fri Mar 26 2021 02:46:58