Skip to content

Commit e1d585d

Browse files
doc: docstring
Signed-off-by: Zulfaqar Azmi <zulfaqar.azmi@tier4.jp>
1 parent f4eea96 commit e1d585d

8 files changed

Lines changed: 154 additions & 46 deletions

File tree

planning/autoware_trajectory_concatenator/include/autoware/trajectory_concatenator/detail/trajectory_concatenator.hpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,37 @@ namespace autoware::trajectory_concatenator
3131
using autoware_internal_planning_msgs::msg::CandidateTrajectories;
3232

3333
/**
34-
* @brief Stateful aggregator of trajectories from multiple generators.
35-
* Uses a most-recent-per-generator buffer with time-based stale pruning.
36-
* * * Pure C++ Library: This class is completely independent of rclcpp.
37-
* * Thread-safety: Not thread-safe. Must be protected by a mutex by the caller.
38-
* * ARCHITECTURAL NOTE ON LATENCY:
39-
* Because this stage is designed to be flushed via a fixed-rate timer (e.g., 30ms),
40-
* it introduces an average ~15ms (max 30ms) latency floor to the pipeline. Consequently,
41-
* all downstream outputs (including debug markers) are quantized to this timer's rate.
34+
* @brief Aggregates candidate trajectories from multiple generators into a single set.
4235
*/
4336
class TrajectoryConcatenator
4437
{
4538
public:
39+
/**
40+
* @brief Constructs the concatenator with the given parameters.
41+
* @param params Initial concatenator parameters.
42+
*/
4643
explicit TrajectoryConcatenator(concatenator::Params params) : params_(std::move(params)) {}
4744

45+
/**
46+
* @brief Replaces the current parameters.
47+
* @param params New parameter values.
48+
*/
4849
void update_parameters(const concatenator::Params & params) { params_ = params; }
4950

51+
/**
52+
* @brief Stores the latest trajectories from the message's generator.
53+
* @param msg Candidate trajectories message from a single generator.
54+
*/
5055
void add_candidate(const CandidateTrajectories & msg);
5156

57+
/**
58+
* @brief Returns the merged set of all non-stale generator trajectories.
59+
* @param current_time Current ROS time used to filter out stale entries.
60+
*/
5261
[[nodiscard]] CandidateTrajectories get_concatenated(
5362
const builtin_interfaces::msg::Time & current_time);
63+
64+
/** @brief Returns and resets the elapsed processing time in milliseconds. */
5465
double take_processing_time();
5566

5667
private:

planning/autoware_trajectory_concatenator/include/autoware/trajectory_concatenator/trajectory_concatenator_interface.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@
2828

2929
namespace autoware::trajectory_concatenator
3030
{
31+
/**
32+
* @brief ROS2 adapter for TrajectoryConcatenator: handles parameter updates and thread safety.
33+
*/
3134
class TrajectoryConcatenatorInterface
3235
{
3336
public:
37+
/**
38+
* @brief Constructs the interface and initialises the concatenator with declared parameters.
39+
* @param node ROS2 node used for parameter declaration and logging.
40+
* @param node_parameters_interface Parameter interface for declaring and reading parameters.
41+
*/
3442
TrajectoryConcatenatorInterface(
3543
rclcpp::Node & node,
3644
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters_interface)
@@ -42,6 +50,7 @@ class TrajectoryConcatenatorInterface
4250
{
4351
}
4452

53+
/** @brief Reloads parameters from the parameter server if they have changed. */
4554
void update_parameters()
4655
{
4756
if (concatenator_params_listener_.is_old(concatenator_params_)) {
@@ -51,13 +60,18 @@ class TrajectoryConcatenatorInterface
5160
}
5261
}
5362

63+
/**
64+
* @brief Adds a set of candidate trajectories to the buffer.
65+
* @param candidate_trajectories Candidate trajectories from a single generator.
66+
*/
5467
void add_candidate(
5568
const autoware_internal_planning_msgs::msg::CandidateTrajectories & candidate_trajectories)
5669
{
5770
std::lock_guard<std::mutex> lock(concatenator_mutex_);
5871
concatenator_ptr_->add_candidate(candidate_trajectories);
5972
}
6073

74+
/** @brief Returns the merged set of all non-stale generator trajectories. */
6175
[[nodiscard]] autoware_internal_planning_msgs::msg::CandidateTrajectories get_concatenated()
6276
{
6377
update_parameters();
@@ -67,6 +81,8 @@ class TrajectoryConcatenatorInterface
6781
return concatenator_ptr_->get_concatenated(time_now);
6882
};
6983

84+
/** @brief Returns the interface name and elapsed processing time in milliseconds, then resets it.
85+
*/
7086
[[nodiscard]] std::pair<std::string, double> take_processing_time()
7187
{
7288
std::lock_guard<std::mutex> lock(concatenator_mutex_);

planning/autoware_trajectory_validator/include/autoware/trajectory_validator/detail/trajectory_validator.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,37 @@ namespace autoware::trajectory_validator
2828
{
2929
using autoware::vehicle_info_utils::VehicleInfo;
3030

31+
/**
32+
* @brief Runs a set of validator plugins against each candidate trajectory.
33+
*/
3134
class TrajectoryValidator
3235
{
3336
public:
37+
/**
38+
* @brief Constructs the validator with the given plugin set.
39+
* @param plugins Validator plugins to run against each trajectory.
40+
*/
3441
explicit TrajectoryValidator(std::vector<std::shared_ptr<plugin::ValidatorInterface>> plugins)
3542
: plugins_(std::move(plugins))
3643
{
3744
}
3845

46+
/**
47+
* @brief Forwards updated parameters to all plugins.
48+
* @param params Latest parameter values.
49+
*/
3950
void update_parameters(const validator::Params & params) const
4051
{
4152
for (const auto & plugin : plugins_) {
4253
plugin->update_parameters(params);
4354
}
4455
}
4556

57+
/**
58+
* @brief Evaluates all plugins against every trajectory and returns a validation report.
59+
* @param input_trajectories Candidate trajectories to validate.
60+
* @param context Current world state snapshot.
61+
*/
4662
[[nodiscard]] TrajectoryValidatorReport process(
4763
const autoware_internal_planning_msgs::msg::CandidateTrajectories & input_trajectories,
4864
const ValidatorContext & context) const;

planning/autoware_trajectory_validator/include/autoware/trajectory_validator/detail/trajectory_validator_report.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace autoware::trajectory_validator
2828
{
2929

30+
/** @brief Feasibility result of a single plugin for a single trajectory. */
3031
struct PluginEvaluation
3132
{
3233
std::string plugin_name;
@@ -35,18 +36,21 @@ struct PluginEvaluation
3536
std::string reason;
3637
};
3738

39+
/** @brief Aggregated plugin evaluations for a single generator's trajectory. */
3840
struct EvaluationTable
3941
{
4042
std::string generator_id;
4143
std::vector<PluginEvaluation> plugin_evaluations;
4244

45+
/** @brief Returns true if every plugin passed or is in shadow mode. */
4346
[[nodiscard]] bool all_acceptable() const
4447
{
4548
return std::all_of(plugin_evaluations.begin(), plugin_evaluations.end(), [](const auto & e) {
4649
return e.is_feasible || e.is_shadow_mode;
4750
});
4851
}
4952

53+
/** @brief Returns true if every plugin passed, ignoring shadow mode. */
5054
[[nodiscard]] bool all_feasible() const
5155
{
5256
return std::all_of(plugin_evaluations.begin(), plugin_evaluations.end(), [](const auto & e) {
@@ -55,13 +59,7 @@ struct EvaluationTable
5559
}
5660
};
5761

58-
/**
59-
* @brief Final opaque result structure returned by the validation stage.
60-
* CONTRACT FOR ROS NODE ADAPTER:
61-
* The Node MUST iterate over `evaluation_tables` post-process to:
62-
* 1. Emit `RCLCPP_WARN_THROTTLE` for any `!evaluation.is_feasible`.
63-
* 2. Update the `diagnostics_interface_` per plugin using the final evaluation states.
64-
*/
62+
/** @brief Result returned by TrajectoryValidator::process. */
6563
struct TrajectoryValidatorReport
6664
{
6765
autoware_internal_planning_msgs::msg::CandidateTrajectories valid_trajectories;

planning/autoware_trajectory_validator/include/autoware/trajectory_validator/detail/validator_context.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
namespace autoware::trajectory_validator
2828
{
2929

30-
/**
31-
* @brief A read-only snapshot of the world state for a single validation stage execution.
32-
* Callees receive it by `const &` and must not mutate fields.
33-
*/
30+
/** @brief World state snapshot passed to each validator plugin. */
3431
struct ValidatorContext
3532
{
3633
nav_msgs::msg::Odometry::ConstSharedPtr odometry;

planning/autoware_trajectory_validator/include/autoware/trajectory_validator/trajectory_selector_node.hpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,43 @@ using autoware_perception_msgs::msg::PredictedObjects;
4343
using geometry_msgs::msg::AccelWithCovarianceStamped;
4444
using nav_msgs::msg::Odometry;
4545

46+
/**
47+
* @brief Concatenates candidate trajectories from multiple planners, validates them, and
48+
* publishes the surviving set.
49+
*/
4650
class TrajectorySelectorNode : public rclcpp::Node
4751
{
4852
public:
53+
/**
54+
* @brief Constructs the node, declares parameters, and initialises all components.
55+
* @param node_options ROS2 node options.
56+
*/
4957
explicit TrajectorySelectorNode(const rclcpp::NodeOptions & node_options);
5058

5159
private:
52-
/**
53-
* @brief Initialise the node's subscribers.
54-
*/
60+
/** @brief Creates all subscriptions. */
5561
void subscribers();
5662

57-
/**
58-
* @brief Initialise the node's publishers.
59-
*/
63+
/** @brief Creates all publishers and initialises the time keeper. */
6064
void publishers();
6165

66+
/**
67+
* @brief Converts and stores the received lanelet map.
68+
* @param msg Binary lanelet map message.
69+
*/
6270
void map_callback(const LaneletMapBin::ConstSharedPtr msg);
6371

72+
/**
73+
* @brief Forwards incoming candidate trajectories to the concatenator.
74+
* @param msg Incoming candidate trajectories message.
75+
*/
6476
void on_trajectories(const CandidateTrajectories::ConstSharedPtr msg);
6577

78+
/** @brief Concatenates buffered trajectories, validates them, and publishes the result. */
6679
void on_timer();
6780

81+
/** @brief Collects the latest sensor data needed for validation; returns an error string if any
82+
* mandatory input is unavailable. */
6883
tl::expected<trajectory_validator::FilterContext, std::string> take_validator_data();
6984

7085
std::unique_ptr<trajectory_concatenator::TrajectoryConcatenatorInterface> concatenator_ptr_;

planning/autoware_trajectory_validator/include/autoware/trajectory_validator/trajectory_validator_interface.hpp

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,63 +58,94 @@ using autoware_utils_diagnostics::DiagnosticsInterface;
5858
using geometry_msgs::msg::AccelWithCovarianceStamped;
5959
using nav_msgs::msg::Odometry;
6060

61+
/**
62+
* @brief ROS2 adapter for TrajectoryValidator: manages plugin loading, parameter updates,
63+
* diagnostics, and debug publishing.
64+
*/
6165
class TrajectoryValidatorInterface
6266
{
6367
public:
68+
/**
69+
* @brief Loads plugins declared in the parameter lists and initialises all publishers.
70+
* @param node ROS2 node used for publisher creation and logging.
71+
* @param node_parameters_interface Parameter interface for declaring and reading parameters.
72+
* @param vehicle_info Ego vehicle dimensions forwarded to each plugin.
73+
* @param time_keeper Shared time keeper for processing time tracking.
74+
*/
6475
TrajectoryValidatorInterface(
6576
rclcpp::Node & node,
6677
rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters_interface,
6778
vehicle_info_utils::VehicleInfo vehicle_info,
6879
std::shared_ptr<autoware_utils_debug::TimeKeeper> time_keeper);
6980

81+
/**
82+
* @brief Runs all plugins against the input trajectories and returns the feasible subset.
83+
* @param input_trajectories Candidate trajectories to validate.
84+
* @param context Current world state snapshot.
85+
*/
7086
CandidateTrajectories validate_trajectories(
7187
const CandidateTrajectories & input_trajectories, const ValidatorContext & context);
7288

7389
private:
90+
/** @brief Creates the debug publisher. */
7491
void publishers();
7592

93+
/** @brief Reloads parameters from the parameter server if they have changed. */
7694
void update_parameters();
7795

96+
/**
97+
* @brief Loads a single plugin by class name and configures it.
98+
* @param name Plugin class name to load.
99+
* @param is_shadow_mode If true, plugin results are logged but not enforced.
100+
*/
78101
void load_metric(const std::string & name, const bool is_shadow_mode = false);
79102

103+
/**
104+
* @brief Updates the diagnostics status based on the number of feasible trajectories.
105+
* @param input_trajectories Original input trajectories (used for total count).
106+
* @param num_feasible_trajectories Number of trajectories that passed all plugins.
107+
*/
80108
void update_diagnostic(
81109
const CandidateTrajectories & input_trajectories, const size_t num_feasible_trajectories);
82110

83111
/**
84-
* @brief Publishes validation reports
85-
* @param reports Validation reports to publish
112+
* @brief Publishes the validation report array.
113+
* @param reports Per-trajectory validation reports to publish.
86114
*/
87115
void publish_validation_reports(const std::vector<ValidationReport> & reports);
88116

89117
/**
90-
* @brief Publish the union of all debug information.
118+
* @brief Publishes all debug outputs: markers, report text, and processing times.
119+
* @param evaluation_tables Per-trajectory plugin evaluation results.
120+
* @param processing_time Per-plugin elapsed time in milliseconds.
121+
* @param marker_pose Pose used to position text markers in RViz.
91122
*/
92123
void publish_debug(
93124
const std::vector<EvaluationTable> & evaluation_tables,
94125
const std::unordered_map<std::string, double> & processing_time,
95126
const geometry_msgs::msg::Pose & marker_pose);
96127

97-
/**
98-
* @brief Publish each plugin's debug markers.
99-
*/
128+
/** @brief Publishes each plugin's accumulated debug markers. */
100129
void publish_plugins_debug_markers() const;
101130

102131
/**
103-
* @brief Publish each plugin's filtering report in a single string stamped marker.
132+
* @brief Publishes a text marker summarising how many trajectories each plugin filtered.
133+
* @param evaluation_tables Per-trajectory plugin evaluation results.
134+
* @param marker_pose Pose used to position the text marker in RViz.
104135
*/
105136
void publish_plugins_report_text(
106137
const std::vector<EvaluationTable> & evaluation_tables,
107138
const geometry_msgs::msg::Pose & marker_pose);
108-
/**
109139

110-
* @brief Publish each plugin's processing time as scalar value.
111-
* @param processing_time Map of plugin name -> elapsed time in [ms].
140+
/**
141+
* @brief Publishes each plugin's processing time as a scalar stamped value.
142+
* @param processing_time Per-plugin elapsed time in milliseconds.
112143
*/
113144
void publish_processing_time(const std::unordered_map<std::string, double> & processing_time);
114145

115146
/**
116-
* @brief Publish each plugin's processing time in a single string stamped marker.
117-
* @param processing_time Map of plugin name -> elapsed time in [ms].
147+
* @brief Publishes all plugin processing times as a single text marker.
148+
* @param processing_time Per-plugin elapsed time in milliseconds.
118149
*/
119150
void publish_processing_time_text(
120151
const std::unordered_map<std::string, double> & processing_time);

0 commit comments

Comments
 (0)