laser_scan_observer.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_ROS_LASER_SCAN_OBSERVER_H_INCLUDED
2 #define SLAM_CTOR_ROS_LASER_SCAN_OBSERVER_H_INCLUDED
3 
4 #include <utility>
5 #include <memory>
6 #include <sensor_msgs/LaserScan.h>
7 #include <boost/shared_ptr.hpp>
8 #include <cassert>
9 #include <iostream>
10 
11 #include "../core/states/state_data.h"
12 #include "../core/states/robot_pose.h"
13 #include "../core/states/world.h"
14 #include "../core/states/sensor_data.h"
15 #include "topic_with_transform.h"
16 
17 class LaserScanObserver : public TopicObserver<sensor_msgs::LaserScan> {
19  using DstPtr = std::shared_ptr<SensorDataObserver<TransformedLaserScan>>;
20 public: //methods
21 
23  bool skip_max_vals,
24  bool use_cached_trig)
25  : _slam(slam), _skip_max_vals(skip_max_vals)
26  , _use_cached_trig_provider{use_cached_trig} {}
27 
28  virtual void handle_transformed_msg(
29  const ScanPtr msg, const tf::StampedTransform& t) {
30 
31  RobotPose new_pose(t.getOrigin().getX(), t.getOrigin().getY(),
32  tf::getYaw(t.getRotation()));
33 
34  TransformedLaserScan transformed_scan;
35  transformed_scan.scan.points().reserve(msg->ranges.size());
36  transformed_scan.quality = 1.0;
37  // TODO: move trig provider setup to the SLAM
38  transformed_scan.scan.trig_provider = trig_provider(msg);
39 
40  double sp_angle = msg->angle_min - msg->angle_increment;
41  for (const auto &range : msg->ranges) {
42  bool sp_is_occupied = true;
43  double sp_range = range;
44  sp_angle += msg->angle_increment;
45 
46  // filter points by range/angle
47  if (sp_range < msg->range_min) {
48  continue;
49  } else if (msg->range_max <= sp_range) {
50  sp_is_occupied = false;
51  sp_range = msg->range_max;
52  if (_skip_max_vals) {
53  continue;
54  }
55  }
56 
57  // add a scan point to a scan
58  transformed_scan.scan.points().emplace_back(sp_range, sp_angle,
59  sp_is_occupied);
60  }
61  assert(are_equal(sp_angle, msg->angle_max));
62 
63  transformed_scan.pose_delta = new_pose - _prev_pose;
64  _prev_pose = new_pose;
65 
66  _slam->handle_sensor_data(transformed_scan);
67  }
68 
69  const RobotPose &odometry_pose() const { return _prev_pose; }
70  void set_odometry_pose(const RobotPose& pose) { _prev_pose = pose; }
71 
72 private:
73 
74  std::shared_ptr<TrigonometryProvider> trig_provider(const ScanPtr msg) {
76  auto provider = std::make_shared<CachedTrigonometryProvider>();
77  provider->update(msg->angle_min, msg->angle_max + msg->angle_increment,
78  msg->angle_increment);
79  return provider;
80  } else {
81  return std::make_shared<RawTrigonometryProvider>();
82  }
83  }
84 
85 private: // fields
90 };
91 
92 #endif
CONSTEXPR bool are_equal(const T &a, const T &b, const T &eps)
Definition: math_utils.h:17
static double getYaw(const Quaternion &bt_q)
TFSIMD_FORCE_INLINE const tfScalar & getY() const
const RobotPose & odometry_pose() const
const Points & points() const
Definition: sensor_data.h:148
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
RobotPoseDelta pose_delta
Definition: sensor_data.h:177
std::shared_ptr< TrigonometryProvider > trig_provider
Definition: sensor_data.h:171
std::shared_ptr< TrigonometryProvider > trig_provider(const ScanPtr msg)
Quaternion getRotation() const
std::shared_ptr< SensorDataObserver< TransformedLaserScan >> DstPtr
void set_odometry_pose(const RobotPose &pose)
TFSIMD_FORCE_INLINE const tfScalar & getX() const
virtual void handle_transformed_msg(const ScanPtr msg, const tf::StampedTransform &t)
LaserScanObserver(DstPtr slam, bool skip_max_vals, bool use_cached_trig)


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25