### Install and build with Conan Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/README.md Experimental setup for non-Catkin users using Conan to manage dependencies and build the project. ```bash pip install conan catkin_pkg numpy git clone https://github.com/fzi-forschungszentrum-informatik/lanelet2.git cd lanelet2 ``` ```bash conan create . --build=missing ``` ```bash source activate.sh python -c "import lanelet2" # or whatever you want to do source deactivate.sh ``` -------------------------------- ### Installation Configuration Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_maps/CMakeLists.txt Installs targets, headers, scripts, and additional files. ```cmake mrt_install(PROGRAMS scripts FILES res data ${PROJECT_INSTALL_FILES}) ``` -------------------------------- ### Setup Python modules and API Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_python/CMakeLists.txt Configures Python module installation and builds the C++ Python API library. ```cmake ######################## ## Add python modules ## ######################## # This adds a python module if located under src/{PROJECT_NAME) mrt_python_module_setup() mrt_glob_files(PROJECT_PYTHON_SOURCE_FILES_SRC "python_api/*.cpp") if (PROJECT_PYTHON_SOURCE_FILES_SRC) # Add a cpp-python api library. Make sure there are no name collisions with python modules in this project mrt_add_python_api( lanelet2 FILES ${PROJECT_PYTHON_SOURCE_FILES_SRC} ) _mrt_get_python_destination(PROJECT_PYTHON_DESTINATION) mrt_glob_files(PROJECT_PYTHON_STUBS "typings/lanelet2/*.pyi") install(FILES ${PROJECT_PYTHON_STUBS} DESTINATION ${PROJECT_PYTHON_DESTINATION}/lanelet2) endif() ``` -------------------------------- ### Build and run Lanelet2 in Docker Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/README.md Commands to build a Docker image, start a container, and verify the Python installation. ```bash docker build -t lanelet2 . # builds a docker image named "lanelet2" docker run -it --rm lanelet2:latest /bin/bash # starts the docker image python -c "import lanelet2" # quick check to see everything is fine ``` -------------------------------- ### Define library build and installation Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_python/CMakeLists.txt Collects source files and defines the library build and installation targets. ```cmake ############################ ## Read source code files ## ############################ mrt_glob_files_recurse(PROJECT_HEADER_FILES_INC "include/*.h" "include/*.hpp" "include/*.cuh") mrt_glob_files(PROJECT_SOURCE_FILES_INC "src/*.h" "src/*.hpp" "src/*.cuh") mrt_glob_files(PROJECT_SOURCE_FILES_SRC "src/*.cpp" "src/*.cu") ########### ## Build ## ########### # Declare a cpp library mrt_add_library(${PROJECT_NAME} INCLUDES ${PROJECT_HEADER_FILES_INC} ${PROJECT_SOURCE_FILES_INC} SOURCES ${PROJECT_SOURCE_FILES_SRC} ) ############# ## Install ## ############# # Install all targets, headers by default and scripts and other files if specified (folders or files). # This command also exports libraries and config files for dependent packages and this supersedes catkin_package. mrt_install(PROGRAMS scripts FILES res data ${PROJECT_INSTALL_FILES}) ``` -------------------------------- ### Setup Python Modules Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Configures Python modules located under the src/{PROJECT_NAME} directory. This function handles the setup process. ```cmake mrt_python_module_setup() ``` -------------------------------- ### Python Module and API Setup Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_maps/CMakeLists.txt Configures Python modules and adds C++ Python API libraries. ```cmake # This adds a python module if located under src/{PROJECT_NAME) mrt_python_module_setup() mrt_glob_files(PROJECT_PYTHON_SOURCE_FILES_SRC "python_api/*.cpp") if (PROJECT_PYTHON_SOURCE_FILES_SRC) # Add a cpp-python api library. Make sure there are no name collisions with python modules in this project mrt_add_python_api( ${PROJECT_NAME} FILES ${PROJECT_PYTHON_SOURCE_FILES_SRC} ) endif() ``` -------------------------------- ### Install ROS dependencies on Ubuntu Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/README.md Commands to install required ROS packages and system dependencies for Lanelet2. ```bash sudo apt-get install ros-melodic-rospack ros-melodic-catkin ros-melodic-mrt-cmake-modules ``` ```bash sudo apt-get install libboost-dev libeigen3-dev libgeographic-dev libpugixml-dev libpython-dev libboost-python-dev python-catkin-tools ``` -------------------------------- ### Read OSM and Write Binary Map Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_io/README.md Example demonstrates reading a map from an .osm file and writing it to a .bin file. Ensure the correct origin is provided for accurate map loading. ```C++ #include std::string filename_in = "mymap.osm"; lanelet::Origin origin(49.0, 8.4); lanelet::LaneletMapPtr laneletMap = lanelet::load(filenameIn, origin); std::string filename_out = "mymap.bin"; lanelet::write(filenameOut, *laneletMap); ``` -------------------------------- ### Install Lanelet2 with ROS Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/README.md Installs the Lanelet2 package for a specific ROS distribution using apt. Ensure your ROS distribution is supported. ```bash sudo apt install ros-noetic-lanelet2 ``` -------------------------------- ### Other Route Queries (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Provides examples for retrieving the shortest path, the full lane sequence, and the remaining lane sequence for a given lanelet within a route. ```cpp // Get underlying shortest path Optional shortestPath = route->shortestPath(); // Get the full lane of a given lanelet 'll' LaneletSequence fullLane = route->fullLane(ll); // Get remaining lane of a given lanelet 'll' LaneletSequence remainingLane = route->remainingLane(ll); ``` -------------------------------- ### Get and Write a Route (Python) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Python equivalent for retrieving a route and writing its LaneletSubmap to an OSM file. Handles cases where no route is found. ```python route = graph.getRoute(fromLanelet, toLanelet, routingCostId) if route: laneletSubmap = route.laneletSubmap() lanelet2.io.write("route.osm", laneletSubmap.laneletMap(), lanelet2.io.Origin(49, 8))) ``` -------------------------------- ### Update Pip for Lanelet2 Installation Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/README.md Updates the pip package installer to the latest version, which may be necessary for installing Lanelet2 if older versions cause errors. ```bash pip3 install -U pip ``` -------------------------------- ### Install Lanelet2 without ROS (PyPI) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/README.md Installs the Lanelet2 Python package using pip. Requires Python 3.8-3.11 on Linux. Ensure pip is up-to-date for compatibility. ```bash pip install lanelet2 ``` -------------------------------- ### Get a Shortest Path Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Queries the routing graph for the shortest path between two lanelets. ```cpp Optional shortestPath = graph->shortestPath(fromLanelet, toLanelet); ``` ```python shortestPath = graph.shortestPath(fromLanelet, toLanelet) ``` -------------------------------- ### Get and Write Route Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Obtain a route between two lanelets and export the associated lanelet map. The Optional will be uninitialized if no route is found. ```c++ Optional route = graph->getRoute(*fromLanelet, *toLanelet, routingCostId); write(std::string("route.osm"), *route->getLaneletMap()); ``` -------------------------------- ### Get and Write a Route (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Retrieves a route between two lanelets and writes the corresponding LaneletSubmap to an OSM file. Note that Optional will be uninitialized if no route is found. ```cpp Optional route = graph->getRoute(fromLanelet, toLanelet, routingCostId); if (route) { LaneletSubmapConstPtr routeMap = route->laneletSubmap(); write("route.osm", *routeMap->laneletMap(), Origin({49, 8})); } ``` -------------------------------- ### Conditional Customization with custom.cmake Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Allows for project-specific customizations by including a custom.cmake file if it exists. This can modify dependencies or installation targets. ```cmake if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake") endif() ``` -------------------------------- ### Relational Queries on Routes (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Performs relational queries on a route, such as getting the left lanelet relation or conflicting lanelets within the route. Note that a route only returns relations to lanelets usable for reaching the goal. ```cpp // Get left lanelet of example lanelet 'll' Optional left = route->leftRelation(ll); // Get conflicting lanelets of 'll' ConstLanelets conflicting = route->conflictingInRoute(ll); ``` -------------------------------- ### Get Reachable Set of Lanelets (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Finds all lanelets reachable from a given lanelet within a specified maximum routing cost. Requires a routingCostId. ```cpp double maxRoutingCost{100}; ConstLanelets reachableSet = graph->reachableSet(lanelet, maxRoutingCost, routingCostId); ``` -------------------------------- ### Get Adjacent Lanelets (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Retrieves adjacent lanelets (left, right, following) from a given lanelet. Differentiates between routable and non-routable adjacent lanelets. ```cpp // Get routable left lanelet if it exists Optional left{graph->left(fromLanelet)}; // Get non-routable left lanelet if it exists Optional adjacentLeft{graph->adjacentLeft(fromLanelet)}; // Get following lanelets ConstLanelets following{graph->following(fromLanelet)}; ``` -------------------------------- ### Get Lanelet Relations (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Obtains lanelet relations, specifically 'left' or 'adjacentLeft', returning a vector of LaneletRelations. This provides more detailed relational information than direct lanelet retrieval. ```cpp // Get relations to all left lanelets LaneletRelations leftRelations = graph->leftRelations( fromLanelet); ``` -------------------------------- ### Build Lanelet2 with Catkin Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/README.md Standard workflow for initializing a Catkin workspace, cloning the repository, and building the project. ```shell source /opt/ros/$ROS_DISTRO/setup.bash mkdir catkin_ws && cd catkin_ws && mkdir src catkin init catkin config --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo # build in release mode (or whatever you prefer) cd src git clone https://github.com/fzi-forschungszentrum-informatik/lanelet2.git cd .. catkin build ``` -------------------------------- ### Create a Routing Graph Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Initializes a routing graph using a map, traffic rules, and optional cost configurations. ```cpp using namespace lanelet; // Load a map LaneletMapPtr map = load("map.osm", Origin({49, 8})); // origin has to be close to the map data in lat/lon coordinates // Initialize traffic rules TrafficRulesPtr trafficRules{TrafficRulesFactory::instance().create(Locations::Germany, Participants::Vehicle)}; // Optional: Initalize routing costs double laneChangeCost = 2; RoutingCostPtrs costPtrs{std::make_shared(laneChangeCost)}; // Optional: Initialize config for routing graph: RoutingGraph::Configuration routingGraphConf; routingGraphConf.emplace(std::make_pair(RoutingGraph::ParticipantHeight, Attribute("2."))); // Create routing graph RoutingGraphPtr graph = RoutingGraph::build(map, trafficRules /*, costPtrs, routingGraphConf*/); ``` ```python import lanelet2 map = lanelet2.io.load("map.osm", lanelet2.io.Origin(49, 8)) trafficRules = lanelet2.traffic_rules.create(lanelet2.traffic_rules.Locations.Germany, lanelet2.traffic_rules.Participants.Vehicle) graph = lanelet2.routing.RoutingGraph(map, trafficRules) ``` -------------------------------- ### CMake Project Initialization Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_maps/CMakeLists.txt Initializes the project version and minimum CMake requirements. ```cmake set(MRT_PKG_VERSION 4.0.0) # Modify only if you know what you are doing! cmake_minimum_required(VERSION 3.5.1) project(lanelet2_maps) ``` -------------------------------- ### Create RoutingGraphContainer (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Demonstrates how to create a RoutingGraphContainer by combining multiple RoutingGraphPtr objects, enabling queries across different participant graphs. ```cpp std::vector graphs; graphs.emplace_back(vehicleGraphLaneletMap); graphs.emplace_back(pedestrianGraphLaneletMap); RoutingGraphContainer container(graphs); ``` -------------------------------- ### Prepare Routing Cost Modules Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Prepares a collection of routing cost modules for use in the routing graph. Each module is moved into the collection. ```cpp RoutingCostUPtrs costPtrs; costPtrs.push_back(std::move(distancePtr)); RoutingCostId routingCostId{0}; ``` -------------------------------- ### Configure CMake project and dependencies Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_python/CMakeLists.txt Initializes the project version and resolves required dependencies using mrt_cmake_modules. ```cmake set(MRT_PKG_VERSION 4.0.0) # Modify only if you know what you are doing! cmake_minimum_required(VERSION 3.5.1) project(lanelet2_python) ################### ## Find packages ## ################### find_package(mrt_cmake_modules REQUIRED) include(UseMrtStdCompilerFlags) include(GatherDeps) # You can add a custom.cmake in order to add special handling for this package. E.g. you can do: # list(REMOVE_ITEM DEPENDEND_PACKAGES ...) # To remove libs which cannot be found automatically. You can also "find_package" other, custom dependencies there. # You can also set PROJECT_INSTALL_FILES to install files that are not installed by default. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake") endif() find_package(AutoDeps REQUIRED COMPONENTS ${DEPENDEND_PACKAGES}) mrt_parse_package_xml() ``` -------------------------------- ### Create and use traffic rules Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/README.md Instantiate traffic rules for a specific location and participant, then query passability and speed limits for a lanelet. ```c++ #include lanelet::traffic_rules::TrafficRulesPtr trafficRulesPtr = lanelet::traffic_rules::TrafficRulesFactory::create(lanelet::Locations::Germany, lanelet::Participants::Vehicle); bool passable = trafficRulesPtr->canPass(myLanelet); lanelet::traffic_rules::SpeedLimitInformation speedLimit = trafficRulesPtr->speedLimit(myLanelet); ``` -------------------------------- ### Configure Lanelet2 build system Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2/CMakeLists.txt Detects the environment ROS version and configures the project for catkin or ament_cmake accordingly. ```cmake cmake_minimum_required(VERSION 3.5.1) project(lanelet2) if($ENV{ROS_VERSION} EQUAL 1) find_package(catkin REQUIRED) install(FILES package.xml DESTINATION share/lanelet2) elseif($ENV{ROS_VERSION} EQUAL 2) if(POLICY CMP0057) cmake_policy(SET CMP0057 NEW) endif() find_package(ament_cmake_core REQUIRED) ament_package() endif() ``` -------------------------------- ### Create Routing Graph Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Constructs a routing graph from a Lanelet map, traffic rules, and configured routing cost modules. Optional configuration for the graph can be provided. ```cpp RoutingGraph::Configuration routingGraphConf; routingGraphConf.emplace(std::make_pair( RoutingGraph::ParticipantHeight, Attribute("2."))); RoutingCostUPtrs costPtrs; costPtrs.push_back(std::move(distancePtr)); RoutingCostId routingCostId{0}; RoutingGraphPtr graph = std::make_shared( map, traffic ``` -------------------------------- ### Package Dependency Management Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_maps/CMakeLists.txt Finds required packages and includes custom configuration if present. ```cmake find_package(mrt_cmake_modules REQUIRED) include(UseMrtStdCompilerFlags) include(GatherDeps) # You can add a custom.cmake in order to add special handling for this package. E.g. you can do: # list(REMOVE_ITEM DEPENDEND_PACKAGES ...) # To remove libs which cannot be found automatically. You can also "find_package" other, custom dependencies there. # You can also set PROJECT_INSTALL_FILES to install files that are not installed by default. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake") include("${CMAKE_CURRENT_SOURCE_DIR}/custom.cmake") endif() find_package(AutoDeps REQUIRED COMPONENTS ${DEPENDEND_PACKAGES}) mrt_parse_package_xml() ``` -------------------------------- ### Initialize Traffic Rules Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Initializes traffic rules for a specific location and participant type. Configuration options can be passed to tailor the rules. ```cpp TrafficRules::Configuration vehicleConf; TrafficRulesPtr trafficRules{ TrafficRulesFactory::instance().create(Locations::Germany, Participants::Vehicle, vehicleConf)}; ``` -------------------------------- ### Export Routing Graph to GraphViz and GraphML (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Exports the routing graph in GraphViz (.gv) and GraphML (.xml) formats. These formats can be viewed with graph visualization tools like Gephi, though lanelet localization is not preserved. ```cpp graph->exportGraphViz("~/graph.gv"); graph->exportGraphML("~/graph.graphml"); ``` -------------------------------- ### Set Project Version Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Sets the version for the project. This is a standard CMake variable. ```cmake set(MRT_PKG_VERSION 4.0.0) ``` -------------------------------- ### Load Lanelet2 Map Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Loads a map from a file using the lanelet2_io library. Ensure the map file exists at the specified path. ```cpp auto uniqueMap = load("map.osm"); LaneletMapPtr map = std::move(uniqueMap); ``` -------------------------------- ### Minimum CMake Version and Project Name Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Specifies the minimum required CMake version and declares the project name. Essential for any CMake project. ```cmake cmake_minimum_required(VERSION 3.5.1) project(lanelet2_traffic_rules) ``` -------------------------------- ### Export Debug LaneletMap (C++) Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Generates a debug LaneletMap containing routing information and writes it to an OSM file. This map is best viewed with JOSM and a custom map style. ```cpp LaneletMapConstPtr debugLaneletMap = graph->getDebugLaneletMap(RoutingCostId(0)); write(std::string("routing_graph.osm"), *debugLaneletMap); ``` -------------------------------- ### Query Route Details Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Extract specific components of a route, including the underlying shortest path, the full lane of a lanelet, or the remaining lane. ```c++ // Get underlying shortest path ConstLanelets shortestPath = route->shortestPath(); // Get the full lane of a given lanelet 'll' ConstLanelets fullLane = route->fullLane(ll); // Get remaining lane of a given lanelet 'll' ConstLanelets remainingLane = route->remainingLane(ll); ``` -------------------------------- ### Test Target Configuration Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_maps/CMakeLists.txt Adds C++ and Python test targets if testing is enabled. ```cmake if (CATKIN_ENABLE_TESTING) mrt_add_tests(test) mrt_add_nosetests(test) endif() ``` -------------------------------- ### Python Lanelet Matching Functions Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_matching/README.md This Python code demonstrates how to perform deterministic lanelet matching and filter results based on traffic rules. Ensure you import the 'lanelet2.matching' submodule. ```python import lanelet2 # Note: in the standalone version of lanelet2_matching, the python module was named # "lanelet2_matching". Now it is a submodule of lanelet2: "lanelet2.matching" # create objects to match obj = lanelet2.matching.Object2d() # retrievelanelet matches from map matches = lanelet2.matching.getDeterministicMatches(lanelet_map, obj, 4.) # max distance = 4m # remove non-compliant matches (such as driving in the wrong direction) compliant_matches = lanelet2.matching.removeNonRuleCompliantMatches(matches, traffic_rules) ``` -------------------------------- ### Load and Modify Lanelet Map in Python Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_python/README.md Load a Lanelet2 map from an OSM file and modify attributes of lanelets. Ensure Lanelet2 is built and sourced before running. ```python import lanelet2 map = lanelet2.io.load("myfile.osm", lanelet2.io.Origin(49,8.4)) # Modify/Add attribute to all lanelets for elem in map.laneletLayer: if "participant:vehicle" in elem.attributes: elem.attributes["participant:vehicle"] = "no" ``` -------------------------------- ### Source File Globbing Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_maps/CMakeLists.txt Collects header and source files for the project. ```cmake mrt_glob_files_recurse(PROJECT_HEADER_FILES_INC "include/*.h" "include/*.hpp" "include/*.cuh") mrt_glob_files(PROJECT_SOURCE_FILES_INC "src/*.h" "src/*.hpp" "src/*.cuh") mrt_glob_files(PROJECT_SOURCE_FILES_SRC "src/*.cpp" "src/*.cu") ``` -------------------------------- ### Glob Python API Source Files Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Recursively finds all .cpp files in the python_api directory for the Python API. Stores the list in PROJECT_PYTHON_SOURCE_FILES_SRC. ```cmake mrt_glob_files(PROJECT_PYTHON_SOURCE_FILES_SRC "python_api/*.cpp") ``` -------------------------------- ### Configure test targets Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_python/CMakeLists.txt Adds C++ and Python test targets if testing is enabled. ```cmake ############# ## Testing ## ############# # Add test targets for cpp and python tests if (CATKIN_ENABLE_TESTING) mrt_add_tests(test) mrt_add_nosetests(test) endif() ``` -------------------------------- ### Boost Geometry Distance Calculation Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_core/doc/Architecture.md Demonstrates calculating the distance between two Lanelet2 points using boost::geometry. The result is in 2D or 3D depending on the point dimension. ```cpp double d = boost::geometry::distance(laneletPoint1, laneletPoint2); ``` -------------------------------- ### Parse Package XML Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Parses the package.xml file to gather package information. This is a common step in ROS-based projects. ```cmake mrt_parse_package_xml() ``` -------------------------------- ### Define Routing Cost Module Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Creates a routing cost module, such as for distance, with a specified lane change cost. This influences path preference in routing. ```cpp constexpr double LaneChangeCost{2.}; std::unique_ptr distancePtr( std::make_unique(LaneChangeCost)); ``` -------------------------------- ### Query Lanelets Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Retrieve adjacent lanelets like left, adjacent left, and following lanelets. Use these to navigate or analyze lane connectivity. ```c++ // Get routable left lanelet if it exists Optional left = graph->left(*fromLanelet); // Get non-routable left lanelet if it exists Optional adjacentLeft = graph->adjacentLeft( *fromLanelet); // Get following lanelets ConstLanelets following = graph->following(*fromLanelet); ``` ```c++ // Get relations to all left lanelets ConstLaneletRelations leftRelations = graph->leftRelations( *fromLanelet); // with using ConstLaneletRelation = std::pair; ``` -------------------------------- ### Library Declaration Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_maps/CMakeLists.txt Declares the C++ library using the collected source files. ```cmake mrt_add_library(${PROJECT_NAME} INCLUDES ${PROJECT_HEADER_FILES_INC} ${PROJECT_SOURCE_FILES_INC} SOURCES ${PROJECT_SOURCE_FILES_SRC} ) ``` -------------------------------- ### Calculate Shortest Path Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Find the shortest path between two lanelets using a specified routing cost ID. The result will be empty if no path exists. ```c++ ConstLanelets shortestPath = graph->shortestPath(*fromLanelet, *toLanelet, routingCostId); ``` -------------------------------- ### C++ Lanelet Matching Functions Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_matching/README.md Use these functions to find deterministic or probabilistic lanelet matches for an object. You can also filter matches based on traffic rules. Requires including . ```cpp #include // create objects to match lanelet::matching::Object2d obj; // deterministic lanelet::matching::ObjectWithCovariance2d obj2; // considering uncertainty // retrievelanelet matches from map auto detMatches = getDeterministicMatches(laneletMap, obj, 4.); // max distance = 4m auto probMatches = getProbabilisticMatches(laneletMap, obj2, 4.); // max distance = 4m // remove non-compliant matches (such as driving in the wrong direction) auto compliantDetMatches = removeNonRuleCompliantMatches(detMatches, trafficRulesPtr); auto compliantProbMatches = removeNonRuleCompliantMatches(probMatches, trafficRulesPtr); ``` -------------------------------- ### Add C++ Python API Library Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Adds a C++ library that serves as a Python API. Ensure no name collisions with other Python modules in the project. ```cmake mrt_add_python_api( ${PROJECT_NAME} FILES ${PROJECT_PYTHON_SOURCE_FILES_SRC} ) ``` -------------------------------- ### Find Required Packages Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Finds necessary external packages using CMake's find_package command. Includes custom modules and standard compiler flags. ```cmake find_package(mrt_cmake_modules REQUIRED) include(UseMrtStdCompilerFlags) include(GatherDeps) ``` -------------------------------- ### Query Route Relations Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/doc/lanelet2_routing.html Access relational information within a route, such as the left lanelet or conflicting lanelets. These relations are limited to lanelets usable for reaching the goal. ```c++ // Get left lanelet of example lanelet 'll' Optional left = route->leftRelation(ll); // Get conflicting lanelets of 'll' ConstLanelets conflicting = route->conflictingInRoute(ll); ``` -------------------------------- ### Query conflicting lanelets for a whole route Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Use these methods to identify conflicting lanelets for an entire route, supporting queries within a single graph or across all graphs. ```cpp // Conflicting lanelets of a route in a single graph ConstLanelets conflictingVehicle{container->conflictingOfRouteInGraph(routePtr, routingGraphId)}; // Conflicting lanelets of a route in all graphs RoutingGraphContainer::ConflictingInGraphs result{container->conflictingOfRouteInGraphs(routePtr, heightClearance)}; ``` -------------------------------- ### Query conflicting lanelets for a single lanelet Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_routing/README.md Use these methods to find lanelets that conflict with a specific lanelet, either within a single graph or across all available graphs. ```cpp double heightClearance{4.}; // Height of the traffic participant // Query a single graph for conflicting lanelets size_t routingGraphId{0}; // E.g. 0 for the first graph ConstLanelets conflictingVehicle{container->conflictingInGraph(bridgeLanelet, routingGraphId, heightClearance)}; // Query all graphs for conflicting lanelets RoutingGraphContainer::ConflictingInGraphs conflicting{container->conflictingInGraphs(bridgeLanelet, heightClearance)}; ``` -------------------------------- ### Register a custom map validator Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_validation/README.md Register a new validator class using the appropriate registry function within a namespace. ```c++ namespace { // or RegisterTrafficRuleValidator or RegisterRoutingGraphValidator... validation::RegisterMapValidator register; } // namespace ``` -------------------------------- ### Automated Dependency Finding Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_traffic_rules/CMakeLists.txt Automatically finds dependencies specified in the DEPENDEND_PACKAGES variable. Requires the AutoDeps package. ```cmake find_package(AutoDeps REQUIRED COMPONENTS ${DEPENDEND_PACKAGES}) ``` -------------------------------- ### Speed Limit Regulatory Element in OSM XML Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_core/doc/RegulatoryElementTagging.md Represents a speed limit regulatory element. It references the traffic sign(s) that constitute the speed limit rule using the 'refers' role. ```xml ``` -------------------------------- ### Traffic Light Regulatory Element in OSM XML Source: https://github.com/fzi-forschungszentrum-informatik/lanelet2/blob/master/lanelet2_core/doc/RegulatoryElementTagging.md Represents a traffic light regulatory element. It references a stop line via the 'ref_line' role and the traffic light itself via the 'refers' role. ```xml ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.