-
Notifications
You must be signed in to change notification settings - Fork 665
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(static_centerline_optimizer): generate centerline from ego's tra…
…jectory in bag (#6788) * implement bag_ego_trajectory_based_centerline Signed-off-by: Takayuki Murooka <[email protected]> * fix Signed-off-by: Takayuki Murooka <[email protected]> * fix Signed-off-by: Takayuki Murooka <[email protected]> --------- Signed-off-by: Takayuki Murooka <[email protected]>
- Loading branch information
1 parent
a06122c
commit e459f09
Showing
18 changed files
with
491 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
planning/static_centerline_optimizer/config/static_centerline_optimizer.param.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/**: | ||
ros__parameters: | ||
centerline_source: "optimization_trajectory_base" # select from "optimization_trajectory_base" and "bag_ego_trajectory_base" | ||
marker_color: ["FF0000", "00FF00", "0000FF"] | ||
marker_color_dist_thresh : [0.1, 0.2, 0.3] | ||
output_trajectory_interval: 1.0 |
29 changes: 29 additions & 0 deletions
29
...ude/static_centerline_optimizer/centerline_source/bag_ego_trajectory_based_centerline.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// 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 STATIC_CENTERLINE_OPTIMIZER__CENTERLINE_SOURCE__BAG_EGO_TRAJECTORY_BASED_CENTERLINE_HPP_ | ||
#define STATIC_CENTERLINE_OPTIMIZER__CENTERLINE_SOURCE__BAG_EGO_TRAJECTORY_BASED_CENTERLINE_HPP_ | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "static_centerline_optimizer/type_alias.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace static_centerline_optimizer | ||
{ | ||
std::vector<TrajectoryPoint> generate_centerline_with_bag(rclcpp::Node & node); | ||
} // namespace static_centerline_optimizer | ||
#endif // STATIC_CENTERLINE_OPTIMIZER__CENTERLINE_SOURCE__BAG_EGO_TRAJECTORY_BASED_CENTERLINE_HPP_ |
45 changes: 45 additions & 0 deletions
45
...tatic_centerline_optimizer/centerline_source/optimization_trajectory_based_centerline.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// 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 STATIC_CENTERLINE_OPTIMIZER__CENTERLINE_SOURCE__OPTIMIZATION_TRAJECTORY_BASED_CENTERLINE_HPP_ // NOLINT | ||
#define STATIC_CENTERLINE_OPTIMIZER__CENTERLINE_SOURCE__OPTIMIZATION_TRAJECTORY_BASED_CENTERLINE_HPP_ // NOLINT | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "static_centerline_optimizer/type_alias.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace static_centerline_optimizer | ||
{ | ||
class OptimizationTrajectoryBasedCenterline | ||
{ | ||
public: | ||
OptimizationTrajectoryBasedCenterline() = default; | ||
explicit OptimizationTrajectoryBasedCenterline(rclcpp::Node & node); | ||
std::vector<TrajectoryPoint> generate_centerline_with_optimization( | ||
rclcpp::Node & node, const RouteHandler & route_handler, | ||
const std::vector<lanelet::Id> & route_lane_ids); | ||
|
||
private: | ||
std::vector<TrajectoryPoint> optimize_trajectory(const Path & raw_path) const; | ||
|
||
rclcpp::Publisher<PathWithLaneId>::SharedPtr pub_raw_path_with_lane_id_{nullptr}; | ||
rclcpp::Publisher<Path>::SharedPtr pub_raw_path_{nullptr}; | ||
}; | ||
} // namespace static_centerline_optimizer | ||
// clang-format off | ||
#endif // STATIC_CENTERLINE_OPTIMIZER__CENTERLINE_SOURCE__OPTIMIZATION_TRAJECTORY_BASED_CENTERLINE_HPP_ // NOLINT | ||
// clang-format on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
planning/static_centerline_optimizer/scripts/tmp/bag_ego_trajectory_based_centerline.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
ros2 launch static_centerline_optimizer static_centerline_optimizer.launch.xml centerline_source:="bag_ego_trajectory_base" run_background:=false lanelet2_input_file_path:="$HOME/autoware_map/sample_map/lanelet2_map.osm" bag_filename:="$(ros2 pkg prefix static_centerline_optimizer --share)/test/data/bag_ego_trajectory.db3" vehicle_model:=lexus |
3 changes: 3 additions & 0 deletions
3
planning/static_centerline_optimizer/scripts/tmp/optimization_trajectory_based_centerline.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
ros2 launch static_centerline_optimizer static_centerline_optimizer.launch.xml centerline_source:="optimization_trajectory_base" run_background:=false lanelet2_input_file_path:="$HOME/autoware_map/sample_map/lanelet2_map.osm" start_lanelet_id:=125 end_lanelet_id:=132 vehicle_model:=lexus |
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
...static_centerline_optimizer/src/centerline_source/bag_ego_trajectory_based_centerline.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2024 TIER IV, Inc. | ||
// | ||
// 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 "static_centerline_optimizer/centerline_source/bag_ego_trajectory_based_centerline.hpp" | ||
|
||
#include "rclcpp/serialization.hpp" | ||
#include "rosbag2_cpp/reader.hpp" | ||
#include "static_centerline_optimizer/static_centerline_optimizer_node.hpp" | ||
|
||
#include <nav_msgs/msg/odometry.hpp> | ||
|
||
namespace static_centerline_optimizer | ||
{ | ||
std::vector<TrajectoryPoint> generate_centerline_with_bag(rclcpp::Node & node) | ||
{ | ||
const auto bag_filename = node.declare_parameter<std::string>("bag_filename"); | ||
|
||
rosbag2_cpp::Reader bag_reader; | ||
bag_reader.open(bag_filename); | ||
|
||
rclcpp::Serialization<nav_msgs::msg::Odometry> bag_serialization; | ||
std::vector<TrajectoryPoint> centerline_traj_points; | ||
while (bag_reader.has_next()) { | ||
const rosbag2_storage::SerializedBagMessageSharedPtr msg = bag_reader.read_next(); | ||
|
||
if (msg->topic_name != "/localization/kinematic_state") { | ||
continue; | ||
} | ||
|
||
rclcpp::SerializedMessage serialized_msg(*msg->serialized_data); | ||
const auto ros_msg = std::make_shared<nav_msgs::msg::Odometry>(); | ||
|
||
bag_serialization.deserialize_message(&serialized_msg, ros_msg.get()); | ||
|
||
if (!centerline_traj_points.empty()) { | ||
constexpr double epsilon = 1e-1; | ||
if ( | ||
std::abs(centerline_traj_points.back().pose.position.x - ros_msg->pose.pose.position.x) < | ||
epsilon && | ||
std::abs(centerline_traj_points.back().pose.position.y - ros_msg->pose.pose.position.y) < | ||
epsilon) { | ||
continue; | ||
} | ||
} | ||
TrajectoryPoint centerline_traj_point; | ||
centerline_traj_point.pose.position = ros_msg->pose.pose.position; | ||
// std::cerr << centerline_traj_point.pose.position.x << " " | ||
// << centerline_traj_point.pose.position.y << std::endl; | ||
centerline_traj_points.push_back(centerline_traj_point); | ||
} | ||
|
||
RCLCPP_INFO(node.get_logger(), "Extracted centerline from the bag."); | ||
|
||
// calculate rough orientation of centerline trajectory points | ||
for (size_t i = 0; i < centerline_traj_points.size(); ++i) { | ||
if (i == centerline_traj_points.size() - 1) { | ||
if (i != 0) { | ||
centerline_traj_points.at(i).pose.orientation = | ||
centerline_traj_points.at(i - 1).pose.orientation; | ||
} | ||
} else { | ||
const double yaw_angle = tier4_autoware_utils::calcAzimuthAngle( | ||
centerline_traj_points.at(i).pose.position, centerline_traj_points.at(i + 1).pose.position); | ||
centerline_traj_points.at(i).pose.orientation = | ||
tier4_autoware_utils::createQuaternionFromYaw(yaw_angle); | ||
} | ||
} | ||
|
||
return centerline_traj_points; | ||
} | ||
} // namespace static_centerline_optimizer |
Oops, something went wrong.