node.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CARTOGRAPHER_ROS_NODE_H_
18 #define CARTOGRAPHER_ROS_NODE_H_
19 
20 #include <memory>
21 #include <vector>
22 
27 #include "cartographer_ros_msgs/FinishTrajectory.h"
28 #include "cartographer_ros_msgs/SensorTopics.h"
29 #include "cartographer_ros_msgs/StartTrajectory.h"
30 #include "cartographer_ros_msgs/SubmapEntry.h"
31 #include "cartographer_ros_msgs/SubmapList.h"
32 #include "cartographer_ros_msgs/SubmapQuery.h"
33 #include "cartographer_ros_msgs/TrajectoryOptions.h"
34 #include "cartographer_ros_msgs/TrajectorySubmapList.h"
35 #include "cartographer_ros_msgs/WriteAssets.h"
36 #include "ros/ros.h"
38 
39 namespace cartographer_ros {
40 
41 // Default topic names; expected to be remapped as needed.
42 constexpr char kLaserScanTopic[] = "scan";
43 constexpr char kMultiEchoLaserScanTopic[] = "echoes";
44 constexpr char kPointCloud2Topic[] = "points2";
45 constexpr char kImuTopic[] = "imu";
46 constexpr char kOdometryTopic[] = "odom";
47 constexpr char kFinishTrajectoryServiceName[] = "finish_trajectory";
48 constexpr char kOccupancyGridTopic[] = "map";
49 constexpr char kScanMatchedPointCloudTopic[] = "scan_matched_points2";
50 constexpr char kSubmapListTopic[] = "submap_list";
51 constexpr char kSubmapQueryServiceName[] = "submap_query";
52 constexpr char kStartTrajectoryServiceName[] = "start_trajectory";
53 constexpr char kWriteAssetsServiceName[] = "write_assets";
54 constexpr char kTrajectoryNodesListTopic[] = "trajectory_nodes_list";
55 
56 // Wires up ROS topics to SLAM.
57 class Node {
58  public:
59  Node(const NodeOptions& node_options, tf2_ros::Buffer* tf_buffer);
60  ~Node();
61 
62  Node(const Node&) = delete;
63  Node& operator=(const Node&) = delete;
64 
65  // Finishes all yet active trajectories.
66  void FinishAllTrajectories();
67 
68  // Starts the first trajectory with the default topics.
70 
73 
74  private:
75  bool HandleSubmapQuery(
76  cartographer_ros_msgs::SubmapQuery::Request& request,
77  cartographer_ros_msgs::SubmapQuery::Response& response);
79  cartographer_ros_msgs::StartTrajectory::Request& request,
80  cartographer_ros_msgs::StartTrajectory::Response& response);
82  cartographer_ros_msgs::FinishTrajectory::Request& request,
83  cartographer_ros_msgs::FinishTrajectory::Response& response);
84  bool HandleWriteAssets(
85  cartographer_ros_msgs::WriteAssets::Request& request,
86  cartographer_ros_msgs::WriteAssets::Response& response);
87  int AddTrajectory(const TrajectoryOptions& options,
88  const cartographer_ros_msgs::SensorTopics& topics);
89  void LaunchSubscribers(const TrajectoryOptions& options,
90  const cartographer_ros_msgs::SensorTopics& topics,
91  int trajectory_id);
92  void PublishSubmapList(const ::ros::WallTimerEvent& timer_event);
93  void PublishTrajectoryStates(const ::ros::WallTimerEvent& timer_event);
94  void PublishTrajectoryNodesList(const ::ros::WallTimerEvent& timer_event);
96  bool ValidateTrajectoryOptions(const TrajectoryOptions& options);
97  bool ValidateTopicName(const ::cartographer_ros_msgs::SensorTopics& topics,
98  const TrajectoryOptions& options);
99 
101 
103 
104  cartographer::common::Mutex mutex_;
105  MapBuilderBridge map_builder_bridge_ GUARDED_BY(mutex_);
106 
110  // These ros::ServiceServers need to live for the lifetime of the node.
111  std::vector<::ros::ServiceServer> service_servers_;
114  cartographer::common::Time::min();
115 
116  // These are keyed with 'trajectory_id'.
117  std::unordered_map<int, ::ros::Subscriber> laser_scan_subscribers_;
118  std::unordered_map<int, ::ros::Subscriber> multi_echo_laser_scan_subscribers_;
119  std::unordered_map<int, ::ros::Subscriber> odom_subscribers_;
120  std::unordered_map<int, ::ros::Subscriber> imu_subscribers_;
121  std::unordered_map<int, std::vector<::ros::Subscriber>>
123  std::unordered_map<int, bool> is_active_trajectory_ GUARDED_BY(mutex_);
126  bool terminating_ = false GUARDED_BY(mutex_);
127 
128  // We have to keep the timer handles of ::ros::WallTimers around, otherwise
129  // they do not fire.
130  std::vector<::ros::WallTimer> wall_timers_;
131 };
132 
133 } // namespace cartographer_ros
134 
135 #endif // CARTOGRAPHER_ROS_NODE_H_
Node & operator=(const Node &)=delete
::ros::Publisher trajectory_nodes_list_publisher_
Definition: node.h:109
std::vector<::ros::ServiceServer > service_servers_
Definition: node.h:111
void FinishAllTrajectories()
Definition: node.cc:493
void PublishTrajectoryNodesList(const ::ros::WallTimerEvent &timer_event)
Definition: node.cc:230
bool ValidateTopicName(const ::cartographer_ros_msgs::SensorTopics &topics, const TrajectoryOptions &options)
Definition: node.cc:382
bool ValidateTrajectoryOptions(const TrajectoryOptions &options)
Definition: node.cc:365
MapBuilderBridge * map_builder_bridge()
Definition: node.cc:155
void PublishSubmapList(const ::ros::WallTimerEvent &timer_event)
Definition: node.cc:164
constexpr char kFinishTrajectoryServiceName[]
Definition: node.h:47
std::thread occupancy_grid_thread_
Definition: node.h:125
constexpr char kImuTopic[]
Definition: node.h:45
cartographer::common::Mutex mutex_
Definition: node.h:104
const NodeOptions node_options_
Definition: node.h:100
constexpr char kTrajectoryNodesListTopic[]
Definition: node.h:54
constexpr char kLaserScanTopic[]
Definition: node.h:42
tf2_ros::TransformBroadcaster tf_broadcaster_
Definition: node.h:102
bool HandleStartTrajectory(cartographer_ros_msgs::StartTrajectory::Request &request, cartographer_ros_msgs::StartTrajectory::Response &response)
Definition: node.cc:415
::ros::Publisher scan_matched_point_cloud_publisher_
Definition: node.h:112
UniversalTimeScaleClock::time_point Time
void SpinOccupancyGridThreadForever()
Definition: node.cc:239
::ros::Publisher submap_list_publisher_
Definition: node.h:108
options
std::unordered_map< int,::ros::Subscriber > odom_subscribers_
Definition: node.h:119
::ros::NodeHandle node_handle_
Definition: node.h:107
std::vector<::ros::WallTimer > wall_timers_
Definition: node.h:130
int AddTrajectory(const TrajectoryOptions &options, const cartographer_ros_msgs::SensorTopics &topics)
Definition: node.cc:258
constexpr char kScanMatchedPointCloudTopic[]
Definition: node.h:49
MapBuilderBridge map_builder_bridge_ GUARDED_BY(mutex_)
std::unordered_map< int,::ros::Subscriber > imu_subscribers_
Definition: node.h:120
constexpr char kStartTrajectoryServiceName[]
Definition: node.h:52
bool HandleWriteAssets(cartographer_ros_msgs::WriteAssets::Request &request, cartographer_ros_msgs::WriteAssets::Response &response)
Definition: node.cc:484
std::unordered_map< int,::ros::Subscriber > laser_scan_subscribers_
Definition: node.h:117
constexpr char kOdometryTopic[]
Definition: node.h:46
cartographer::common::Time last_scan_matched_point_cloud_time_
Definition: node.h:113
::ros::NodeHandle * node_handle()
Definition: node.cc:153
constexpr char kOccupancyGridTopic[]
Definition: node.h:48
bool HandleFinishTrajectory(cartographer_ros_msgs::FinishTrajectory::Request &request, cartographer_ros_msgs::FinishTrajectory::Response &response)
Definition: node.cc:452
void StartTrajectoryWithDefaultTopics(const TrajectoryOptions &options)
Definition: node.cc:438
constexpr char kWriteAssetsServiceName[]
Definition: node.h:53
constexpr char kMultiEchoLaserScanTopic[]
Definition: node.h:43
std::unordered_map< int, std::vector<::ros::Subscriber > > point_cloud_subscribers_
Definition: node.h:122
::ros::Publisher occupancy_grid_publisher_
Definition: node.h:124
constexpr char kSubmapQueryServiceName[]
Definition: node.h:51
Node(const NodeOptions &node_options, tf2_ros::Buffer *tf_buffer)
Definition: node.cc:100
constexpr char kPointCloud2Topic[]
Definition: node.h:44
constexpr char kSubmapListTopic[]
Definition: node.h:50
std::unordered_map< int,::ros::Subscriber > multi_echo_laser_scan_subscribers_
Definition: node.h:118
bool HandleSubmapQuery(cartographer_ros_msgs::SubmapQuery::Request &request, cartographer_ros_msgs::SubmapQuery::Response &response)
Definition: node.cc:157
void LaunchSubscribers(const TrajectoryOptions &options, const cartographer_ros_msgs::SensorTopics &topics, int trajectory_id)
Definition: node.cc:287
tf2_ros::Buffer * tf_buffer
void PublishTrajectoryStates(const ::ros::WallTimerEvent &timer_event)
Definition: node.cc:169
const std::string response


cartographer_ros
Author(s):
autogenerated on Wed Jun 5 2019 22:35:56