Skip to content

Commit

Permalink
feat(behavior_path_planner): add occupancy_grid_based_collision_detec…
Browse files Browse the repository at this point in the history
…tor (#1259)

* feat(behavior_path_planner): add occupancy_grid_based_collision_detector

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* modify copyright

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* move occ and path_shifter to utils

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* fix humble werror

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>

* fix precomit

Signed-off-by: kosuke55 <kosuke.tnp@gmail.com>
  • Loading branch information
kosuke55 authored and esteve committed Jul 8, 2022
1 parent d6381d9 commit d2c61e5
Show file tree
Hide file tree
Showing 21 changed files with 380 additions and 22 deletions.
3 changes: 2 additions & 1 deletion planning/behavior_path_planner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ament_auto_add_library(behavior_path_planner_node SHARED
src/utilities.cpp
src/path_utilities.cpp
src/debug_utilities.cpp
src/path_shifter/path_shifter.cpp
src/turn_signal_decider.cpp
src/scene_module/scene_module_bt_node_interface.cpp
src/scene_module/side_shift/side_shift_module.cpp
Expand All @@ -28,6 +27,8 @@ ament_auto_add_library(behavior_path_planner_node SHARED
src/scene_module/pull_out/pull_out_module.cpp
src/scene_module/pull_out/util.cpp
src/scene_module/utils/geometric_parallel_parking.cpp
src/scene_module/utils/occupancy_grid_based_collision_detector.cpp
src/scene_module/utils/path_shifter.cpp
)

target_include_directories(behavior_path_planner_node SYSTEM PUBLIC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#ifndef BEHAVIOR_PATH_PLANNER__DEBUG_UTILITIES_HPP_
#define BEHAVIOR_PATH_PLANNER__DEBUG_UTILITIES_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/path_utilities.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"
#include "behavior_path_planner/utilities.hpp"

#include <tier4_autoware_utils/ros/marker_helper.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define BEHAVIOR_PATH_PLANNER__PATH_UTILITIES_HPP_

#include <behavior_path_planner/parameters.hpp>
#include <behavior_path_planner/path_shifter/path_shifter.hpp>
#include <behavior_path_planner/scene_module/utils/path_shifter.hpp>
#include <opencv2/opencv.hpp>

#include <autoware_auto_planning_msgs/msg/path.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE__AVOIDANCE_MODULE_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE__AVOIDANCE_MODULE_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/avoidance/avoidance_module_data.hpp"
#include "behavior_path_planner/scene_module/scene_module_interface.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <rclcpp/rclcpp.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE__AVOIDANCE_MODULE_DATA_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE__AVOIDANCE_MODULE_DATA_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <rclcpp/rclcpp.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__AVOIDANCE__DEBUG_HPP_

#include "behavior_path_planner/debug_utilities.hpp"
#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/avoidance/avoidance_module_data.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <tier4_autoware_utils/ros/marker_helper.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__LANE_CHANGE__LANE_CHANGE_PATH_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__LANE_CHANGE__LANE_CHANGE_PATH_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__PULL_OUT__PULL_OUT_MODULE_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__PULL_OUT__PULL_OUT_MODULE_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/pull_out/pull_out_path.hpp"
#include "behavior_path_planner/scene_module/scene_module_interface.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"
#include "behavior_path_planner/utilities.hpp"

#include <lanelet2_extension/utility/message_conversion.hpp>
Expand All @@ -35,7 +35,6 @@

namespace behavior_path_planner
{

struct PullOutParameters
{
double min_stop_distance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__PULL_OUT__PULL_OUT_PATH_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__PULL_OUT__PULL_OUT_PATH_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__PULL_OVER__PULL_OVER_MODULE_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__PULL_OVER__PULL_OVER_MODULE_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/pull_over/pull_over_path.hpp"
#include "behavior_path_planner/scene_module/scene_module_interface.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"
#include "behavior_path_planner/utilities.hpp"

#include <lanelet2_extension/utility/message_conversion.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__PULL_OVER__PULL_OVER_PATH_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__PULL_OVER__PULL_OVER_PATH_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__SIDE_SHIFT__SIDE_SHIFT_MODULE_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__SIDE_SHIFT__SIDE_SHIFT_MODULE_HPP_

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/scene_module_interface.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <rclcpp/rclcpp.hpp>
#include <route_handler/route_handler.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright 2022 TIER IV, Inc. All rights reserved.
//
// 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 BEHAVIOR_PATH_PLANNER__SCENE_MODULE__UTILS__OCCUPANCY_GRID_BASED_COLLISION_DETECTOR_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__UTILS__OCCUPANCY_GRID_BASED_COLLISION_DETECTOR_HPP_

#include <tier4_autoware_utils/geometry/geometry.hpp>

#include <autoware_auto_planning_msgs/msg/path_with_lane_id.hpp>
#include <geometry_msgs/msg/pose_array.hpp>
#include <nav_msgs/msg/occupancy_grid.hpp>

#include <tf2/utils.h>

#ifdef ROS_DISTRO_GALACTIC
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#else
#include <tf2_geometry_msgs/tf2_geometry_msgs.hpp>
#endif

#include <vector>

namespace behavior_path_planner
{
int discretizeAngle(const double theta, const int theta_size);

struct IndexXYT
{
int x;
int y;
int theta;
};

struct IndexXY
{
int x;
int y;
};

IndexXYT pose2index(
const nav_msgs::msg::OccupancyGrid & costmap, const geometry_msgs::msg::Pose & pose_local,
const int theta_size);

geometry_msgs::msg::Pose index2pose(
const nav_msgs::msg::OccupancyGrid & costmap, const IndexXYT & index, const int theta_size);

geometry_msgs::msg::Pose global2local(
const nav_msgs::msg::OccupancyGrid & costmap, const geometry_msgs::msg::Pose & pose_global);

geometry_msgs::msg::Pose local2global(
const nav_msgs::msg::OccupancyGrid & costmap, const geometry_msgs::msg::Pose & pose_local);

struct VehicleShape
{
double length; // X [m]
double width; // Y [m]
double base2back; // base_link to rear [m]
};

struct OccupancyGridMapParam
{
// robot configs
VehicleShape vehicle_shape;

// costmap configs
int theta_size; // discretized angle table size [-]
int obstacle_threshold; // obstacle threshold on grid [-]
};

struct PlannerWaypoint
{
geometry_msgs::msg::PoseStamped pose;
bool is_back = false;
};

struct PlannerWaypoints
{
std_msgs::msg::Header header;
std::vector<PlannerWaypoint> waypoints;
};

class OccupancyGridBasedCollisionDetector
{
public:
OccupancyGridBasedCollisionDetector() {}
void setParam(const OccupancyGridMapParam & param) { param_ = param; };
OccupancyGridMapParam getParam() const { return param_; };
void setMap(const nav_msgs::msg::OccupancyGrid & costmap);
nav_msgs::msg::OccupancyGrid getMap() const { return costmap_; };
void setVehicleShape(const VehicleShape & vehicle_shape) { param_.vehicle_shape = vehicle_shape; }
bool hasObstacleOnPath(
const geometry_msgs::msg::PoseArray & path, const bool check_out_of_range) const;
bool hasObstacleOnPath(
const autoware_auto_planning_msgs::msg::PathWithLaneId & path,
const bool check_out_of_range) const;
const PlannerWaypoints & getWaypoints() const { return waypoints_; }
bool detectCollision(const IndexXYT & base_index, const bool check_out_of_range) const;
virtual ~OccupancyGridBasedCollisionDetector() {}

protected:
void computeCollisionIndexes(int theta_index, std::vector<IndexXY> & indexes);
inline bool isOutOfRange(const IndexXYT & index) const
{
if (index.x < 0 || static_cast<int>(costmap_.info.width) <= index.x) {
return true;
}
if (index.y < 0 || static_cast<int>(costmap_.info.height) <= index.y) {
return true;
}
return false;
}
inline bool isObs(const IndexXYT & index) const
{
// NOTE: Accessing by .at() instead makes 1.2 times slower here.
// Also, boundary check is already done in isOutOfRange before calling this function.
// So, basically .at() is not necessary.
return is_obstacle_table_[index.y][index.x];
}

OccupancyGridMapParam param_;

// costmap as occupancy grid
nav_msgs::msg::OccupancyGrid costmap_;

// collision indexes cache
std::vector<std::vector<IndexXY>> coll_indexes_table_;

// is_obstacle's table
std::vector<std::vector<bool>> is_obstacle_table_;

// pose in costmap frame
geometry_msgs::msg::Pose start_pose_;
geometry_msgs::msg::Pose goal_pose_;

// result path
PlannerWaypoints waypoints_;
};

} // namespace behavior_path_planner

#endif // BEHAVIOR_PATH_PLANNER__SCENE_MODULE__UTILS__OCCUPANCY_GRID_BASED_COLLISION_DETECTOR_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef BEHAVIOR_PATH_PLANNER__PATH_SHIFTER__PATH_SHIFTER_HPP_
#define BEHAVIOR_PATH_PLANNER__PATH_SHIFTER__PATH_SHIFTER_HPP_
#ifndef BEHAVIOR_PATH_PLANNER__SCENE_MODULE__UTILS__PATH_SHIFTER_HPP_
#define BEHAVIOR_PATH_PLANNER__SCENE_MODULE__UTILS__PATH_SHIFTER_HPP_

#include "behavior_path_planner/parameters.hpp"

Expand Down Expand Up @@ -242,4 +242,4 @@ class PathShifter

} // namespace behavior_path_planner

#endif // BEHAVIOR_PATH_PLANNER__PATH_SHIFTER__PATH_SHIFTER_HPP_
#endif // BEHAVIOR_PATH_PLANNER__SCENE_MODULE__UTILS__PATH_SHIFTER_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "behavior_path_planner/scene_module/lane_change/util.hpp"

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <lanelet2_extension/utility/query.hpp>
#include <lanelet2_extension/utility/utilities.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#include "behavior_path_planner/scene_module/pull_out/pull_out_module.hpp"

#include "behavior_path_planner/behavior_path_planner_node.hpp"
#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/path_utilities.hpp"
#include "behavior_path_planner/scene_module/avoidance/debug.hpp"
#include "behavior_path_planner/scene_module/pull_out/util.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"
#include "behavior_path_planner/util/create_vehicle_footprint.hpp"
#include "behavior_path_planner/utilities.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "behavior_path_planner/scene_module/pull_out/util.hpp"

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/path_utilities.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"
#include "behavior_path_planner/util/create_vehicle_footprint.hpp"

#include <lanelet2_extension/utility/query.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
#include "behavior_path_planner/scene_module/pull_over/pull_over_module.hpp"

#include "behavior_path_planner/behavior_path_planner_node.hpp"
#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/path_utilities.hpp"
#include "behavior_path_planner/scene_module/avoidance/debug.hpp"
#include "behavior_path_planner/scene_module/pull_over/util.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"
#include "behavior_path_planner/utilities.hpp"

#include <lanelet2_extension/utility/message_conversion.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include "behavior_path_planner/scene_module/pull_over/util.hpp"

#include "behavior_path_planner/path_shifter/path_shifter.hpp"
#include "behavior_path_planner/path_utilities.hpp"
#include "behavior_path_planner/scene_module/utils/path_shifter.hpp"

#include <lanelet2_extension/utility/query.hpp>
#include <lanelet2_extension/utility/utilities.hpp>
Expand Down
Loading

0 comments on commit d2c61e5

Please sign in to comment.