MRPT  2.0.1
map.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
14 #include <nav_msgs/OccupancyGrid.h>
15 #include <cstdint>
16 #include <string>
17 
18 namespace mrpt::ros1bridge
19 {
20 /** \addtogroup mrpt_ros1bridge_grp
21  * @{ */
22 
23 /** @name Maps, Occupancy Grid Maps: ROS <-> MRPT
24  * @{ */
25 
26 /** Methods to convert between ROS msgs and MRPT objects for map datatypes.
27  * @brief the map class is implemented as singeleton use map::instance
28  * ()->fromROS ...
29  */
30 class MapHdl
31 {
32  private:
33 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS
34  int lut_cellmrpt2ros[0x100]; // lookup table for entry convertion
35 #else
36  int lut_cellmrpt2ros[0xFFFF]; // lookup table for entry convertion
37 #endif
38  int lut_cellros2mrpt[101]; // lookup table for entry convertion
39 
40  MapHdl();
41  MapHdl(const MapHdl&);
42  ~MapHdl() = default;
43 
44  public:
45  /**
46  * @return returns singeleton instance
47  * @brief it creates a instance with some look up table to speed up the
48  * conversions
49  */
50  static MapHdl* instance();
51 
52 #ifdef OCCUPANCY_GRIDMAP_CELL_SIZE_8BITS
53  int8_t cellMrpt2Ros(int8_t i)
54  {
55  return lut_cellmrpt2ros[static_cast<int>(i) - INT8_MIN];
56  }
57 #else
58  int16_t cellMrpt2Ros(int16_t i)
59  {
60  return lut_cellmrpt2ros[static_cast<int>(i) - INT16_MIN];
61  }
62 #endif
63  int8_t cellRos2Mrpt(int8_t i)
64  {
65  if (i < 0)
66  {
67  // unobserved cells: no log-odds information
68  return 0;
69  }
70  ASSERT_BELOWEQ_(i, 100);
71  return lut_cellros2mrpt[i];
72  }
73 
74  /**
75  * loads a mprt map
76  * @return true on sucess.
77  * @param _metric_map
78  * @param _config_file
79  * @param _map_file default: map.simplemap
80  * @param _section_name default: metricMap
81  * @param _debug default: false
82  */
83  static bool loadMap(
84  mrpt::maps::CMultiMetricMap& _metric_map,
85  const mrpt::config::CConfigFileBase& _config_file,
86  const std::string& _map_file = "map.simplemap",
87  const std::string& _section_name = "metricMap", bool _debug = false);
88 };
89 
90 /**
91  * converts ros msg to mrpt object
92  * @return true on sucessful conversion, false on any error.
93  * @param src
94  * @param des
95  */
96 bool fromROS(
97  const nav_msgs::OccupancyGrid& src, mrpt::maps::COccupancyGridMap2D& des);
98 
99 /**
100  * converts mrpt object to ros msg and updates the msg header
101  * @return true on sucessful conversion, false on any error.
102  * @param src
103  * @param header
104  */
105 bool toROS(
106  const mrpt::maps::COccupancyGridMap2D& src, nav_msgs::OccupancyGrid& msg,
107  const std_msgs::Header& header);
108 /**
109  * converts mrpt object to ros msg
110  * @return true on sucessful conversion, false on any error.
111  */
112 bool toROS(
113  const mrpt::maps::COccupancyGridMap2D& src, nav_msgs::OccupancyGrid& msg);
114 
115 /** @}
116  * @}
117  */
118 
119 } // namespace mrpt::ros1bridge
static bool loadMap(mrpt::maps::CMultiMetricMap &_metric_map, const mrpt::config::CConfigFileBase &_config_file, const std::string &_map_file="map.simplemap", const std::string &_section_name="metricMap", bool _debug=false)
loads a mprt map
Definition: map.cpp:149
int16_t cellMrpt2Ros(int16_t i)
Definition: map.h:58
int8_t cellRos2Mrpt(int8_t i)
Definition: map.h:63
This class allows loading and storing values and vectors of different types from a configuration text...
nv_oem6_header_t header
Novatel frame: NV_OEM6_BESTPOS.
static MapHdl * instance()
it creates a instance with some look up table to speed up the conversions
Definition: map.cpp:78
int lut_cellmrpt2ros[0xFFFF]
Definition: map.h:36
A class for storing an occupancy grid map.
bool toROS(const mrpt::obs::CObservationGPS &obj, const std_msgs::Header &msg_header, sensor_msgs::NavSatFix &msg)
Convert mrpt::obs::CObservationGPS -> sensor_msgs/NavSatFix The user must supply the "msg_header" fie...
Definition: gps.cpp:48
ROS message: http://docs.ros.org/api/sensor_msgs/html/msg/NavSatFix.html MRPT message: https://github...
Definition: gps.h:28
int lut_cellros2mrpt[101]
Definition: map.h:38
bool fromROS(const sensor_msgs::NavSatFix &msg, mrpt::obs::CObservationGPS &obj)
Convert sensor_msgs/NavSatFix -> mrpt::obs::CObservationGPS.
Definition: gps.cpp:20
#define INT16_MIN
Definition: map.cpp:35
#define INT8_MIN
Definition: map.cpp:33
#define ASSERT_BELOWEQ_(__A, __B)
Definition: exceptions.h:161
This class stores any customizable set of metric maps.
Methods to convert between ROS msgs and MRPT objects for map datatypes.
Definition: map.h:30



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020