Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(map_loader, route_handler)!: add format_version validation #7074

Merged
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions map/map_loader/config/lanelet2_map_loader.param.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**:
ros__parameters:
allow_unsupported_version: true # flag to load unsupported format_version anyway. If true, just prints warning.
center_line_resolution: 5.0 # [m]
use_waypoints: true # "centerline" in the Lanelet2 map will be used as a "waypoints" tag.
lanelet2_map_path: $(var lanelet2_map_path) # The lanelet2 map path
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#ifndef MAP_LOADER__LANELET2_MAP_LOADER_NODE_HPP_
#define MAP_LOADER__LANELET2_MAP_LOADER_NODE_HPP_

#include <autoware_lanelet2_extension/version.hpp>
#include <component_interface_specs/map.hpp>
#include <component_interface_utils/rclcpp.hpp>
#include <rclcpp/rclcpp.hpp>
@@ -29,6 +30,9 @@

class Lanelet2MapLoaderNode : public rclcpp::Node
{
public:
static constexpr lanelet::autoware::Version version = lanelet::autoware::version;

public:
explicit Lanelet2MapLoaderNode(const rclcpp::NodeOptions & options);

5 changes: 5 additions & 0 deletions map/map_loader/schema/lanelet2_map_loader.schema.json
Original file line number Diff line number Diff line change
@@ -6,6 +6,11 @@
"lanelet2_map_loader": {
"type": "object",
"properties": {
"allow_unsupported_version": {
"type": "boolean",
"description": "Flag to load unsupported format_version anyway. If true, just prints warning.",
"default": "true"
},
"center_line_resolution": {
"type": "number",
"description": "Resolution of the Lanelet center line [m]",
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@
#include <lanelet2_io/Io.h>
#include <lanelet2_projection/UTM.h>

#include <stdexcept>
#include <string>

using autoware_map_msgs::msg::LaneletMapBin;
@@ -64,6 +65,7 @@
sub_map_projector_info_,
[this](const MapProjectorInfo::Message::ConstSharedPtr msg) { on_map_projector_info(msg); });

declare_parameter<bool>("allow_unsupported_version");
declare_parameter<std::string>("lanelet2_map_path");
declare_parameter<double>("center_line_resolution");
declare_parameter<bool>("use_waypoints");
@@ -72,17 +74,47 @@
void Lanelet2MapLoaderNode::on_map_projector_info(
const MapProjectorInfo::Message::ConstSharedPtr msg)
{
const auto allow_unsupported_version = get_parameter("allow_unsupported_version").as_bool();
const auto lanelet2_filename = get_parameter("lanelet2_map_path").as_string();
const auto center_line_resolution = get_parameter("center_line_resolution").as_double();
const auto use_waypoints = get_parameter("use_waypoints").as_bool();

// load map from file
const auto map = load_map(lanelet2_filename, *msg);
if (!map) {
RCLCPP_ERROR(get_logger(), "Failed to load lanelet2_map. Not published.");
return;
}

std::string format_version{"null"}, map_version{""};
lanelet::io_handlers::AutowareOsmParser::parseVersions(
lanelet2_filename, &format_version, &map_version);
if (format_version == "null" || format_version.empty() || !isdigit(format_version[0])) {

Check warning on line 92 in map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

Lanelet2MapLoaderNode::on_map_projector_info has 1 complex conditionals with 2 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
RCLCPP_WARN(
get_logger(),
"%s has no format_version(null) or non semver-style format_version(%s) information",
lanelet2_filename.c_str(), format_version.c_str());
if (!allow_unsupported_version) {
throw std::invalid_argument(
"allow_unsupported_version is false, so stop loading lanelet map");

Check warning on line 99 in map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp

Codecov / codecov/patch

map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp#L99

Added line #L99 was not covered by tests
}
} else if (const auto map_major_ver_opt = lanelet::io_handlers::parseMajorVersion(format_version);
map_major_ver_opt.has_value()) {
const auto map_major_ver = map_major_ver_opt.value();

Check warning on line 103 in map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp

Codecov / codecov/patch

map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp#L103

Added line #L103 was not covered by tests
if (map_major_ver > static_cast<uint64_t>(lanelet::autoware::version)) {
RCLCPP_WARN(
get_logger(),
"format_version(%ld) of the provided map(%s) is larger than the supported version(%ld)",
map_major_ver, lanelet2_filename.c_str(),
static_cast<uint64_t>(lanelet::autoware::version));
if (!allow_unsupported_version) {
throw std::invalid_argument(
"allow_unsupported_version is false, so stop loading lanelet map");

Check warning on line 112 in map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp

Codecov / codecov/patch

map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp#L112

Added line #L112 was not covered by tests
}
}
}
RCLCPP_INFO(get_logger(), "Loaded map format_version: %s", format_version.c_str());

Check notice on line 117 in map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ New issue: Complex Method

Lanelet2MapLoaderNode::on_map_projector_info has a cyclomatic complexity of 12, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 117 in map/map_loader/src/lanelet2_map_loader/lanelet2_map_loader_node.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

Lanelet2MapLoaderNode::on_map_projector_info has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
// overwrite centerline
if (use_waypoints) {
lanelet::utils::overwriteLaneletsCenterlineWithWaypoints(map, center_line_resolution, false);
1 change: 1 addition & 0 deletions map/map_loader/test/lanelet2_map_loader_launch.test.py
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ def generate_test_description():
"lanelet2_map_path": lanelet2_map_path,
"center_line_resolution": 5.0,
"use_waypoints": True,
"allow_unsupported_version": True,
}
],
)
11 changes: 11 additions & 0 deletions planning/autoware_route_handler/src/route_handler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2024 TIER IV, Inc.

Check notice on line 1 in planning/autoware_route_handler/src/route_handler.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1848 to 1858, improve code health by reducing it to 1000. The number of Lines of Code in a single file. More Lines of Code lowers the code health.

Check notice on line 1 in planning/autoware_route_handler/src/route_handler.cpp

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Overall Code Complexity

The mean cyclomatic complexity increases from 4.66 to 4.68, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
#include "autoware/route_handler/route_handler.hpp"

#include <autoware/universe_utils/geometry/geometry.hpp>
#include <autoware_lanelet2_extension/io/autoware_osm_parser.hpp>
#include <autoware_lanelet2_extension/utility/message_conversion.hpp>
#include <autoware_lanelet2_extension/utility/query.hpp>
#include <autoware_lanelet2_extension/utility/route_checker.hpp>
@@ -186,6 +187,16 @@
lanelet_map_ptr_ = std::make_shared<lanelet::LaneletMap>();
lanelet::utils::conversion::fromBinMsg(
map_msg, lanelet_map_ptr_, &traffic_rules_ptr_, &routing_graph_ptr_);
const auto map_major_version_opt =
lanelet::io_handlers::parseMajorVersion(map_msg.version_map_format);
if (!map_major_version_opt) {
RCLCPP_WARN(
logger_, "setMap() for invalid version map: %s", map_msg.version_map_format.c_str());
} else if (map_major_version_opt.value() > static_cast<uint64_t>(lanelet::autoware::version)) {
RCLCPP_WARN(
logger_, "setMap() for a map(version %s) newer than lanelet2_extension support version(%d)",
map_msg.version_map_format.c_str(), static_cast<int>(lanelet::autoware::version));
}

const auto traffic_rules = lanelet::traffic_rules::TrafficRulesFactory::create(
lanelet::Locations::Germany, lanelet::Participants::Vehicle);

Unchanged files with check annotations Beta

control/autoware_pid_longitudinal_controller/** mamoru.sobue@tier4.jp takamasa.horibe@tier4.jp takayuki.murooka@tier4.jp
control/autoware_pure_pursuit/** takamasa.horibe@tier4.jp takayuki.murooka@tier4.jp
control/autoware_shift_decider/** takamasa.horibe@tier4.jp takayuki.murooka@tier4.jp
control/autoware_smart_mpc_trajectory_follower/** kosuke.takeuchi@tier4.jp masayuki.aino@proxima-ai-tech.com takamasa.horibe@tier4.jp takayuki.murooka@tier4.jp

Check warning on line 58 in .github/CODEOWNERS

GitHub Actions / spell-check-differential

Unknown word (masayuki)

Check warning on line 58 in .github/CODEOWNERS

GitHub Actions / spell-check-differential

Unknown word (aino)
control/autoware_trajectory_follower_base/** takamasa.horibe@tier4.jp takayuki.murooka@tier4.jp
control/autoware_trajectory_follower_node/** takamasa.horibe@tier4.jp takayuki.murooka@tier4.jp
control/autoware_vehicle_cmd_gate/** takamasa.horibe@tier4.jp tomoya.kimura@tier4.jp