Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

feat(lanelet2_extension): add regulatory element details checker #237

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e3e81ac
Added autoware_lanenet2_validation
sgk-000 Jan 31, 2024
546bf3c
Added autoware_lanelet2_validation to cmake
sgk-000 Jan 31, 2024
b34790b
Splited unconnected_relations checker to missing regulatory elements …
sgk-000 Jan 31, 2024
e5d01f7
Added test for missing regulatory elements checker
sgk-000 Jan 31, 2024
1f0d928
Added test of missing regulatory elements checker to cmake
sgk-000 Jan 31, 2024
aa0d33f
Added license and copyright notice
sgk-000 Jan 31, 2024
da970b0
Refactored
sgk-000 Jan 31, 2024
bea8df7
Removed unnecessary files
sgk-000 Jan 31, 2024
c047c3d
Change default projector to MGRS projector
sgk-000 Feb 1, 2024
9d8d286
Updated help messages in cli
sgk-000 Feb 1, 2024
9646c34
Removed local from projector option
sgk-000 Feb 1, 2024
2dfe7e3
Updated help message to be more readable
sgk-000 Feb 1, 2024
3c7bf70
Added document for autoware_lanelet2_validation
sgk-000 Feb 1, 2024
bafae94
Added simple_lanelet2_validation
sgk-000 Feb 1, 2024
6a28437
Updated help description to warn if lat or lon is not set when projec…
sgk-000 Feb 1, 2024
54da3d6
Used move_iterator
sgk-000 Feb 1, 2024
4e72c8d
style(pre-commit): autofix
pre-commit-ci[bot] Feb 1, 2024
df4f04d
Made fenced code blocks to have language specified context
sgk-000 Feb 1, 2024
874b4e2
Added include guard
sgk-000 Feb 1, 2024
ac974db
Rename validators directory to vals because include guard name too long
sgk-000 Feb 1, 2024
a34c8d3
Removed unnecessary namespace
sgk-000 Feb 1, 2024
c597752
Add static cast
sgk-000 Feb 1, 2024
ecc58a8
Fixed include guard name
sgk-000 Feb 1, 2024
c2ac49d
Removed explicitly operetor call
sgk-000 Feb 1, 2024
4a1b85c
Added missed namespace
sgk-000 Feb 5, 2024
160a942
Added template for append_issue
sgk-000 Feb 5, 2024
b4ca2fd
Check missing regulatory elements in stop lines
sgk-000 Feb 5, 2024
13bd2f2
Added regulatory element details checker
sgk-000 Feb 5, 2024
1d0d25f
Added copyright and license notice
sgk-000 Feb 5, 2024
ae7ec07
Updated comments
sgk-000 Feb 5, 2024
54bee13
Fixed bug of the issue which is reported when ref line of traffic lig…
sgk-000 Feb 6, 2024
530dc9b
Added more test case
sgk-000 Feb 6, 2024
f17a8a9
Added TODO comment. Check if regulatory element of traffic light must…
sgk-000 Feb 6, 2024
5e08fad
Report error if traffic light regulatory element does not have stop l…
sgk-000 Feb 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions tmp/lanelet2_extension/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ target_link_libraries(lanelet2_extension_lib
get_target_property(lanelet2_core_INCLUDE_DIRECTORIES lanelet2_core::lanelet2_core INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(lanelet2_extension_lib
SYSTEM PRIVATE
${lanelet2_core_INCLUDE_DIRECTORIES}
${lanelet2_core_INCLUDE_DIRECTORIES}
)

ament_auto_add_executable(lanelet2_extension_sample src/sample_code.cpp)
Expand All @@ -64,9 +64,9 @@ target_link_libraries(lanelet2_extension_sample
lanelet2_extension_lib
)

ament_auto_add_executable(autoware_lanelet2_validation src/validation.cpp)
add_dependencies(autoware_lanelet2_validation lanelet2_extension_lib)
target_link_libraries(autoware_lanelet2_validation
ament_auto_add_executable(simple_lanelet2_validation src/validation.cpp)
add_dependencies(simple_lanelet2_validation lanelet2_extension_lib)
target_link_libraries(simple_lanelet2_validation
${catkin_LIBRARIES}
${PUGIXML_LIBRARIES}
lanelet2_extension_lib
Expand All @@ -80,6 +80,21 @@ target_link_libraries(check_right_of_way
lanelet2_extension_lib
)

file(GLOB_RECURSE autoware_lanelet2_validation_lib_src src/autoware_lanelet2_validation/lib/*.cpp)
ament_auto_add_library(autoware_lanelet2_validation_lib SHARED
${autoware_lanelet2_validation_lib_src}
)

target_link_libraries(autoware_lanelet2_validation_lib
lanelet2_extension_lib
)

ament_auto_add_executable(autoware_lanelet2_validation src/autoware_lanelet2_validation/main.cpp)
add_dependencies(autoware_lanelet2_validation autoware_lanelet2_validation_lib)
target_link_libraries(autoware_lanelet2_validation
autoware_lanelet2_validation_lib
)

if(BUILD_TESTING)
ament_add_ros_isolated_gtest(message_conversion-test test/src/test_message_conversion.cpp)
target_link_libraries(message_conversion-test lanelet2_extension_lib)
Expand All @@ -92,11 +107,25 @@ if(BUILD_TESTING)
ament_add_ros_isolated_gtest(utilities-test test/src/test_utilities.cpp)
target_link_libraries(utilities-test lanelet2_extension_lib)
target_include_directories(utilities-test
SYSTEM PRIVATE
SYSTEM PRIVATE
${lanelet2_core_INCLUDE_DIRECTORIES}
)
ament_add_ros_isolated_gtest(route-test test/src/test_route_checker.cpp)
target_link_libraries(route-test lanelet2_extension_lib)

function(add_validation_test VALIDATION_NAME)
ament_add_ros_isolated_gtest(
${VALIDATION_NAME}_test
test/src/autoware_lanelet2_validation/test_${VALIDATION_NAME}.cpp
)
target_link_libraries(
${VALIDATION_NAME}_test
autoware_lanelet2_validation_lib
)
endfunction()

add_validation_test(missing_regulatory_elements)
add_validation_test(regulatory_element_details)
endif()

ament_auto_package()
49 changes: 47 additions & 2 deletions tmp/lanelet2_extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,56 @@ Currently it contains following conversions:
Code for this explains how this lanelet2_extension library is used.
The executable is not meant to do anything.

### autoware_lanelet2_extension
### simple_lanelet2_validation

This node checks if an .osm file follows the Autoware version of Lanelet2 format.
You can check by running:

```sh
ros2 run lanelet2_extension autoware_lanelet2_validation --ros-args -p map_file:=<path/to/map.osm>
ros2 run lanelet2_extension simple_lanelet2_validation --ros-args -p map_file:=<path/to/map.osm>
```

### autoware_lanelet2_validation

This node validates if the provided lanelet2 map is usable with Autoware.
You can check by running:

```sh
ros2 run lanelet2_extension autoware_lanelet2_validation --map_file <path/to/map.osm> --validator <validator name>
```

Example:

```sh
ros2 run lanelet2_extension autoware_lanelet2_validation --map_file ~/autoware_map/sample-map-planning/lanelet2_map.osm --validator mapping.missing_regulatory_elements
```

Output of above example:

```sh
Set to default projector: MGRS projector
Error: linestring 9776 Traffic light must have a regulatory element. [mapping.missing_regulatory_elements]
Error: linestring 9774 Traffic light must have a regulatory element. [mapping.missing_regulatory_elements]
Error: linestring 9771 Traffic light must have a regulatory element. [mapping.missing_regulatory_elements]
Error: linestring 9769 Traffic light must have a regulatory element. [mapping.missing_regulatory_elements]
Error: linestring 340 Traffic light must have a regulatory element. [mapping.missing_regulatory_elements]
Error: linestring 342 Traffic light must have a regulatory element. [mapping.missing_regulatory_elements]
Error: linestring 345 Traffic light must have a regulatory element. [mapping.missing_regulatory_elements]
Error: linestring 347 Traffic light must have a regulatory element. [mapping.missing_regulatory_elements]
Error: lanelet 163 Crosswalk must have a regulatory element. [mapping.missing_regulatory_elements]
Error: lanelet 164 Crosswalk must have a regulatory element. [mapping.missing_regulatory_elements]
Error: lanelet 165 Crosswalk must have a regulatory element. [mapping.missing_regulatory_elements]
Error: lanelet 166 Crosswalk must have a regulatory element. [mapping.missing_regulatory_elements]
```

For more information, please refer to help. You can check by running:

```sh
ros2 run lanelet2_extension autoware_lanelet2_validation --help
```

#### Avalilable validators

##### mapping.missing_regulatory_elements

This validate if given lanelet2 map has the traffic light or crosswalk which is not associated with a regulatory element.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 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.

#ifndef LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__CLI_HPP_
#define LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__CLI_HPP_

#include <boost/program_options.hpp>

#include <lanelet2_validation/Cli.h>

#include <iostream>
#include <string>

namespace lanelet
{
namespace autoware
{
namespace validation
{
struct MetaConfig
{
lanelet::validation::CommandLineConfig command_line_config;
std::string projector_type;
};

MetaConfig parseCommandLine(int argc, const char * argv[]);

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

#endif // LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__CLI_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2023 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.

#ifndef LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__UTILS_HPP_
#define LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__UTILS_HPP_

#include <lanelet2_validation/Validation.h>
#include <lanelet2_validation/ValidatorFactory.h>

#include <string>
#include <vector>

namespace lanelet
{
namespace autoware
{
namespace validation
{
template <typename T>
void appendIssues(std::vector<T> & to, std::vector<T> && from)
{
to.insert(to.end(), std::make_move_iterator(from.begin()), std::make_move_iterator(from.end()));
}

template <typename T>
void checkPrimitivesType(
std::vector<T> & in_vec, const std::string & expected_type,
const lanelet::validation::Issue & issue, lanelet::validation::Issues & issues)
{
for (auto iter = in_vec.begin(); iter != in_vec.end(); ++iter) {
const auto & item = *iter;
const auto & attrs = item.attributes();
const auto & it = attrs.find(lanelet::AttributeName::Type);
if (it == attrs.end() || it->second != expected_type) {
issues.emplace_back(issue.severity, issue.primitive, item.id(), issue.message);
const auto new_it = in_vec.erase(iter);
if (new_it != in_vec.end()) {
iter = new_it;
} else {
break;
}
}
}
}

template <typename T>
void checkPrimitivesType(
std::vector<T> & in_vec, const std::string & expected_type, const std::string & expected_subtype,
const lanelet::validation::Issue & issue, lanelet::validation::Issues & issues)
{
for (auto iter = in_vec.begin(); iter != in_vec.end(); ++iter) {
const auto & item = *iter;
const auto & attrs = item.attributes();
const auto & it = attrs.find(lanelet::AttributeName::Type);
const auto & it_sub = attrs.find(lanelet::AttributeName::Subtype);
if (
it == attrs.end() || it->second != expected_type || it_sub == attrs.end() ||
it_sub->second != expected_subtype) {
issues.emplace_back(issue.severity, issue.primitive, item.id(), issue.message);
const auto new_it = in_vec.erase(iter);
if (new_it != in_vec.end()) {
iter = new_it;
} else {
break;
}
}
}
}

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

#endif // LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__UTILS_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 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.

#ifndef LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__VALIDATION_HPP_
#define LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__VALIDATION_HPP_

#include "lanelet2_extension/autoware_lanelet2_validation/cli.hpp"
#include "lanelet2_extension/autoware_lanelet2_validation/utils.hpp"
#include "lanelet2_extension/projection/mgrs_projector.hpp"
#include "lanelet2_extension/projection/transverse_mercator_projector.hpp"

#include <lanelet2_io/Io.h>
#include <lanelet2_projection/UTM.h>
#include <lanelet2_validation/Cli.h>
#include <lanelet2_validation/Validation.h>

#include <memory>
#include <regex>
#include <vector>

namespace
{
namespace projector_names
{
constexpr const char * mgrs = "mgrs";
constexpr const char * transverse_mercator = "transverse_mercator";
constexpr const char * utm = "utm";
} // namespace projector_names
} // namespace

namespace lanelet
{
namespace autoware
{
namespace validation
{
std::unique_ptr<lanelet::Projector> getProjector(const MetaConfig & config);
std::vector<lanelet::validation::DetectedIssues> validateMap(const MetaConfig & config);
} // namespace validation
} // namespace autoware
} // namespace lanelet

#endif // LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__VALIDATION_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 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.

#ifndef LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__VALS__MISSING_REGULATORY_ELEMENTS_HPP_
#define LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__VALS__MISSING_REGULATORY_ELEMENTS_HPP_

#include "lanelet2_extension/autoware_lanelet2_validation/utils.hpp"
#include "lanelet2_extension/regulatory_elements/crosswalk.hpp"

#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>
#include <range/v3/view/unique.hpp>

#include <lanelet2_core/LaneletMap.h>
#include <lanelet2_validation/Validation.h>

#include <set>

namespace lanelet
{
namespace validation
{

class MissingRegulatoryElementsChecker : public lanelet::validation::MapValidator
{
public:
constexpr static const char * name() { return "mapping.missing_regulatory_elements"; }

lanelet::validation::Issues operator()(const lanelet::LaneletMap & map) override;

private:
lanelet::validation::Issues checkMissingReglatoryElementsInTrafficLight(
const lanelet::LaneletMap & map);
lanelet::validation::Issues checkMissingReglatoryElementsInCrosswalk(
const lanelet::LaneletMap & map);
lanelet::validation::Issues checkMissingReglatoryElementsInStopLine(
const lanelet::LaneletMap & map);
std::set<lanelet::Id> tl_elem_with_cw_;
};
} // namespace validation
} // namespace lanelet

#endif // LANELET2_EXTENSION__AUTOWARE_LANELET2_VALIDATION__VALS__MISSING_REGULATORY_ELEMENTS_HPP_
Loading
Loading