virtual_sensor_node.hpp
Go to the documentation of this file.
1 /*
2  * virtual_sensor_node.hpp
3  *
4  * Created on: May 13, 2013
5  * Author: jorge
6  */
7 
8 #ifndef VIRTUAL_SENSOR_NODE_HPP_
9 #define VIRTUAL_SENSOR_NODE_HPP_
10 
11 #include <tf/tf.h>
12 #include <tf/transform_listener.h>
13 #include <sensor_msgs/LaserScan.h>
14 
16 
17 #include <yocs_msgs/Wall.h>
18 #include <yocs_msgs/WallList.h>
19 #include <yocs_msgs/Column.h>
20 #include <yocs_msgs/ColumnList.h>
21 
22 namespace virtual_sensor
23 {
24 
26 {
27 public:
28 
29  class Obstacle
30  {
31  public:
32  Obstacle(const std::string& name, const tf::Transform& tf, double height)
33  : name_(name), tf_(tf), height_(height) { }
34  ~Obstacle() { }
35  std::string& name() { return name_;}
36  double distance() { return distance_; }
37  double minHeight() { return tf_.getOrigin().z(); }
38  double maxHeight() { return tf_.getOrigin().z() + height_; }
39  virtual bool intersects(double rx, double ry, double max_dist, double& distance) = 0;
40 
41  protected:
42  std::string name_;
44  double distance_;
45  double height_;
46  };
47 
48  class Column : public Obstacle
49  {
50  public:
51  Column(const std::string& name, const tf::Transform& tf, double radius, double height)
52  : Obstacle(name, tf, height)
53  {
54  radius_ = radius;
55  distance_ = mtk::distance2D(tf.getOrigin()) - radius;
56  }
57 
58  double radius() { return radius_; }
59  bool intersects(double rx, double ry, double max_dist, double& distance)
60  {
61  double ix, iy;
62  bool intersects =
63  mtk::rayCircleIntersection(rx, ry, tf_.getOrigin().x(), tf_.getOrigin().y(), radius_, ix, iy, distance);
64  if ((intersects == false) || (distance > max_dist))
65  return false;
66  else
67  return true;
68  }
69 
70  private:
71  double radius_;
72  };
73 
74  class Wall : public Obstacle
75  {
76  public:
77  Wall(const std::string& name, const tf::Transform& tf, double length, double width, double height)
78  : Obstacle(name, tf, height)
79  {
80  length_ = length;
81  width_ = width;
82 
83  p1_.setX(- width_/2.0);
84  p1_.setY(- length_/2.0);
85  p1_.setZ( 0.0);
86  p2_.setX(+ width_/2.0);
87  p2_.setY(+ length_/2.0);
88  p2_.setZ(+ height_);
89 
90  p1_ = tf_ * p1_;
91  p2_ = tf_ * p2_;
92 
93  distance_ = mtk::pointSegmentDistance(0.0, 0.0, p1_.x(), p1_.y(), p2_.x(), p2_.y());
94  }
95 
96  double length() { return length_; }
97  double width() { return width_; }
98  bool intersects(double rx, double ry, double max_dist, double& distance)
99  {
100  double ix, iy;
101  bool intersects =
102  mtk::raySegmentIntersection(0.0, 0.0, rx, ry, p1_.x(), p1_.y(), p2_.x(), p2_.y(), ix, iy, distance);
103  if ((intersects == false) || (distance > max_dist))
104  return false;
105  else
106  return true;
107  }
108 
109  private:
112  double length_;
113  double width_;
114  };
115 
118 
119  bool init();
120  void spin();
121 
122  void columnPosesCB(const yocs_msgs::ColumnList::ConstPtr& msg);
123  void wallPosesCB(const yocs_msgs::WallList::ConstPtr& msg);
124 
125 private:
126  double angle_min_;
127  double angle_max_;
128  double angle_inc_;
129  double scan_time_;
130  double range_min_;
131  double range_max_;
132  double frequency_;
134  std::string sensor_frame_id_;
135  std::string global_frame_id_;
140  sensor_msgs::LaserScan scan_;
142  std::vector<yocs_msgs::Column> columns_;
143  std::vector<yocs_msgs::Wall> walls_;
144 
153  bool add(boost::shared_ptr<Obstacle>& new_obs, std::vector< boost::shared_ptr<Obstacle> >& obstacles);
154 };
155 
156 } /* namespace virtual_sensor */
157 #endif /* VIRTUAL_SENSOR_NODE_HPP_ */
Obstacle(const std::string &name, const tf::Transform &tf, double height)
Column(const std::string &name, const tf::Transform &tf, double radius, double height)
bool intersects(double rx, double ry, double max_dist, double &distance)
bool raySegmentIntersection(double r1x, double r1y, double r2x, double r2y, double s1x, double s1y, double s2x, double s2y, double &ix, double &iy, double &distance)
double distance2D(double ax, double ay, double bx, double by)
bool rayCircleIntersection(double rx, double ry, double cx, double cy, double radius, double &ix, double &iy, double &distance)
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
std::vector< yocs_msgs::Wall > walls_
void columnPosesCB(const yocs_msgs::ColumnList::ConstPtr &msg)
TFSIMD_FORCE_INLINE const tfScalar & y() const
double pointSegmentDistance(double px, double py, double s1x, double s1y, double s2x, double s2y)
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
Wall(const std::string &name, const tf::Transform &tf, double length, double width, double height)
bool add(boost::shared_ptr< Obstacle > &new_obs, std::vector< boost::shared_ptr< Obstacle > > &obstacles)
virtual bool intersects(double rx, double ry, double max_dist, double &distance)=0
void wallPosesCB(const yocs_msgs::WallList::ConstPtr &msg)
std::vector< yocs_msgs::Column > columns_
bool intersects(double rx, double ry, double max_dist, double &distance)


yocs_virtual_sensor
Author(s): Jorge Santos
autogenerated on Mon Jun 10 2019 15:54:08