Skip to content

Commit

Permalink
feat(autoware_lanelet2_map_validator): introduce autoware_lanelet2_ma…
Browse files Browse the repository at this point in the history
…p_validator (#118)

* introduce autoware_lanelet2_map_validator to autoware_tools

Signed-off-by: TaikiYamada4 <[email protected]>

* wrote description a little to README.md

Signed-off-by: TaikiYamada4 <[email protected]>

* style(pre-commit): autofix

* Restore commented out parts.
Removed rclcpp which is unused.

Signed-off-by: TaikiYamada4 <[email protected]>

* style(pre-commit): autofix

* Separate validation rules to samller pieces.
Added validation template

Signed-off-by: TaikiYamada4 <[email protected]>

* Split the validation code into smaller pieces.
Added yaml input/output for a set of validations

Signed-off-by: TaikiYamada4 <[email protected]>

* Fixed test codes to use the separated codes

Signed-off-by: TaikiYamada4 <[email protected]>

* Removed unused code which are already divided to smaller codes.

Signed-off-by: TaikiYamada4 <[email protected]>

* Rename new_main.cpp to main.cpp

Signed-off-by: TaikiYamada4 <[email protected]>

* style(pre-commit): autofix

* Wrote detailed README.md

Signed-off-by: TaikiYamada4 <[email protected]>

* Fixed commit mistake

Signed-off-by: TaikiYamada4 <[email protected]>

* Renew input command option to `-i` from `-r`.
Fixed mistakes in README.md

Signed-off-by: TaikiYamada4 <[email protected]>

* style(pre-commit): autofix

* Fixed long to uint64_t

Signed-off-by: TaikiYamada4 <[email protected]>

* Fixed spelling

Signed-off-by: TaikiYamada4 <[email protected]>

* style(pre-commit): autofix

* Fixed typo

Signed-off-by: TaikiYamada4 <[email protected]>

* Split long lines in the code

Signed-off-by: TaikiYamada4 <[email protected]>

* style(pre-commit): autofix

* Changed the entire structure.
Fixed pre-commit.ci related errors.

Signed-off-by: TaikiYamada4 <[email protected]>

* style(pre-commit): autofix

* Fixed pre-commit.ci related stuff

Signed-off-by: TaikiYamada4 <[email protected]>

* Write more details about the relationship to lanelet2_validation.
Rewrite misleading examples.

Signed-off-by: TaikiYamada4 <[email protected]>

* Added figure of the architecture

Signed-off-by: TaikiYamada4 <[email protected]>

* Change the input/output to JSON

Signed-off-by: TaikiYamada4 <[email protected]>

* Revised architecture image of autoware_lanelet2_map_validator

Signed-off-by: TaikiYamada4 <[email protected]>

* fixed typo

Signed-off-by: TaikiYamada4 <[email protected]>

* Renew year numbers

Signed-off-by: TaikiYamada4 <[email protected]>

* Fixed dependency

Signed-off-by: TaikiYamada4 <[email protected]>

* Fixed pointed out issues

Signed-off-by: TaikiYamada4 <[email protected]>

* Improve error handling
Refactor code style

Signed-off-by: TaikiYamada4 <[email protected]>

* Avoid clang format
Delete unused variables

Signed-off-by: TaikiYamada4 <[email protected]>

* Removed redundant process.
Restrict input/output format.

Signed-off-by: TaikiYamada4 <[email protected]>

* Added approaches to the documents

Signed-off-by: TaikiYamada4 <[email protected]>

* Fixed typo

Signed-off-by: TaikiYamada4 <[email protected]>

* Removed catch and improve io error handling

Signed-off-by: TaikiYamada4 <[email protected]>

* Fixed grammatical error.
Fixed explanation of issues

Signed-off-by: TaikiYamada4 <[email protected]>

* Added stop_line validator to the table in the main README.md

Signed-off-by: TaikiYamada4 <[email protected]>

* Renamed lib to common.
Refined CMakeLists.txt

Signed-off-by: TaikiYamada4 <[email protected]>

* Removed redundant under score

Signed-off-by: TaikiYamada4 <[email protected]>

* Removed redundant underscore again

Signed-off-by: TaikiYamada4 <[email protected]>

* Changed years.
Removed redundant else statement.
Removed debug comments

Signed-off-by: TaikiYamada4 <[email protected]>

* Removed underscore from test_regulatory_element_details.cpp

Signed-off-by: TaikiYamada4 <[email protected]>

---------

Signed-off-by: TaikiYamada4 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
TaikiYamada4 and pre-commit-ci[bot] authored Oct 31, 2024
1 parent c634977 commit dfc2a78
Show file tree
Hide file tree
Showing 31 changed files with 3,324 additions and 0 deletions.
46 changes: 46 additions & 0 deletions map/autoware_lanelet2_map_validator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.14)
project(autoware_lanelet2_map_validator)

find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_find_build_dependencies()
find_package(nlohmann_json REQUIRED)

include_directories(
src
)

file(GLOB_RECURSE autoware_lanelet2_map_validator_lib_src
src/common/*.cpp
src/validators/*.cpp
)
ament_auto_add_library(autoware_lanelet2_map_validator_lib SHARED
${autoware_lanelet2_map_validator_lib_src}
)

ament_auto_add_executable(autoware_lanelet2_map_validator src/main.cpp)
add_dependencies(autoware_lanelet2_map_validator autoware_lanelet2_map_validator_lib)
target_link_libraries(autoware_lanelet2_map_validator
autoware_lanelet2_map_validator_lib
nlohmann_json
)

if(BUILD_TESTING)
function(add_validation_test VALIDATION_NAME)
ament_add_ros_isolated_gtest(
${VALIDATION_NAME}_test
test/src/test_${VALIDATION_NAME}.cpp
)
target_link_libraries(
${VALIDATION_NAME}_test
autoware_lanelet2_map_validator_lib
nlohmann_json
)
endfunction()

add_validation_test(missing_regulatory_elements)
add_validation_test(regulatory_element_details)
endif()

ament_auto_package()
313 changes: 313 additions & 0 deletions map/autoware_lanelet2_map_validator/README.md

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions map/autoware_lanelet2_map_validator/autoware_requirement_set.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"requirements": [
{
"id": "vm-04-01",
"validators": [
{
"name": "mapping.crosswalk.missing_regulatory_elements"
},
{
"name": "mapping.crosswalk.regulatory_element_details"
}
]
},
{
"id": "vm-05-01",
"validators": [
{
"name": "mapping.traffic_light.missing_regulatory_elements"
},
{
"name": "mapping.traffic_light.regulatory_element_details"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# missing_regulator_elements_for_crosswalk

## Validator name

mapping.crosswalk.missing_regulatory_elements

## Feature

This validator checks whether each `crosswalk` subtype lanelet has a relevant regulatory element.
Required information for a crosswalk is written in the [Autoware documentation](https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-architecture/map/map-requirements/vector-map-requirements-overview/category_crosswalk/#vm-05-01-crosswalks-across-the-road).

The output issue marks "lanelet" as the **primitive**, and the lanelet ID is written together as **ID**.

| Message | Severity | Description | Approach |
| ------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| "No regulatory element refers to this crosswalk." | Error | There is a `crosswalk` subtype lanelet that hasn't been referred to any regulatory element. | Create a `crosswalk` subtype regulatory element and refer to the crosswalk lanelet. |

## Related source codes

- missing_regulatory_elements_for_crosswalk.hpp
- missing_regulatory_elements_for_crosswalk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# regulatory_element_details_for_crosswalks

## Validator name

mapping.crosswalk.regulatory_element_details

## Feature

This validator checks whether the details in the `crosswalk` subtype regulatory elements are valid.
Required information for a crosswalk is written in the [Autoware documentation](https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-architecture/map/map-requirements/vector-map-requirements-overview/category_crosswalk/#vm-05-01-crosswalks-across-the-road).
This validator checks eight types of issues.

The output issue marks "lanelet", "linestring" or "regulatory_element" as the **primitive**, and the regulatory element ID is written together as **ID**.

| Message | Severity | Primitive | Description | Approach |
| ---------------------------------------------------------------------------------------- | -------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| "Refers of crosswalk regulatory element must have type of crosswalk." | Error | lanelet | There is a `crosswalk` subtype regulatory element whose `refers` is not a `crosswalk` subtype lanelet. | Check that the `refers` is a `crosswalk` subtype lanelet |
| "ref_line of crosswalk regulatory element must have type of stopline." | Error | linestring | There is a `crosswalk` subtype regulatory element whose `ref_line` is not a `stop_line` type linestring. | Check that the `ref_line` is a `stop_line` type linestring |
| "Crosswalk polygon of crosswalk regulatory element must have type of Crosswalk_polygon." | Error | polygon | There is a `crosswalk` subtype regulatory element whose `crosswalk_polygon` is not a `crosswalk_polygon` type polygon. | Check that the `crosswalk_polygon` mentioned in the regulatory element refers to a `crosswalk_polygon` type area. |
| "Regulatory element of crosswalk must have lanelet of crosswalk(refers)." | Error | regulatory element | There is a `crosswalk` subtype regulatory element that has no `refers`es. | Write `refers` referring to a `crosswalk` subtype lanelet in the regulatory element |
| "Regulatory element of crosswalk must have only one lanelet of crosswalk(refers)." | Error | regulatory element | There is a `crosswalk` subtype regulatory element that has multiple `refers`es. | A `crosswalk` subtype regulatory element can have only one `refers`. Remove the `refers` that is not a crosswalk lanelet. |
| "Regulatory element of crosswalk does not have stop line(ref_line)." | Info | regulatory element | There is a `crosswalk` subtype regulatory element that has no `ref_line`s | Generally, there should be a stop line for the crosswalk. Be sure that the stop line exists or doesn't. |
| "Regulatory element of crosswalk is nice to have crosswalk_polygon." | Warning | regulatory element | There is a `crosswalk` subtype regulatory element that has no `crosswalk_polygon`s. | It is recommended to surround a crosswalk with a `crosswalk_polygon`. Create one and add a `crosswalk_polygon` role member to the regulatory element with the polygon ID. |
| "Regulatory element of crosswalk must have only one crosswalk_polygon." | Error | regulatory element | There is a `crosswalk` subtype regulatory element that has multiple `crosswalk_polygon`s. | Only one `crosswalk_polygon` is allowed per polygon. Remove the unnecessary ones. |

## Related source codes

- regulatory_element_details_for_crosswalks.hpp
- regulatory_element_details_for_crosswalks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# missing_regulator_elements_for_stop_lines

## Validator name

mapping.stop_line.missing_regulatory_elements

## Feature

This validator checks whether each `stop_line` type linestring has a relevant regulatory element.
Required information for a stop line is written in the [Autoware documentation](https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-architecture/map/map-requirements/vector-map-requirements-overview/category_stop_line/#vm-02-02-stop-sign).

The output issue marks "linestring" as the **primitive**, and the linestring ID is written together as **ID**.

| Message | Severity | Description | Approach |
| ------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| "No regulatory element refers to this stop line." | Error | There is a `stop_line` type linestring that hasn't been referred to any regulatory element. | Create a regulatory element that refers to this stop line. |

## Related source codes

- missing_regulatory_elements_for_stop_line.cpp
- missing_regulatory_elements_for_stop_line.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# missing_regulator_elements_for_traffic_lights

## Validator name

mapping.traffic_light.missing_regulatory_elements

## Feature

This validator checks whether each `traffic_light` type linestring has a relevant regulatory element.
Required information for traffic lights is written in the [Autoware documentation](https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-architecture/map/map-requirements/vector-map-requirements-overview/category_traffic_light/#vm-04-01-traffic-light-basics).

The output issue marks "linestring" as the **primitive**, and the linestring ID is written together as **ID**.

| Message | Severity | Description | Approach |
| ----------------------------------------------------- | -------- | ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| "No regulatory element refers to this traffic light." | Error | There is a `traffic_light` type linestring that hasn't been referred to any regulatory element. | Create a `traffic_light` subtype regulatory element that refers to this linestring |

## Related source codes

- missing_regulatory_elements_for_traffic_light.hpp
- missing_regulatory_elements_for_traffic_light.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# regulatory_element_details_for_traffic_lights

## Validator name

mapping.traffic_light.regulatory_element_details

## Feature

This validator checks whether the details in the `traffic_light` subtype regulatory elements are valid.
Required information for traffic lights is written in the [Autoware documentation](https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-architecture/map/map-requirements/vector-map-requirements-overview/category_traffic_light/#vm-04-01-traffic-light-basics).
This validator checks four types of issues.

The output issue marks "linestring" or "regulatory element" as the **primitive**, and the lanelet ID is written together as **ID**.

| Message | Severity | Primitive | Description | Approach |
| ----------------------------------------------------------------------------- | -------- | ------------------ | -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| "Refers of traffic light regulatory element must have type of traffic_light." | Error | linestring | There is a `traffic_light` subtype regulatory element whose `refers` is not a `traffic_light` type linestring. | Check that the `refers` in the regulatory element is a `traffic_light` type linestring. |
| "ref_line of traffic light regulatory element must have type of stop_line." | Error | linestring | There is a `traffic_light` subtype regulatory element whose `ref_line` is not a `stop_line` type linestring. | Check that the `ref_line` in the regulatory element is a `stop_line` type linestring |
| "Regulatory element of traffic light must have a traffic light(refers)." | Error | regulatory element | There is a `traffic_light` subtype regulatory element that has no `refers`es. | Add `refers` to the regulatory element that refers to the id of the traffic light linestring. |
| "Regulatory element of traffic light must have a stop line(ref_line)." | Error | regulatory element | There is a `traffic_light` subtype regulatory element that has no `ref_line`s | Add `ref_line` to the regulatory element that refers to the id of the stop line linestring. |

## Related source codes

- regulatory_element_details_for_traffic_lights.hpp
- regulatory_element_details_for_traffic_lights.cpp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions map/autoware_lanelet2_map_validator/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>autoware_lanelet2_map_validator</name>
<version>0.1.0</version>
<description>Validation tool for lanelet2 maps especially for Autoware usage</description>
<maintainer email="[email protected]">Taiki Yamada</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_lanelet2_extension</depend>
<depend>lanelet2_core</depend>
<depend>lanelet2_io</depend>
<depend>lanelet2_maps</depend>
<depend>lanelet2_projection</depend>
<depend>lanelet2_routing</depend>
<depend>lanelet2_traffic_rules</depend>
<depend>lanelet2_validation</depend>
<depend>nlohmann-json-dev</depend>

<test_depend>ament_cmake_ros</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
107 changes: 107 additions & 0 deletions map/autoware_lanelet2_map_validator/src/common/cli.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2024 Autoware Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "common/cli.hpp"

namespace po = boost::program_options;

namespace lanelet
{
namespace autoware
{
namespace validation
{

MetaConfig parseCommandLine(int argc, const char * argv[])
{
MetaConfig config;
auto & validation_config = config.command_line_config.validationConfig;
po::options_description desc(
"Runs a set of validators on a map. Think of it like a linter. The following checks are "
"available");

// clang-format off
desc.add_options()
(
"help,h", "This help message"
)(
"map_file,m", po::value<std::string>(), "Path to the map to be validated"
)(
"input_requirements,i", po::value<std::string>(),
"Path to the yaml file where the list of requirements and validators is written"
)(
"output_directory,o", po::value<std::string>(),
"Directory to save the list of validation results in a yaml format"
)(
"validator,v", po::value(&validation_config.checksFilter),
"Comma separated list of regexes to filter the applicable validators. Will run all "
"validators by default. Example: routing_graph.* to run all checks for the routing graph"
)(
"projector,p", po::value(&config.projector_type)->composing(),
"Projector used for loading lanelet map. Available projectors are: mgrs, utm, "
"transverse_mercator. (default: mgrs)"
)(
"location,l", po::value(&validation_config.location)->default_value(validation_config.location),
"Location of the map (for instantiating the traffic rules), e.g. de for Germany"
)(
"participants", po::value(&validation_config.participants)->composing(),
"Participants for which the routing graph will be instantiated (default: vehicle)"
)(
"lat", po::value(&validation_config.origin.lat)->default_value(validation_config.origin.lat),
"Latitude coordinate of map origin. This is required for the transverse mercator "
"and utm projector."
)(
"lon", po::value(&validation_config.origin.lon)->default_value(validation_config.origin.lon),
"Longitude coordinate of map origin. This is required for the transverse mercator "
"and utm projector."
)(
"print", "Print all available checker without running them"
);
// clang-format on

po::variables_map vm;
po::positional_options_description pos;
pos.add("map_file", 1);
po::store(po::command_line_parser(argc, argv).options(desc).positional(pos).run(), vm);
po::notify(vm);
config.command_line_config.help = vm.count("help") != 0;
config.command_line_config.print = vm.count("print") != 0;
if (vm.count("map_file") != 0) {
config.command_line_config.mapFile =
vm["map_file"].as<decltype(config.command_line_config.mapFile)>();
}
if (vm.count("input_requirements") != 0) {
config.requirements_file = vm["input_requirements"].as<std::string>();
}
if (vm.count("output_directory") != 0) {
config.output_file_path = vm["output_directory"].as<std::string>();
}
if (
(vm.count("lat") != 0 && vm.count("lon") != 0) &&
(config.projector_type == "tm" || config.projector_type == "utm")) {
throw std::runtime_error(
"Please set latitude and longitude. These are required for " + config.projector_type +
" projector. Please refer to the help message.");
}
if (config.command_line_config.help) {
std::cout << '\n' << desc;
} else if (config.command_line_config.mapFile.empty() && !config.command_line_config.print) {
std::cout << "Please pass either a valid file or '--print' or '--help'!\n";
}
return config;
}

} // namespace validation
} // namespace autoware
} // namespace lanelet
Loading

0 comments on commit dfc2a78

Please sign in to comment.