@@ -71,6 +71,9 @@ using Vector3 = geometry_msgs::msg::Vector3;
71
71
using autoware_perception_msgs::msg::PredictedObject;
72
72
using autoware_perception_msgs::msg::PredictedObjects;
73
73
74
+ /* *
75
+ * @brief Struct to store object data
76
+ */
74
77
struct ObjectData
75
78
{
76
79
rclcpp::Time stamp;
@@ -80,22 +83,44 @@ struct ObjectData
80
83
double distance_to_object{0.0 };
81
84
};
82
85
86
+ /* *
87
+ * @brief Class to manage collision data
88
+ */
83
89
class CollisionDataKeeper
84
90
{
85
91
public:
92
+ /* *
93
+ * @brief Constructor for CollisionDataKeeper
94
+ * @param clock Shared pointer to the clock
95
+ */
86
96
explicit CollisionDataKeeper (rclcpp::Clock::SharedPtr clock) { clock_ = clock ; }
87
97
98
+ /* *
99
+ * @brief Set timeout values for collision and obstacle data
100
+ * @param collision_keep_time Time to keep collision data
101
+ * @param previous_obstacle_keep_time Time to keep previous obstacle data
102
+ */
88
103
void setTimeout (const double collision_keep_time, const double previous_obstacle_keep_time)
89
104
{
90
105
collision_keep_time_ = collision_keep_time;
91
106
previous_obstacle_keep_time_ = previous_obstacle_keep_time;
92
107
}
93
108
109
+ /* *
110
+ * @brief Get timeout values for collision and obstacle data
111
+ * @return Pair of collision and obstacle data timeout values
112
+ */
94
113
std::pair<double , double > getTimeout ()
95
114
{
96
115
return {collision_keep_time_, previous_obstacle_keep_time_};
97
116
}
98
117
118
+ /* *
119
+ * @brief Check if object data has expired
120
+ * @param data Optional reference to the object data
121
+ * @param timeout Timeout value to check against
122
+ * @return True if object data has expired, false otherwise
123
+ */
99
124
bool checkObjectDataExpired (std::optional<ObjectData> & data, const double timeout)
100
125
{
101
126
if (!data.has_value ()) return true ;
@@ -109,38 +134,70 @@ class CollisionDataKeeper
109
134
return false ;
110
135
}
111
136
137
+ /* *
138
+ * @brief Check if collision data has expired
139
+ * @return True if collision data has expired, false otherwise
140
+ */
112
141
bool checkCollisionExpired ()
113
142
{
114
143
return this ->checkObjectDataExpired (closest_object_, collision_keep_time_);
115
144
}
116
145
146
+ /* *
147
+ * @brief Check if previous object data has expired
148
+ * @return True if previous object data has expired, false otherwise
149
+ */
117
150
bool checkPreviousObjectDataExpired ()
118
151
{
119
152
return this ->checkObjectDataExpired (prev_closest_object_, previous_obstacle_keep_time_);
120
153
}
121
154
155
+ /* *
156
+ * @brief Get the closest object data
157
+ * @return Object data of the closest object
158
+ */
122
159
[[nodiscard]] ObjectData get () const
123
160
{
124
161
return (closest_object_.has_value ()) ? closest_object_.value () : ObjectData ();
125
162
}
126
163
164
+ /* *
165
+ * @brief Get the previous closest object data
166
+ * @return Object data of the previous closest object
167
+ */
127
168
[[nodiscard]] ObjectData getPreviousObjectData () const
128
169
{
129
170
return (prev_closest_object_.has_value ()) ? prev_closest_object_.value () : ObjectData ();
130
171
}
131
172
173
+ /* *
174
+ * @brief Set collision data
175
+ * @param data Object data to set
176
+ */
132
177
void setCollisionData (const ObjectData & data)
133
178
{
134
179
closest_object_ = std::make_optional<ObjectData>(data);
135
180
}
136
181
182
+ /* *
183
+ * @brief Set previous object data
184
+ * @param data Object data to set
185
+ */
137
186
void setPreviousObjectData (const ObjectData & data)
138
187
{
139
188
prev_closest_object_ = std::make_optional<ObjectData>(data);
140
189
}
141
190
191
+ /* *
192
+ * @brief Reset the obstacle velocity history
193
+ */
142
194
void resetVelocityHistory () { obstacle_velocity_history_.clear (); }
143
195
196
+ /* *
197
+ * @brief Update the velocity history with current object velocity
198
+ * @param current_object_velocity Current object velocity
199
+ * @param current_object_velocity_time_stamp Timestamp of the current object velocity
200
+ */
144
201
void updateVelocityHistory (
145
202
const double current_object_velocity, const rclcpp::Time & current_object_velocity_time_stamp)
146
203
{
@@ -158,6 +215,10 @@ class CollisionDataKeeper
158
215
current_object_velocity, current_object_velocity_time_stamp);
159
216
}
160
217
218
+ /* *
219
+ * @brief Get the median obstacle velocity from history
220
+ * @return Optional median obstacle velocity
221
+ */
161
222
[[nodiscard]] std::optional<double > getMedianObstacleVelocity () const
162
223
{
163
224
if (obstacle_velocity_history_.empty ()) return std::nullopt;
@@ -177,6 +238,13 @@ class CollisionDataKeeper
177
238
return (vel1 + vel2) / 2.0 ;
178
239
}
179
240
241
+ /* *
242
+ * @brief Calculate object speed from velocity history
243
+ * @param closest_object Closest object data
244
+ * @param path Ego vehicle path
245
+ * @param current_ego_speed Current ego vehicle speed
246
+ * @return Optional calculated object speed
247
+ */
180
248
std::optional<double > calcObjectSpeedFromHistory (
181
249
const ObjectData & closest_object, const Path & path, const double current_ego_speed)
182
250
{
@@ -241,9 +309,16 @@ class CollisionDataKeeper
241
309
rclcpp::Clock::SharedPtr clock_;
242
310
};
243
311
312
+ /* *
313
+ * @brief Autonomous Emergency Braking (AEB) node
314
+ */
244
315
class AEB : public rclcpp ::Node
245
316
{
246
317
public:
318
+ /* *
319
+ * @brief Constructor for AEB
320
+ * @param node_options Options for the node
321
+ */
247
322
explicit AEB (const rclcpp::NodeOptions & node_options);
248
323
249
324
// subscriber
@@ -267,53 +342,156 @@ class AEB : public rclcpp::Node
267
342
rclcpp::TimerBase::SharedPtr timer_;
268
343
269
344
// callback
345
+ /* *
346
+ * @brief Callback for point cloud messages
347
+ * @param input_msg Shared pointer to the point cloud message
348
+ */
270
349
void onPointCloud (const PointCloud2::ConstSharedPtr input_msg);
350
+
351
+ /* *
352
+ * @brief Callback for IMU messages
353
+ * @param input_msg Shared pointer to the IMU message
354
+ */
271
355
void onImu (const Imu::ConstSharedPtr input_msg);
356
+
357
+ /* *
358
+ * @brief Timer callback function
359
+ */
272
360
void onTimer ();
361
+
362
+ /* *
363
+ * @brief Callback for parameter updates
364
+ * @param parameters Vector of updated parameters
365
+ * @return Set parameters result
366
+ */
273
367
rcl_interfaces::msg::SetParametersResult onParameter (
274
368
const std::vector<rclcpp::Parameter> & parameters);
275
369
370
+ /* *
371
+ * @brief Fetch the latest data from subscribers
372
+ * @return True if data fetch was successful, false otherwise
373
+ */
276
374
bool fetchLatestData ();
277
375
278
- // main function
376
+ /* *
377
+ * @brief Diagnostic check for collisions
378
+ * @param stat Diagnostic status wrapper
379
+ */
279
380
void onCheckCollision (DiagnosticStatusWrapper & stat);
381
+
382
+ /* *
383
+ * @brief Check for collisions
384
+ * @param debug_markers Marker array for debugging
385
+ * @return True if a collision is detected, false otherwise
386
+ */
280
387
bool checkCollision (MarkerArray & debug_markers);
388
+
389
+ /* *
390
+ * @brief Check if there is a collision with the closest object
391
+ * @param current_v Current velocity of the ego vehicle
392
+ * @param closest_object Data of the closest object
393
+ * @return True if a collision is detected, false otherwise
394
+ */
281
395
bool hasCollision (const double current_v, const ObjectData & closest_object);
282
396
397
+ /* *
398
+ * @brief Generate the ego vehicle path
399
+ * @param curr_v Current velocity of the ego vehicle
400
+ * @param curr_w Current angular velocity of the ego vehicle
401
+ * @return Generated ego path
402
+ */
283
403
Path generateEgoPath (const double curr_v, const double curr_w);
404
+
405
+ /* *
406
+ * @brief Generate the ego vehicle path from the predicted trajectory
407
+ * @param predicted_traj Predicted trajectory of the ego vehicle
408
+ * @return Optional generated ego path
409
+ */
284
410
std::optional<Path> generateEgoPath (const Trajectory & predicted_traj);
411
+
412
+ /* *
413
+ * @brief Generate the footprint of the path with extra width margin
414
+ * @param path Ego vehicle path
415
+ * @param extra_width_margin Extra width margin for the footprint
416
+ * @return Vector of polygons representing the path footprint
417
+ */
285
418
std::vector<Polygon2d> generatePathFootprint (const Path & path, const double extra_width_margin);
286
419
420
+ /* *
421
+ * @brief Create object data using point cloud clusters
422
+ * @param ego_path Ego vehicle path
423
+ * @param ego_polys Polygons representing the ego vehicle footprint
424
+ * @param stamp Timestamp of the data
425
+ * @param objects Vector to store the created object data
426
+ * @param obstacle_points_ptr Pointer to the point cloud of obstacles
427
+ */
287
428
void createObjectDataUsingPointCloudClusters (
288
429
const Path & ego_path, const std::vector<Polygon2d> & ego_polys, const rclcpp::Time & stamp,
289
430
std::vector<ObjectData> & objects,
290
431
const pcl::PointCloud<pcl::PointXYZ>::Ptr obstacle_points_ptr);
291
432
433
+ /* *
434
+ * @brief Create object data using predicted objects
435
+ * @param ego_path Ego vehicle path
436
+ * @param ego_polys Polygons representing the ego vehicle footprint
437
+ * @param objects Vector to store the created object data
438
+ */
292
439
void createObjectDataUsingPredictedObjects (
293
440
const Path & ego_path, const std::vector<Polygon2d> & ego_polys,
294
441
std::vector<ObjectData> & objects);
295
442
443
+ /* *
444
+ * @brief Crop the point cloud with the ego vehicle footprint path
445
+ * @param ego_polys Polygons representing the ego vehicle footprint
446
+ * @param filtered_objects Pointer to the filtered point cloud of obstacles
447
+ */
296
448
void cropPointCloudWithEgoFootprintPath (
297
449
const std::vector<Polygon2d> & ego_polys, pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_objects);
298
450
299
- void createObjectDataUsingPointCloudClusters (
300
- const Path & ego_path, const std::vector<Polygon2d> & ego_polys, const rclcpp::Time & stamp,
301
- std::vector<ObjectData> & objects);
302
- void cropPointCloudWithEgoFootprintPath (const std::vector<Polygon2d> & ego_polys);
303
-
451
+ /* *
452
+ * @brief Add a marker for debugging
453
+ * @param current_time Current time
454
+ * @param path Ego vehicle path
455
+ * @param polygons Polygons representing the ego vehicle footprint
456
+ * @param objects Vector of object data
457
+ * @param closest_object Optional data of the closest object
458
+ * @param color_r Red color component
459
+ * @param color_g Green color component
460
+ * @param color_b Blue color component
461
+ * @param color_a Alpha (transparency) component
462
+ * @param ns Namespace for the marker
463
+ * @param debug_markers Marker array for debugging
464
+ */
304
465
void addMarker (
305
466
const rclcpp::Time & current_time, const Path & path, const std::vector<Polygon2d> & polygons,
306
467
const std::vector<ObjectData> & objects, const std::optional<ObjectData> & closest_object,
307
468
const double color_r, const double color_g, const double color_b, const double color_a,
308
469
const std::string & ns, MarkerArray & debug_markers);
309
470
471
+ /* *
472
+ * @brief Add a collision marker for debugging
473
+ * @param data Data of the collision object
474
+ * @param debug_markers Marker array for debugging
475
+ */
310
476
void addCollisionMarker (const ObjectData & data, MarkerArray & debug_markers);
311
477
478
+ /* *
479
+ * @brief Add an info marker stop wall in front of the ego vehicle
480
+ * @param markers Data of the closest object
481
+ */
312
482
void addVirtualStopWallMarker (MarkerArray & markers);
313
483
484
+ /* *
485
+ * @brief Calculate object speed from history
486
+ * @param closest_object Data of the closest object
487
+ * @param path Ego vehicle path
488
+ * @param current_ego_speed Current speed of the ego vehicle
489
+ * @return Optional calculated object speed
490
+ */
314
491
std::optional<double > calcObjectSpeedFromHistory (
315
492
const ObjectData & closest_object, const Path & path, const double current_ego_speed);
316
493
494
+ // Member variables
317
495
PointCloud2::SharedPtr obstacle_ros_pointcloud_ptr_{nullptr };
318
496
VelocityReport::ConstSharedPtr current_velocity_ptr_{nullptr };
319
497
Vector3::SharedPtr angular_velocity_ptr_{nullptr };
@@ -330,7 +508,7 @@ class AEB : public rclcpp::Node
330
508
// diag
331
509
Updater updater_{this };
332
510
333
- // member variables
511
+ // Member variables
334
512
bool publish_debug_pointcloud_;
335
513
bool publish_debug_markers_;
336
514
bool use_predicted_trajectory_;
0 commit comments