init_utils.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_ROS_INIT_UTILS_H
2 #define SLAM_CTOR_ROS_INIT_UTILS_H
3 
4 #include <string>
5 #include <memory>
6 
7 #include <ros/ros.h>
8 
9 #include "../core/states/world.h"
10 
11 #include "../utils/properties_providers.h"
12 #include "topic_with_transform.h"
14 #include "robot_pose_observers.h"
16 
17 // TODO: remove
18 std::string get_string_param(const std::string &name,
19  const std::string &dflt_value) {
20  std::string value;
21  ros::param::param<std::string>(name, value, dflt_value);
22  return value;
23 }
24 
26  return props.get_str("in/lscan2D/ros/topic/name", "/base_scan");
27 }
28 
29 std::string tf_odom_frame_id(const PropertiesProvider &props) {
30  return props.get_str("in/odometry/ros/tf/odom_frame_id", "odom_combined");
31 }
32 
33 std::string tf_map_frame_id() { // TODO: obtain from props
34  return get_string_param("~ros/tf/map_frame_id", "map");
35 }
36 
37 std::string tf_robot_pose_frame_id() {
38  return get_string_param("~ros/tf/robot_pose_frame_id", "robot_pose");
39 }
40 
42  bool async_correction;
43  ros::param::param<bool>("~ros/tf/async_correction", async_correction, false);
44  return async_correction;
45 }
46 
47 // scan handling
48 
50  return props.get_bool("in/lscan2D/skip_exceeding_vals",
51  false);
52 }
53 
54 // performance
55 
57  return props.get_bool("slam/performance/use_trig_cache", false);
58 }
59 
60 // TODO: move to IO
61 
63  std::string Rec_Sep = ":", Entry_Sep = "-";
64  std::unordered_map<std::string, std::vector<std::string>> ignores;
65 
66  auto data = props.get_str("in/odometry/ros/tf/ignore", "");
67  auto next_entry_i = std::string::size_type{0};
68  while (next_entry_i < data.length()) {
69  auto next_sep_i = data.find(Rec_Sep, next_entry_i);
70  if (next_sep_i == std::string::npos) {
71  next_sep_i = data.length();
72  }
73 
74  auto entry = data.substr(next_entry_i, next_sep_i - next_entry_i);
75  next_entry_i = next_sep_i + 1;
76 
77  auto entry_sep_i = entry.find("-");
78  if (entry_sep_i == std::string::npos) {
79  std::cout << "[WARN] Unable to parse tf_ignore entry \""
80  << entry << "\"" << std::endl;
81  continue;
82  }
83  auto from = entry.substr(0, entry_sep_i);
84  auto to = entry.substr(entry_sep_i + 1, entry.size() - entry_sep_i - 1);
85  ignores["/" + from].push_back("/" + to);
86  }
87  return ignores;
88 }
89 
90 template <typename ObservT, typename MapT>
91 std::shared_ptr<PoseCorrectionTfPublisher<ObservT>>
93  TopicWithTransform<ObservT> *scan_prov,
94  const PropertiesProvider &props) {
95  auto pose_publisher = std::make_shared<PoseCorrectionTfPublisher<ObservT>>(
97  );
98  scan_prov->subscribe(pose_publisher);
99  slam->subscribe_pose(pose_publisher);
100  return pose_publisher;
101 }
102 
103 template <typename MapT>
104 std::shared_ptr<RobotPoseTfPublisher>
106  auto pose_publisher = std::make_shared<RobotPoseTfPublisher>(
108  slam->subscribe_pose(pose_publisher);
109  return pose_publisher;
110 }
111 
112 template <typename ObservT, typename MapT>
114  WorldObservable<MapT> *slam,
115  TopicWithTransform<ObservT> *scan_provider,
116  const PropertiesProvider &props) {
118  auto stamped_pose_publisher =
119  std::make_shared<PosePubT>(tf_map_frame_id(),
121  scan_provider->subscribe(stamped_pose_publisher);
122  slam->subscribe_pose(stamped_pose_publisher);
123  return stamped_pose_publisher;
124 }
125 
126 template <typename MapT>
127 std::shared_ptr<OccupancyGridPublisher<MapT>>
129  ros::NodeHandle nh,
130  double ros_map_publishing_rate) {
131  auto map_publisher = std::make_shared<OccupancyGridPublisher<MapT>>(
132  nh.advertise<nav_msgs::OccupancyGrid>("map", 5),
133  tf_map_frame_id(), ros_map_publishing_rate);
134  slam->subscribe_map(map_publisher);
135  return map_publisher;
136 }
137 
138 void init_constants_for_ros(double &ros_tf_buffer_size,
139  double &ros_map_rate,
140  int &ros_filter_queue,
141  int &ros_subscr_queue) {
142  ros::param::param<double>("~ros/tf/buffer_duration",ros_tf_buffer_size, 5.0);
143  ros::param::param<double>("~ros/rviz/map_publishing_rate", ros_map_rate, 5.0);
144  ros::param::param<int>("~ros/filter_queue_size",ros_filter_queue, 1000);
145  ros::param::param<int>("~ros/subscribers_queue_size",ros_subscr_queue, 1000);
146 }
147 
148 #endif
std::shared_ptr< PoseCorrectionTfPublisher< ObservT > > create_pose_correction_tf_publisher(WorldObservable< MapT > *slam, TopicWithTransform< ObservT > *scan_prov, const PropertiesProvider &props)
Definition: init_utils.h:92
auto tf_ignored_transforms(const PropertiesProvider &props)
Definition: init_utils.h:62
virtual str get_str(const std::string &id, const str &dflt) const =0
std::shared_ptr< RobotPoseTfPublisher > create_robot_pose_tf_publisher(WorldObservable< MapT > *slam)
Definition: init_utils.h:105
std::string laser_scan_2D_ros_topic_name(const PropertiesProvider &props)
Definition: init_utils.h:25
bool get_use_trig_cache(const PropertiesProvider &props)
Definition: init_utils.h:56
std::shared_ptr< OccupancyGridPublisher< MapT > > create_occupancy_grid_publisher(WorldObservable< MapT > *slam, ros::NodeHandle nh, double ros_map_publishing_rate)
Definition: init_utils.h:128
void subscribe_map(std::shared_ptr< WorldMapObserver< MapType >> obs)
Definition: world.h:34
std::string tf_odom_frame_id(const PropertiesProvider &props)
Definition: init_utils.h:29
void subscribe(std::shared_ptr< TopicObserver< MsgType >> obs)
void subscribe_pose(std::shared_ptr< WorldPoseObserver > obs)
Definition: world.h:38
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::string tf_robot_pose_frame_id()
Definition: init_utils.h:37
void init_constants_for_ros(double &ros_tf_buffer_size, double &ros_map_rate, int &ros_filter_queue, int &ros_subscr_queue)
Definition: init_utils.h:138
auto make_pose_correction_observation_stamped_publisher(WorldObservable< MapT > *slam, TopicWithTransform< ObservT > *scan_provider, const PropertiesProvider &props)
Definition: init_utils.h:113
bool is_async_correction()
Definition: init_utils.h:41
bool get_skip_exceeding_lsr(const PropertiesProvider &props)
Definition: init_utils.h:49
virtual bool get_bool(const std::string &id, bool dflt) const =0
std::string get_string_param(const std::string &name, const std::string &dflt_value)
Definition: init_utils.h:18
std::string tf_map_frame_id()
Definition: init_utils.h:33


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