Skip to content

Commit cf0266e

Browse files
authoredDec 5, 2024··
feat(costmap_generator, scenario_selector): improve freespace planning stability (#9579)
* discretize updating grid center position by size of grid resolution Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * modify logic for switching to lane driving in scenario selector Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> * fix spelling Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp> --------- Signed-off-by: mohammad alqudah <alqudah.mohammad@tier4.jp>
1 parent e75bbbc commit cf0266e

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed
 

‎planning/autoware_costmap_generator/include/autoware/costmap_generator/costmap_generator.hpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ class CostmapGenerator : public rclcpp::Node
139139

140140
void set_current_pose();
141141

142+
/// \brief set position of grid center
143+
/// \details computes relative position of ego from current grid center,
144+
/// if offset is larger than grid resolution, grid center will be updated
145+
/// by a multiple of the grid resolution
146+
/// \param[in] tf costmap frame to vehicle frame transform
147+
void set_grid_center(const geometry_msgs::msg::TransformStamped & tf);
148+
142149
void onTimer();
143150

144151
bool isActive();
@@ -148,7 +155,9 @@ class CostmapGenerator : public rclcpp::Node
148155

149156
/// \brief publish ros msg: grid_map::GridMap, and nav_msgs::OccupancyGrid
150157
/// \param[in] gridmap with calculated cost
151-
void publishCostmap(const grid_map::GridMap & costmap);
158+
/// \param[in] tf costmap frame to vehicle frame transform
159+
void publishCostmap(
160+
const grid_map::GridMap & costmap, const geometry_msgs::msg::TransformStamped & tf);
152161

153162
/// \brief fill a vector with road area polygons
154163
/// \param [in] lanelet_map input lanelet map

‎planning/autoware_costmap_generator/src/costmap_generator.cpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,7 @@ void CostmapGenerator::onTimer()
286286
}
287287
time_keeper_->end_track("lookupTransform");
288288

289-
// Set grid center
290-
grid_map::Position p;
291-
p.x() = tf.transform.translation.x;
292-
p.y() = tf.transform.translation.y;
293-
costmap_.setPosition(p);
289+
set_grid_center(tf);
294290

295291
if ((param_->use_wayarea || param_->use_parkinglot) && lanelet_map_) {
296292
autoware::universe_utils::ScopedTimeTrack st("generatePrimitivesCostmap()", *time_keeper_);
@@ -312,7 +308,18 @@ void CostmapGenerator::onTimer()
312308
costmap_[LayerName::combined] = generateCombinedCostmap();
313309
}
314310

315-
publishCostmap(costmap_);
311+
publishCostmap(costmap_, tf);
312+
}
313+
314+
void CostmapGenerator::set_grid_center(const geometry_msgs::msg::TransformStamped & tf)
315+
{
316+
const auto cur_pos = costmap_.getPosition();
317+
const grid_map::Position ref_pos(tf.transform.translation.x, tf.transform.translation.y);
318+
const auto disp = ref_pos - cur_pos;
319+
const auto resolution = costmap_.getResolution();
320+
const grid_map::Position offset(
321+
std::round(disp.x() / resolution) * resolution, std::round(disp.y() / resolution) * resolution);
322+
costmap_.setPosition(cur_pos + offset);
316323
}
317324

318325
bool CostmapGenerator::isActive()
@@ -452,7 +459,8 @@ grid_map::Matrix CostmapGenerator::generateCombinedCostmap()
452459
return combined_costmap[LayerName::combined];
453460
}
454461

455-
void CostmapGenerator::publishCostmap(const grid_map::GridMap & costmap)
462+
void CostmapGenerator::publishCostmap(
463+
const grid_map::GridMap & costmap, const geometry_msgs::msg::TransformStamped & tf)
456464
{
457465
// Set header
458466
std_msgs::msg::Header header;
@@ -465,11 +473,13 @@ void CostmapGenerator::publishCostmap(const grid_map::GridMap & costmap)
465473
costmap, LayerName::combined, param_->grid_min_value, param_->grid_max_value,
466474
out_occupancy_grid);
467475
out_occupancy_grid.header = header;
476+
out_occupancy_grid.info.origin.position.z = tf.transform.translation.z;
468477
pub_occupancy_grid_->publish(out_occupancy_grid);
469478

470479
// Publish GridMap
471480
auto out_gridmap_msg = grid_map::GridMapRosConverter::toMessage(costmap);
472481
out_gridmap_msg->header = header;
482+
out_gridmap_msg->info.pose.position.z = tf.transform.translation.z;
473483
pub_costmap_->publish(*out_gridmap_msg);
474484

475485
// Publish ProcessingTime

‎planning/autoware_scenario_selector/src/node.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "autoware/scenario_selector/node.hpp"
1616

17+
#include <autoware/universe_utils/geometry/geometry.hpp>
1718
#include <autoware_lanelet2_extension/utility/message_conversion.hpp>
1819
#include <autoware_lanelet2_extension/utility/query.hpp>
1920

@@ -65,6 +66,22 @@ bool isInLane(
6566
return dist_to_nearest_lanelet < margin;
6667
}
6768

69+
bool isAlongLane(
70+
const std::shared_ptr<autoware::route_handler::RouteHandler> & route_handler,
71+
const geometry_msgs::msg::Pose & current_pose)
72+
{
73+
lanelet::ConstLanelet closest_lanelet;
74+
if (!route_handler->getClosestLaneletWithConstrainsWithinRoute(
75+
current_pose, &closest_lanelet, 0.0, M_PI_4)) {
76+
return false;
77+
}
78+
const lanelet::BasicPoint2d src_point(current_pose.position.x, current_pose.position.y);
79+
const auto dist_to_centerline =
80+
lanelet::geometry::distanceToCenterline2d(closest_lanelet, src_point);
81+
static constexpr double margin = 1.0;
82+
return dist_to_centerline < margin;
83+
}
84+
6885
bool isInParkingLot(
6986
const std::shared_ptr<lanelet::LaneletMap> & lanelet_map_ptr,
7087
const geometry_msgs::msg::Pose & current_pose)
@@ -215,10 +232,9 @@ bool ScenarioSelectorNode::isSwitchToParking(const bool is_stopped)
215232

216233
bool ScenarioSelectorNode::isSwitchToLaneDriving()
217234
{
218-
const auto is_in_lane =
219-
isInLane(route_handler_->getLaneletMapPtr(), current_pose_->pose.pose.position);
235+
const auto is_along_lane = isAlongLane(route_handler_, current_pose_->pose.pose);
220236

221-
if (!isEmptyParkingTrajectory() || !is_in_lane) {
237+
if (!isEmptyParkingTrajectory() || !is_along_lane) {
222238
empty_parking_trajectory_time_ = {};
223239
return false;
224240
}

0 commit comments

Comments
 (0)
Please sign in to comment.