Examples

This sections contains examples of how to use the maliput framework by integrating it into various build systems. The examples are using maliput_malidrive as maliput backend as it is the most developed backend, but the same principles apply to other maliput backends as well.

Python

As indicated in the Installation section you can start using maliput by simply installing it via pip.

pip install maliput maliput_malidrive

For adding maliput and maliput_malidrive as dependency for your project you can add them directly to the setup.py file or pyproject.toml file of your project.

For example, if you are relying on poetry for managing your python dependencies you can add the following to your pyproject.toml` file:

[tool.poetry.dependencies]
maliput = "*"
maliput_malidrive = "*"

That’s all the configuration you need to do to start using maliput in your python project.

import maliput

def main():
    filepath = os.path.join(os.path.dirname(__file__), "xodr", "TShapeRoad.xodr")
    params = { "opendrive_file": filepath }

    road_network = maliput.plugin.create_road_network("maliput_malidrive", params)
    road_geometry = road_network.road_geometry()

    inertial_pos = maliput.api.InertialPosition(-0.5, 0, 1.0)
    result = road_geometry.ToRoadPosition(inertial_pos)

You can find a full example at maliput_examples

Bazel

If you are using bazel as your build system you can add maliput and maliput_malidrive as dependency to your project as they are available as bazel packages via the Bazel Central Registry.

Add the dependency to your MODULE, for instance:

bazel_dep(name = "maliput", version = "1.1.1")
bazel_dep(name = "maliput_malidrive", version = "0.1.4")

And remember to link the libraries to your targets in the BUILD` file:

cc_binary(
    name = "my_binary",
    srcs = ["my_binary.cc"],
    deps = [
        "@maliput//:maliput",
        "@maliput_malidrive//:maliput_malidrive",
    ],
)

You can find a full example at maliput_examples

Rust

If you are using cargo as your build system you can add maliput as dependency to your project by adding them to your Cargo.toml file.

[dependencies]
maliput = { version = "^0.1.1"}

You can find a full example at maliput_examples