Creating a maliput backend using maliput_sparse


maliput_sparse is a convenient package that provides several helpers for creating a maliput backend that is expected to be built on top of waypoints without any analytical model of the surface.

By using the builder API, the mathematical model is solved under the hood so the user doesn’t have to dive into complex geometric calculations.

Creating a maliput backend

  1. Implement a maliput_sparse::parser::Parser: This abstract class is responsible for parsing an user-defined underlying road description format and serve the parsed data. During the parsing process, the user will have to fill some data structures about the parsed lanes and connections between them, that will be used by the maliput_sparse’s builder to create the maliput backend.

 1 class MyParser : public Parser {
 2  public:
 3   MyParser(const std::string& my_file) : Parser() {
 4    // TODO:
 5    // Parse underlying file and fill up junctions and connections.
 6   }
 7  private:
 8   const std::unordered_map<Junction::Id, Junction>& DoGetJunctions() const override {
 9     return junctions_;
10   }
11   const std::vector<Connection>& DoGetConnections() const override {
12     return connections_;
13   }
15   // Collection of junctions.
16   std::unordered_map<maliput_sparse::parser::Junction::Id, maliput_sparse::parser::Junction> junctions_{};
17   // Collection of connections;
18   std::vector<maliput_sparse::parser::Connection> connections_{};
19  };

As example: Take a look at the maliput_osm’s parser implementation: maliput_osm::osm::OSMManager.

  1. Once the above class is implemented, the user can make use of the maliput_sparse::loader::RoadNetworkLoader to load the road network from the user-defined format by injecting the previously implemented maliput_sparse::parser::Parser class.

1  maliput_sparse::loader::BuilderConfiguration maliput_sparse_config;
2  // ..
3  // Fill up maliput_sparse_config with the desired parameters.
4  //
5  const std::string my_file{"my_file.txt"};
6  std::unique_ptr<maliput_sparse::parser::Parser> my_parser =
7        std::make_unique<my_parser::MyParser>(my_file);
8  std::unique_ptr<maliput::api::RoadNetwork> road_network = maliput_sparse::loader::RoadNetworkLoader(std::move(my_parser), maliput_sparse_config)();

As example: Take a look at the maliput_osm’s road network loader: maliput_osm::builder::RoadNetworkBuilder.

  1. Finally, it is recommended to provide a maliput::plugin::RoadNetworkLoader implementation with this new backend, in a way that it can be loaded in runtime to be used by packages like maliput_viz.

 1// Implementation of a maliput::plugin::RoadNetworkLoader using a new maliput backend.
 2class RoadNetworkLoader : public maliput::plugin::RoadNetworkLoader {
 4  std::unique_ptr<maliput::api::RoadNetwork> operator()(
 5      const std::map<std::string, std::string>& properties) const override {
 6    // return a unique_ptr to a maliput::api::RoadNetwork.
 7  }
 8  std::map<std::string, std::string> GetDefaultParameters() const override {
 9    // return the default parameters for the backend.
10  }
13}  // namespace
15REGISTER_ROAD_NETWORK_LOADER_PLUGIN("my_maliput_backend", RoadNetworkLoader);

See also Maliput Python Interface for general information about the maliput python interface.

As example take a look at the plugin namespace in any of the provided backends (e.g: maliput_osm).