Skip to content

Commit fafba00

Browse files
authored
Merge pull request #2046 from tier4/chore/cherry-pick-10344
fix(autoware_probabilistic_occupancy_grid_map): fixed transform issues and border conditions (autowarefoundation#10344)
2 parents 98017c1 + 28dde95 commit fafba00

File tree

11 files changed

+65
-23
lines changed

11 files changed

+65
-23
lines changed

perception/autoware_probabilistic_occupancy_grid_map/include/autoware/probabilistic_occupancy_grid_map/updater/binary_bayes_filter_updater.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define AUTOWARE__PROBABILISTIC_OCCUPANCY_GRID_MAP__UPDATER__BINARY_BAYES_FILTER_UPDATER_HPP_
1717

1818
#ifdef USE_CUDA
19-
#include "autoware/cuda_utils/cuda_unique_ptr.hpp"
19+
#include <autoware/cuda_utils/cuda_unique_ptr.hpp>
2020
#endif
2121

2222
#include "autoware/probabilistic_occupancy_grid_map/updater/ogm_updater_interface.hpp"

perception/autoware_probabilistic_occupancy_grid_map/include/autoware/probabilistic_occupancy_grid_map/utils/utils.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#ifdef USE_CUDA
2121
#include "autoware/probabilistic_occupancy_grid_map/utils/cuda_pointcloud.hpp"
2222
#include "autoware/probabilistic_occupancy_grid_map/utils/utils_kernel.hpp"
23+
24+
#include <autoware/cuda_utils/cuda_unique_ptr.hpp>
2325
#endif
2426

2527
#include <builtin_interfaces/msg/time.hpp>
@@ -61,7 +63,9 @@ bool transformPointcloud(
6163

6264
#ifdef USE_CUDA
6365
bool transformPointcloudAsync(
64-
CudaPointCloud2 & input, const tf2_ros::Buffer & tf2, const std::string & target_frame);
66+
CudaPointCloud2 & input, const tf2_ros::Buffer & tf2, const std::string & target_frame,
67+
autoware::cuda_utils::CudaUniquePtr<Eigen::Matrix3f> & device_rotation,
68+
autoware::cuda_utils::CudaUniquePtr<Eigen::Vector3f> & device_translation);
6569
#endif
6670

6771
Eigen::Matrix4f getTransformMatrix(const geometry_msgs::msg::Pose & pose);

perception/autoware_probabilistic_occupancy_grid_map/include/autoware/probabilistic_occupancy_grid_map/utils/utils_kernel.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void copyMapRegionLaunch(
4444

4545
void transformPointCloudLaunch(
4646
std::uint8_t * points, std::size_t num_points, std::size_t points_step,
47-
const Eigen::Matrix3f & rotation, const Eigen::Vector3f & translation, cudaStream_t stream);
47+
const Eigen::Matrix3f * rotation, const Eigen::Vector3f * translation, cudaStream_t stream);
4848

4949
} // namespace utils
5050
} // namespace autoware::occupancy_grid_map

perception/autoware_probabilistic_occupancy_grid_map/lib/costmap_2d/occupancy_grid_map_fixed_kernel.cu

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ __global__ void fillUnknownSpaceKernel(
133133
int angle_bin_index = idx / range_bins;
134134
int range_bin_index = idx % range_bins;
135135

136+
if (range_bin_index == range_bins - 1) {
137+
return;
138+
}
139+
136140
std::uint64_t obs_range_and_x =
137141
obstacle_points_tensor[2 * (angle_bin_index * range_bins + range_bin_index) + 0];
138142
std::uint64_t obs_range_and_y =
@@ -149,7 +153,7 @@ __global__ void fillUnknownSpaceKernel(
149153
int next_raw_range_bin_index = range_bin_index + 1;
150154
int next_obs_range_bin_index = range_bin_index + 1;
151155

152-
for (; next_raw_range_bin_index < range_bins; next_raw_range_bin_index++) {
156+
for (; next_raw_range_bin_index < range_bins - 1; next_raw_range_bin_index++) {
153157
std::uint64_t next_raw_range_and_x =
154158
raw_points_tensor[2 * (angle_bin_index * range_bins + next_raw_range_bin_index) + 0];
155159
std::uint32_t next_raw_range_int = next_raw_range_and_x >> 32;
@@ -160,7 +164,7 @@ __global__ void fillUnknownSpaceKernel(
160164
}
161165
}
162166

163-
for (; next_obs_range_bin_index < range_bins; next_obs_range_bin_index++) {
167+
for (; next_obs_range_bin_index < range_bins - 1; next_obs_range_bin_index++) {
164168
std::uint64_t next_obs_range_and_x =
165169
obstacle_points_tensor[2 * (angle_bin_index * range_bins + next_obs_range_bin_index) + 0];
166170
std::uint32_t next_obs_range_int = next_obs_range_and_x >> 32;
@@ -289,7 +293,7 @@ __global__ void fillObstaclesKernel(
289293

290294
// Look for the next obstacle point
291295
int next_obs_range_bin_index = range_bin_index + 1;
292-
for (; next_obs_range_bin_index < range_bins; next_obs_range_bin_index++) {
296+
for (; next_obs_range_bin_index < range_bins - 1; next_obs_range_bin_index++) {
293297
std::uint64_t next_obs_range_and_x =
294298
obstacle_points_tensor[2 * (angle_bin_index * range_bins + next_obs_range_bin_index) + 0];
295299
std::uint32_t next_obs_range_int = next_obs_range_and_x >> 32;
@@ -299,6 +303,8 @@ __global__ void fillObstaclesKernel(
299303
}
300304
}
301305

306+
next_obs_range_bin_index = std::min<int>(next_obs_range_bin_index, range_bins - 1);
307+
302308
std::uint64_t next_obs_range_and_x =
303309
obstacle_points_tensor[2 * (angle_bin_index * range_bins + range_bin_index) + 0];
304310
std::uint64_t next_obs_range_and_y =

perception/autoware_probabilistic_occupancy_grid_map/lib/costmap_2d/occupancy_grid_map_projective_kernel.cu

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ __global__ void fillUnknownSpaceKernel(
255255
int angle_bin_index = idx / range_bins;
256256
int range_bin_index = idx % range_bins;
257257

258+
if (range_bin_index == range_bins - 1) {
259+
return;
260+
}
261+
258262
std::uint64_t obs_range_and_x =
259263
obstacle_points_tensor[6 * (angle_bin_index * range_bins + range_bin_index) + 0];
260264
std::uint64_t obs_range_and_y =
@@ -277,7 +281,7 @@ __global__ void fillUnknownSpaceKernel(
277281
int next_raw_range_bin_index = range_bin_index + 1;
278282
int next_obs_range_bin_index = range_bin_index + 1;
279283

280-
for (; next_raw_range_bin_index < range_bins; next_raw_range_bin_index++) {
284+
for (; next_raw_range_bin_index < range_bins - 1; next_raw_range_bin_index++) {
281285
std::uint64_t next_raw_range_and_x =
282286
raw_points_tensor[6 * (angle_bin_index * range_bins + next_raw_range_bin_index) + 0];
283287
std::uint32_t next_raw_range_int = next_raw_range_and_x >> 32;
@@ -292,7 +296,7 @@ __global__ void fillUnknownSpaceKernel(
292296
}
293297
}
294298

295-
for (; next_obs_range_bin_index < range_bins; next_obs_range_bin_index++) {
299+
for (; next_obs_range_bin_index < range_bins - 1; next_obs_range_bin_index++) {
296300
std::uint64_t next_obs_range_and_x =
297301
obstacle_points_tensor[6 * (angle_bin_index * range_bins + next_obs_range_bin_index) + 0];
298302
std::uint32_t next_obs_range_int = next_obs_range_and_x >> 32;
@@ -414,7 +418,7 @@ __global__ void fillObstaclesKernel(
414418

415419
// Look for the next obstacle point
416420
int next_obs_range_bin_index = range_bin_index + 1;
417-
for (; next_obs_range_bin_index < range_bins; next_obs_range_bin_index++) {
421+
for (; next_obs_range_bin_index < range_bins - 1; next_obs_range_bin_index++) {
418422
std::uint64_t next_obs_range_and_x =
419423
obstacle_points_tensor[6 * (angle_bin_index * range_bins + next_obs_range_bin_index) + 0];
420424
std::uint32_t next_obs_range_int = next_obs_range_and_x >> 32;
@@ -424,6 +428,8 @@ __global__ void fillObstaclesKernel(
424428
}
425429
}
426430

431+
next_obs_range_bin_index = std::min<int>(next_obs_range_bin_index, range_bins - 1);
432+
427433
std::uint64_t next_obs_range_and_x =
428434
obstacle_points_tensor[6 * (angle_bin_index * range_bins + range_bin_index) + 0];
429435
std::uint64_t next_obs_range_and_y =

perception/autoware_probabilistic_occupancy_grid_map/lib/utils/utils.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
#include "autoware/probabilistic_occupancy_grid_map/utils/utils.hpp"
1616

17+
#ifdef USE_CUDA
18+
#include <autoware/cuda_utils/cuda_check_error.hpp>
19+
#endif
20+
1721
#include <autoware_utils/geometry/geometry.hpp>
1822

1923
#include <string>
@@ -49,7 +53,9 @@ bool transformPointcloud(
4953

5054
#ifdef USE_CUDA
5155
bool transformPointcloudAsync(
52-
CudaPointCloud2 & input, const tf2_ros::Buffer & tf2, const std::string & target_frame)
56+
CudaPointCloud2 & input, const tf2_ros::Buffer & tf2, const std::string & target_frame,
57+
autoware::cuda_utils::CudaUniquePtr<Eigen::Matrix3f> & device_rotation,
58+
autoware::cuda_utils::CudaUniquePtr<Eigen::Vector3f> & device_translation)
5359
{
5460
geometry_msgs::msg::TransformStamped tf_stamped;
5561
// lookup transform
@@ -66,9 +72,18 @@ bool transformPointcloudAsync(
6672
Eigen::Matrix4f tf_matrix = tf2::transformToEigen(tf_stamped.transform).matrix().cast<float>();
6773
Eigen::Matrix3f rotation = tf_matrix.block<3, 3>(0, 0);
6874
Eigen::Vector3f translation = tf_matrix.block<3, 1>(0, 3);
75+
76+
CHECK_CUDA_ERROR(cudaMemcpyAsync(
77+
device_rotation.get(), rotation.data(), sizeof(Eigen::Matrix3f), cudaMemcpyHostToDevice,
78+
input.stream));
79+
CHECK_CUDA_ERROR(cudaMemcpyAsync(
80+
device_translation.get(), translation.data(), sizeof(Eigen::Vector3f), cudaMemcpyHostToDevice,
81+
input.stream));
82+
6983
transformPointCloudLaunch(
70-
input.data.get(), input.width * input.height, input.point_step, rotation, translation,
71-
input.stream);
84+
input.data.get(), input.width * input.height, input.point_step, device_rotation.get(),
85+
device_translation.get(), input.stream);
86+
7287
input.header.frame_id = target_frame;
7388
return true;
7489
}

perception/autoware_probabilistic_occupancy_grid_map/lib/utils/utils_kernel.cu

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,15 @@ void __device__ raytrace(
236236

237237
__global__ void transformPointCloudKernel(
238238
std::uint8_t * points, std::size_t num_points, std::size_t points_step,
239-
const Eigen::Matrix3f & rotation, const Eigen::Vector3f & translation)
239+
const Eigen::Matrix3f * rotation, const Eigen::Vector3f * translation)
240240
{
241241
int idx = blockIdx.x * blockDim.x + threadIdx.x;
242242
if (idx >= num_points) {
243243
return;
244244
}
245245

246246
Eigen::Map<Eigen::Vector3f> point_map(reinterpret_cast<float *>(points + idx * points_step));
247-
point_map = rotation * point_map + translation;
247+
point_map = rotation[0] * point_map + translation[0];
248248
}
249249

250250
__global__ void copyMapRegionKernel(
@@ -271,10 +271,10 @@ __global__ void copyMapRegionKernel(
271271

272272
void transformPointCloudLaunch(
273273
std::uint8_t * points, std::size_t num_points, std::size_t points_step,
274-
const Eigen::Matrix3f & rotation, const Eigen::Vector3f & translation, cudaStream_t stream)
274+
const Eigen::Matrix3f * rotation, const Eigen::Vector3f * translation, cudaStream_t stream)
275275
{
276276
// Launch kernel
277-
int threads_per_block = 256;
277+
const int threads_per_block = 256;
278278
int num_blocks = (num_points + threads_per_block - 1) / threads_per_block;
279279
transformPointCloudKernel<<<num_blocks, threads_per_block, 0, stream>>>(
280280
points, num_points, points_step, rotation, translation);
@@ -291,6 +291,10 @@ void copyMapRegionLaunch(
291291
const int num_blocks =
292292
(region_size_x * region_size_y + threads_per_block - 1) / threads_per_block;
293293

294+
if (num_blocks == 0) {
295+
return;
296+
}
297+
294298
copyMapRegionKernel<<<num_blocks, threads_per_block, 0, stream>>>(
295299
source_map, sm_lower_left_x, sm_lower_left_y, sm_size_x, sm_size_y, dest_map, dm_lower_left_x,
296300
dm_lower_left_y, dm_size_x, dm_size_y, region_size_x, region_size_y);

perception/autoware_probabilistic_occupancy_grid_map/src/pointcloud_based_occupancy_grid_map/pointcloud_based_occupancy_grid_map_node.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ PointcloudBasedOccupancyGridMapNode::PointcloudBasedOccupancyGridMapNode(
122122
occupancy_grid_map_ptr_->setCudaStream(stream_);
123123
occupancy_grid_map_updater_ptr_->setCudaStream(stream_);
124124

125+
device_rotation_ = autoware::cuda_utils::make_unique<Eigen::Matrix3f>();
126+
device_translation_ = autoware::cuda_utils::make_unique<Eigen::Vector3f>();
127+
125128
occupancy_grid_map_ptr_->initRosParam(*this);
126129
occupancy_grid_map_updater_ptr_->initRosParam(*this);
127130

@@ -185,12 +188,14 @@ void PointcloudBasedOccupancyGridMapNode::onPointcloudWithObstacleAndRaw()
185188
if (use_height_filter_) {
186189
// Make sure that the frame is base_link
187190
if (raw_pointcloud_.header.frame_id != base_link_frame_) {
188-
if (!utils::transformPointcloudAsync(raw_pointcloud_, *tf2_, base_link_frame_)) {
191+
if (!utils::transformPointcloudAsync(
192+
raw_pointcloud_, *tf2_, base_link_frame_, device_rotation_, device_translation_)) {
189193
return;
190194
}
191195
}
192196
if (obstacle_pointcloud_.header.frame_id != base_link_frame_) {
193-
if (!utils::transformPointcloudAsync(obstacle_pointcloud_, *tf2_, base_link_frame_)) {
197+
if (!utils::transformPointcloudAsync(
198+
obstacle_pointcloud_, *tf2_, base_link_frame_, device_rotation_, device_translation_)) {
194199
return;
195200
}
196201
}

perception/autoware_probabilistic_occupancy_grid_map/src/pointcloud_based_occupancy_grid_map/pointcloud_based_occupancy_grid_map_node.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class PointcloudBasedOccupancyGridMapNode : public rclcpp::Node
8181
CudaPointCloud2 raw_pointcloud_;
8282
CudaPointCloud2 obstacle_pointcloud_;
8383

84+
autoware::cuda_utils::CudaUniquePtr<Eigen::Matrix3f> device_rotation_;
85+
autoware::cuda_utils::CudaUniquePtr<Eigen::Vector3f> device_translation_;
86+
8487
// ROS Parameters
8588
std::string map_frame_;
8689
std::string base_link_frame_;

planning/motion_velocity_planner/autoware_motion_velocity_obstacle_stop_module/src/obstacle_stop_module.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class ObstacleStopModule : public PluginModuleInterface
170170
const std::shared_ptr<PlannerData::Object> object, const double dist_to_bumper,
171171
const std::vector<Polygon2d> & decimated_traj_polys_with_lat_margin,
172172
const std::optional<std::pair<geometry_msgs::msg::Point, double>> & collision_point) const;
173-
173+
174174
std::optional<std::pair<geometry_msgs::msg::Point, double>> get_nearest_collision_point(
175175
const std::vector<TrajectoryPoint> & traj_points, const std::vector<Polygon2d> & traj_polygons,
176176
const PlannerData::Pointcloud & point_cloud, const VehicleInfo & vehicle_info,

planning/motion_velocity_planner/autoware_motion_velocity_obstacle_stop_module/src/types.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ struct StopObstacle
6969
{
7070
}
7171
StopObstacle(
72-
const rclcpp::Time & arg_stamp, const bool arg_is_point_cloud,
73-
const double arg_lon_velocity, const geometry_msgs::msg::Point & arg_collision_point,
72+
const rclcpp::Time & arg_stamp, const bool arg_is_point_cloud, const double arg_lon_velocity,
73+
const geometry_msgs::msg::Point & arg_collision_point,
7474
const double arg_dist_to_collide_on_decimated_traj, const double arg_braking_dist = 0.0)
75-
:
76-
stamp(arg_stamp),
75+
: stamp(arg_stamp),
7776
velocity(arg_lon_velocity),
7877
collision_point(arg_collision_point),
7978
dist_to_collide_on_decimated_traj(arg_dist_to_collide_on_decimated_traj),

0 commit comments

Comments
 (0)