Flatland
laser.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name laser.h
11  * @brief Laser plugin
12  * @author Chunshang Li
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #include <flatland_plugins/update_timer.h>
48 #include <flatland_server/model_plugin.h>
49 #include <flatland_server/timekeeper.h>
50 #include <flatland_server/types.h>
51 #include <ros/ros.h>
52 #include <sensor_msgs/LaserScan.h>
53 #include <tf/transform_broadcaster.h>
54 #include <visualization_msgs/Marker.h>
55 #include <Eigen/Dense>
56 
57 #ifndef FLATLAND_PLUGINS_LASER_H
58 #define FLATLAND_PLUGINS_LASER_H
59 
60 using namespace flatland_server;
61 
62 namespace flatland_plugins {
63 
68 class Laser : public ModelPlugin, public b2RayCastCallback {
69  public:
70  std::string topic_;
73  double range_;
74  double noise_std_dev_;
75  double max_angle_;
76  double min_angle_;
77  double increment_;
78  double update_rate_;
79  std::string frame_id_;
81  uint16_t layers_bits_;
82 
83  /*
84  * for setting reflectance layers. if the laser hits those layers,
85  * intensity will be high (255)
86  */
87  uint16_t reflectance_layers_bits_;
88 
89  std::default_random_engine rng_;
90  std::normal_distribution<double> noise_gen_;
91 
92  Eigen::Matrix3f m_body_to_laser_;
93  Eigen::Matrix3f m_world_to_body_;
94  Eigen::Matrix3f m_world_to_laser_;
95  Eigen::MatrixXf m_laser_points_;
96  Eigen::MatrixXf m_world_laser_points_;
97  Eigen::Vector3f v_zero_point_;
98  Eigen::Vector3f v_world_laser_origin_;
99  sensor_msgs::LaserScan laser_scan_;
100  bool did_hit_;
101  float fraction_;
102  float intensity_;
103 
104  ros::Publisher scan_publisher_;
105  tf::TransformBroadcaster tf_broadcaster_;
106  geometry_msgs::TransformStamped laser_tf_;
108 
117  float ReportFixture(b2Fixture *fixture, const b2Vec2 &point,
118  const b2Vec2 &normal, float fraction) override;
119 
124  void OnInitialize(const YAML::Node &config) override;
125 
130  void BeforePhysicsStep(const Timekeeper &timekeeper) override;
131 
135  void ComputeLaserRanges();
136 
141  void ParseParameters(const YAML::Node &config);
142 };
143 };
144 
145 #endif
std::normal_distribution< double > noise_gen_
gaussian noise generator
Definition: laser.h:90
Eigen::Vector3f v_world_laser_origin_
(0,0) in the laser frame
Definition: laser.h:98
bool broadcast_tf_
whether to broadcast laser origin w.r.t body
Definition: laser.h:80
double noise_std_dev_
noise std deviation
Definition: laser.h:74
Eigen::Matrix3f m_body_to_laser_
tf from body to laser
Definition: laser.h:92
Definition: dummy_model_plugin.h:59
Pose origin_
laser frame w.r.t the body
Definition: laser.h:72
std::string frame_id_
laser frame id name
Definition: laser.h:79
double increment_
laser angle increment
Definition: laser.h:77
std::default_random_engine rng_
random generator
Definition: laser.h:89
float fraction_
Box2D ray trace fraction.
Definition: laser.h:101
Eigen::Matrix3f m_world_to_body_
tf from world to body
Definition: laser.h:93
float intensity_
Intensity of raytrace collision.
Definition: laser.h:102
Definition: body.h:55
sensor_msgs::LaserScan laser_scan_
for publishing laser scan
Definition: laser.h:99
std::string topic_
topic name to publish the laser scan
Definition: laser.h:70
double range_
laser max range
Definition: laser.h:73
Definition: laser.h:68
double min_angle_
< laser max angle
Definition: laser.h:76
bool did_hit_
Box2D ray trace checking if ray hits anything.
Definition: laser.h:100
Definition: types.h:84
ros::Publisher scan_publisher_
ros laser topic publisher
Definition: laser.h:104
Eigen::Vector3f v_zero_point_
laser point in the world frame
Definition: laser.h:97
Eigen::Matrix3f m_world_to_laser_
tf from world to laser
Definition: laser.h:94
uint16_t layers_bits_
for setting the layers where laser will function
Definition: laser.h:81
UpdateTimer update_timer_
for controlling update rate
Definition: laser.h:107
Definition: timekeeper.h:55
Eigen::MatrixXf m_laser_points_
laser points in the laser&#39; frame
Definition: laser.h:95
double update_rate_
the rate laser scan will be published
Definition: laser.h:78
Definition: model_plugin.h:64
Definition: body.h:61
Body * body_
body the laser frame attaches to
Definition: laser.h:71
Definition: update_timer.h:55
tf::TransformBroadcaster tf_broadcaster_
broadcast laser frame
Definition: laser.h:105
geometry_msgs::TransformStamped laser_tf_
tf from body to laser frame
Definition: laser.h:106