23 #include "cartographer_ros_msgs/TrajectorySubmapList.h" 31 : node_options_(node_options),
32 map_builder_(node_options.map_builder_options),
33 tf_buffer_(tf_buffer) {}
36 const std::unordered_set<string>& expected_sensor_ids,
40 LOG(INFO) <<
"Added trajectory with ID '" << trajectory_id <<
"'.";
44 cartographer::common::make_unique<SensorBridge>(
50 CHECK(emplace_result.second ==
true);
55 LOG(INFO) <<
"Finishing trajectory with ID '" << trajectory_id <<
"'...";
64 std::ofstream proto_file(stem +
".pb",
65 std::ios_base::out | std::ios_base::binary);
68 <<
"Could not serialize pose graph.";
70 CHECK(proto_file) <<
"Could not write pose graph.";
74 const auto all_trajectory_nodes =
78 CHECK_EQ(all_trajectory_nodes.size(), 1);
79 if (all_trajectory_nodes[0].empty()) {
80 LOG(WARNING) <<
"No data was collected and no assets will be written.";
82 LOG(INFO) <<
"Writing assets with stem '" << stem <<
"'...";
87 .trajectory_builder_options.trajectory_builder_2d_options()
94 all_trajectory_nodes[0],
96 .trajectory_builder_options.trajectory_builder_3d_options()
105 cartographer_ros_msgs::SubmapQuery::Request& request,
106 cartographer_ros_msgs::SubmapQuery::Response& response) {
107 cartographer::mapping::proto::SubmapQuery::Response response_proto;
109 request.trajectory_id, request.submap_index, &response_proto);
110 if (!error.empty()) {
115 response.submap_version = response_proto.submap_version();
116 response.cells.insert(response.cells.begin(), response_proto.cells().begin(),
117 response_proto.cells().end());
118 response.width = response_proto.width();
119 response.height = response_proto.height();
120 response.resolution = response_proto.resolution();
127 cartographer_ros_msgs::SubmapList submap_list;
130 for (
int trajectory_id = 0;
133 auto*
const trajectory_builder =
135 const int num_submaps = trajectory_builder->
num_submaps();
136 cartographer_ros_msgs::TrajectorySubmapList trajectory_submap_list;
137 for (
int submap_index = 0; submap_index != num_submaps; ++submap_index) {
138 cartographer_ros_msgs::SubmapEntry submap_entry;
139 const auto submap_data = trajectory_builder->GetSubmapData(submap_index);
140 submap_entry.submap_version = submap_data.submap->num_range_data();
142 trajectory_submap_list.submap.push_back(submap_entry);
144 submap_list.trajectory.push_back(trajectory_submap_list);
149 std::unique_ptr<nav_msgs::OccupancyGrid>
152 <<
"Publishing OccupancyGrids for 3D data is not yet supported";
153 std::vector<::cartographer::mapping::TrajectoryNode> flat_trajectory_nodes;
154 for (
const auto& single_trajectory_nodes :
156 flat_trajectory_nodes.insert(flat_trajectory_nodes.end(),
157 single_trajectory_nodes.begin(),
158 single_trajectory_nodes.end());
160 std::unique_ptr<nav_msgs::OccupancyGrid> occupancy_grid;
161 if (!flat_trajectory_nodes.empty()) {
163 cartographer::common::make_unique<nav_msgs::OccupancyGrid>();
168 .trajectory_builder_options.trajectory_builder_2d_options()
170 occupancy_grid.get());
172 return occupancy_grid;
175 std::unordered_map<int, MapBuilderBridge::TrajectoryState>
177 std::unordered_map<int, TrajectoryState> trajectory_states;
179 const int trajectory_id = entry.first;
191 trajectory_states[trajectory_id] = {
200 return trajectory_states;
204 visualization_msgs::MarkerArray trajectory_nodes_list;
205 const auto all_trajectory_nodes =
208 for (
int trajectory_id = 0;
209 trajectory_id < static_cast<int>(all_trajectory_nodes.size());
211 const auto& single_trajectory_nodes = all_trajectory_nodes[trajectory_id];
212 visualization_msgs::Marker marker;
213 marker.id = marker_id++;
214 marker.type = visualization_msgs::Marker::LINE_STRIP;
217 marker.color =
GetColor(trajectory_id);
219 marker.pose.orientation.w = 1.0;
220 for (
const auto& node : single_trajectory_nodes) {
221 if (node.trimmed()) {
225 (node.pose * node.constant_data->tracking_to_pose).translation());
226 marker.points.push_back(node_point);
229 if (marker.points.size() == 16384) {
230 trajectory_nodes_list.markers.push_back(marker);
231 marker.id = marker_id++;
232 marker.points.clear();
234 marker.points.push_back(node_point);
237 trajectory_nodes_list.markers.push_back(marker);
239 return trajectory_nodes_list;
void Write3DAssets(const std::vector<::cartographer::mapping::TrajectoryNode > &trajectory_nodes, const double voxel_size, const std::string &stem)
int AddTrajectoryBuilder(const std::unordered_set< string > &expected_sensor_ids, const proto::TrajectoryBuilderOptions &trajectory_options)
const NodeOptions node_options_
::cartographer::mapping::proto::MapBuilderOptions map_builder_options
mapping::SparsePoseGraph * sparse_pose_graph()
geometry_msgs::Pose ToGeometryMsgPose(const Rigid3d &rigid3d)
geometry_msgs::Point ToGeometryMsgPoint(const Eigen::Vector3d &vector3d)
std::unique_ptr<::cartographer::transform::Rigid3d > LookupToTracking(::cartographer::common::Time time, const string &frame_id) const
void WriteAssets(const string &stem)
const TfBridge & tf_bridge() const
virtual int num_submaps()=0
virtual std::vector< std::vector< TrajectoryNode > > GetTrajectoryNodes()=0
void Write2DAssets(const std::vector<::cartographer::mapping::TrajectoryNode > &trajectory_nodes, const string &map_frame, const ::cartographer::mapping_2d::proto::SubmapsOptions &submaps_options, const std::string &stem)
SensorBridge * sensor_bridge(int trajectory_id)
virtual void RunFinalOptimization()=0
tf2_ros::Buffer *const tf_buffer_
::std_msgs::ColorRGBA GetColor(int id)
void FinishTrajectory(int trajectory_id)
void BuildOccupancyGrid2D(const std::vector<::cartographer::mapping::TrajectoryNode > &trajectory_nodes, const string &map_frame, const ::cartographer::mapping_2d::proto::SubmapsOptions &submaps_options,::nav_msgs::OccupancyGrid *const occupancy_grid)
virtual const PoseEstimate & pose_estimate() const =0
cartographer::mapping::MapBuilder map_builder_
constexpr double kTrajectoryLineStripMarkerScale
visualization_msgs::MarkerArray GetTrajectoryNodesList()
mapping::TrajectoryBuilder * GetTrajectoryBuilder(int trajectory_id) const
cartographer_ros_msgs::SubmapList GetSubmapList()
void SerializeState(const string &stem)
void FinishTrajectory(int trajectory_id)
proto::SparsePoseGraph ToProto()
int64 ToUniversal(const Time time)
::cartographer::mapping::proto::TrajectoryBuilderOptions trajectory_builder_options
string SubmapToProto(int trajectory_id, int submap_index, proto::SubmapQuery::Response *response)
MapBuilderBridge(const NodeOptions &node_options, tf2_ros::Buffer *tf_buffer)
bool HandleSubmapQuery(cartographer_ros_msgs::SubmapQuery::Request &request, cartographer_ros_msgs::SubmapQuery::Response &response)
std::unordered_map< int, TrajectoryOptions > trajectory_options_
int num_trajectory_builders() const
double lookup_transform_timeout_sec
virtual transform::Rigid3d GetLocalToGlobalTransform(int trajectory_id)=0
std::unordered_map< int, TrajectoryState > GetTrajectoryStates()
int AddTrajectory(const std::unordered_set< string > &expected_sensor_ids, const TrajectoryOptions &trajectory_options)
std::unique_ptr< nav_msgs::OccupancyGrid > BuildOccupancyGrid()
std::unordered_map< int, std::unique_ptr< SensorBridge > > sensor_bridges_