selfdriving
ObstacleSource.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * SelfDriving C++ library based on PTGs and mrpt-nav
3  * Copyright (C) 2019-2022 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
6 
7 #pragma once
8 
9 #include <mrpt/core/lock_helper.h>
10 #include <mrpt/maps/CPointsMap.h>
11 #include <mrpt/maps/CSimplePointsMap.h>
12 #include <mrpt/obs/CObservation.h>
13 #include <mrpt/system/datetime.h>
14 
15 namespace mpp
16 {
18 {
19  public:
20  using Ptr = std::shared_ptr<ObstacleSource>;
21 
22  ObstacleSource() = default;
23  virtual ~ObstacleSource();
24 
25  static Ptr FromStaticPointcloud(const mrpt::maps::CPointsMap::Ptr& pc);
26 
27  /** Returns all global obstacle points, in global "map" reference frame.
28  */
29  virtual mrpt::maps::CPointsMap::Ptr obstacles(
30  mrpt::system::TTimeStamp t = mrpt::system::TTimeStamp()) = 0;
31 
32  virtual bool dynamic() const { return false; }
33 };
34 
35 /** A simple obstacle source from a fixed (static world) point cloud. */
37 {
38  public:
40  const mrpt::maps::CPointsMap::Ptr& staticObstacles)
41  : static_obs_(staticObstacles)
42  {
43  ASSERT_(static_obs_);
44  }
45 
46  mrpt::maps::CPointsMap::Ptr obstacles(
47  [[maybe_unused]] mrpt::system::TTimeStamp t =
48  mrpt::system::TTimeStamp()) override
49  {
50  return static_obs_;
51  }
52 
53  private:
54  mrpt::maps::CPointsMap::Ptr static_obs_;
55 };
56 
57 /** Obstacles from a generic MRPT observation (2D lidar, 3D camera, velodyne,
58  * etc.).
59  * This creates a pointcloud with obstacles in the global nav frame, from the
60  * raw observation data and a robot pose from an external localization system.
61  */
63 {
64  public:
66 
68  const mrpt::obs::CObservation::Ptr& o,
69  const mrpt::poses::CPose3D& robotPose)
70  {
71  auto lck = mrpt::lockHelper(obsMtx_);
72  obs_ = o;
73  robotPoseForObs_ = robotPose;
74  }
75 
76  mrpt::obs::CObservation::Ptr get_stored_sensor_observation() const
77  {
78  auto lck = mrpt::lockHelper(obsMtx_);
79  return obs_;
80  }
81 
82  mrpt::maps::CPointsMap::Ptr obstacles(
83  [[maybe_unused]] mrpt::system::TTimeStamp t =
84  mrpt::system::TTimeStamp()) override
85  {
86  auto lck = mrpt::lockHelper(obsMtx_);
87 
88  // TODO: Cached pts with obs timestamp for checking.
89  auto pts = mrpt::maps::CSimplePointsMap::Create();
90  if (obs_) { pts->insertObservation(*obs_, robotPoseForObs_); }
91 
92  return pts;
93  }
94 
95  private:
96  std::mutex obsMtx_;
97  mrpt::obs::CObservation::Ptr obs_;
98  mrpt::poses::CPose3D robotPoseForObs_;
99 };
100 
101 } // namespace mpp
Definition: ObstacleSource.h:62
virtual bool dynamic() const
Definition: ObstacleSource.h:32
mrpt::maps::CPointsMap::Ptr obstacles([[maybe_unused]] mrpt::system::TTimeStamp t=mrpt::system::TTimeStamp()) override
Definition: ObstacleSource.h:46
mrpt::obs::CObservation::Ptr get_stored_sensor_observation() const
Definition: ObstacleSource.h:76
Definition: bestTrajectory.h:15
static Ptr FromStaticPointcloud(const mrpt::maps::CPointsMap::Ptr &pc)
ObstacleSourceGenericSensor()
Definition: ObstacleSource.h:65
mrpt::poses::CPose3D robotPoseForObs_
Definition: ObstacleSource.h:98
Definition: ObstacleSource.h:17
virtual mrpt::maps::CPointsMap::Ptr obstacles(mrpt::system::TTimeStamp t=mrpt::system::TTimeStamp())=0
std::shared_ptr< ObstacleSource > Ptr
Definition: ObstacleSource.h:20
Definition: ObstacleSource.h:36
virtual ~ObstacleSource()
mrpt::maps::CPointsMap::Ptr obstacles([[maybe_unused]] mrpt::system::TTimeStamp t=mrpt::system::TTimeStamp()) override
Definition: ObstacleSource.h:82
mrpt::obs::CObservation::Ptr obs_
Definition: ObstacleSource.h:97
void set_sensor_observation(const mrpt::obs::CObservation::Ptr &o, const mrpt::poses::CPose3D &robotPose)
Definition: ObstacleSource.h:67
mrpt::maps::CPointsMap::Ptr static_obs_
Definition: ObstacleSource.h:54
ObstacleSource()=default
ObstacleSourceStaticPointcloud(const mrpt::maps::CPointsMap::Ptr &staticObstacles)
Definition: ObstacleSource.h:39
std::mutex obsMtx_
Definition: ObstacleSource.h:96