@@ -63,38 +63,10 @@ MotionVelocityPlannerNode::MotionVelocityPlannerNode(const rclcpp::NodeOptions &
63
63
sub_trajectory_ = this ->create_subscription <autoware_planning_msgs::msg::Trajectory>(
64
64
" ~/input/trajectory" , 1 , std::bind (&MotionVelocityPlannerNode::on_trajectory, this , _1),
65
65
create_subscription_options (this ));
66
- sub_predicted_objects_ =
67
- this ->create_subscription <autoware_perception_msgs::msg::PredictedObjects>(
68
- " ~/input/dynamic_objects" , 1 ,
69
- std::bind (&MotionVelocityPlannerNode::on_predicted_objects, this , _1),
70
- create_subscription_options (this ));
71
- sub_no_ground_pointcloud_ = this ->create_subscription <sensor_msgs::msg::PointCloud2>(
72
- " ~/input/no_ground_pointcloud" , rclcpp::SensorDataQoS (),
73
- std::bind (&MotionVelocityPlannerNode::on_no_ground_pointcloud, this , _1),
74
- create_subscription_options (this ));
75
- sub_vehicle_odometry_ = this ->create_subscription <nav_msgs::msg::Odometry>(
76
- " ~/input/vehicle_odometry" , 1 , std::bind (&MotionVelocityPlannerNode::on_odometry, this , _1),
77
- create_subscription_options (this ));
78
- sub_acceleration_ = this ->create_subscription <geometry_msgs::msg::AccelWithCovarianceStamped>(
79
- " ~/input/accel" , 1 , std::bind (&MotionVelocityPlannerNode::on_acceleration, this , _1),
80
- create_subscription_options (this ));
81
66
sub_lanelet_map_ = this ->create_subscription <autoware_map_msgs::msg::LaneletMapBin>(
82
67
" ~/input/vector_map" , rclcpp::QoS (10 ).transient_local (),
83
68
std::bind (&MotionVelocityPlannerNode::on_lanelet_map, this , _1),
84
69
create_subscription_options (this ));
85
- sub_traffic_signals_ =
86
- this ->create_subscription <autoware_perception_msgs::msg::TrafficLightGroupArray>(
87
- " ~/input/traffic_signals" , 1 ,
88
- std::bind (&MotionVelocityPlannerNode::on_traffic_signals, this , _1),
89
- create_subscription_options (this ));
90
- sub_virtual_traffic_light_states_ =
91
- this ->create_subscription <tier4_v2x_msgs::msg::VirtualTrafficLightStateArray>(
92
- " ~/input/virtual_traffic_light_states" , 1 ,
93
- std::bind (&MotionVelocityPlannerNode::on_virtual_traffic_light_states, this , _1),
94
- create_subscription_options (this ));
95
- sub_occupancy_grid_ = this ->create_subscription <nav_msgs::msg::OccupancyGrid>(
96
- " ~/input/occupancy_grid" , 1 , std::bind (&MotionVelocityPlannerNode::on_occupancy_grid, this , _1),
97
- create_subscription_options (this ));
98
70
99
71
srv_load_plugin_ = create_service<LoadPlugin>(
100
72
" ~/service/load_plugin" , std::bind (&MotionVelocityPlannerNode::on_load_plugin, this , _1, _2));
@@ -151,45 +123,59 @@ void MotionVelocityPlannerNode::on_unload_plugin(
151
123
}
152
124
153
125
// NOTE: argument planner_data must not be referenced for multithreading
154
- bool MotionVelocityPlannerNode::is_data_ready () const
126
+ bool MotionVelocityPlannerNode::update_planner_data ()
155
127
{
156
- const auto & d = planner_data_;
157
128
auto clock = *get_clock ();
158
- const auto check_with_msg = [&](const auto ptr, const auto & msg) {
129
+ auto is_ready = true ;
130
+ const auto check_with_log = [&](const auto ptr, const auto & log ) {
159
131
constexpr auto throttle_duration = 3000 ; // [ms]
160
132
if (!ptr) {
161
- RCLCPP_INFO_THROTTLE (get_logger (), clock , throttle_duration, msg);
133
+ RCLCPP_INFO_THROTTLE (get_logger (), clock , throttle_duration, log );
134
+ is_ready = false ;
162
135
return false ;
163
136
}
164
137
return true ;
165
138
};
166
139
167
- return check_with_msg (d.current_odometry , " Waiting for current odometry" ) &&
168
- check_with_msg (d.current_velocity , " Waiting for current velocity" ) &&
169
- check_with_msg (d.current_acceleration , " Waiting for current acceleration" ) &&
170
- check_with_msg (d.predicted_objects , " Waiting for predicted objects" ) &&
171
- check_with_msg (d.no_ground_pointcloud , " Waiting for pointcloud" ) &&
172
- check_with_msg (map_ptr_, " Waiting for the map" ) &&
173
- check_with_msg (
174
- d.velocity_smoother_ , " Waiting for the initialization of the velocity smoother" ) &&
175
- check_with_msg (d.occupancy_grid , " Waiting for the occupancy grid" );
176
- }
140
+ const auto ego_state_ptr = sub_vehicle_odometry_.takeData ();
141
+ if (check_with_log (ego_state_ptr, " Waiting for current odometry" ))
142
+ planner_data_.current_odometry = *ego_state_ptr;
177
143
178
- void MotionVelocityPlannerNode::on_occupancy_grid (
179
- const nav_msgs::msg::OccupancyGrid::ConstSharedPtr msg)
180
- {
181
- std::lock_guard<std::mutex> lock (mutex_);
182
- planner_data_.occupancy_grid = msg;
183
- }
144
+ const auto ego_accel_ptr = sub_acceleration_.takeData ();
145
+ if (check_with_log (ego_accel_ptr, " Waiting for current acceleration" ))
146
+ planner_data_.current_acceleration = *ego_accel_ptr;
184
147
185
- void MotionVelocityPlannerNode::on_predicted_objects (
186
- const autoware_perception_msgs::msg::PredictedObjects::ConstSharedPtr msg)
187
- {
188
- std::lock_guard<std::mutex> lock (mutex_);
189
- planner_data_.predicted_objects = msg;
148
+ const auto predicted_objects_ptr = sub_predicted_objects_.takeData ();
149
+ if (check_with_log (predicted_objects_ptr, " Waiting for predicted objects" ))
150
+ planner_data_.predicted_objects = *predicted_objects_ptr;
151
+
152
+ const auto no_ground_pointcloud_ptr = sub_no_ground_pointcloud_.takeData ();
153
+ if (check_with_log (no_ground_pointcloud_ptr, " Waiting for pointcloud" )) {
154
+ const auto no_ground_pointcloud = process_no_ground_pointcloud (no_ground_pointcloud_ptr);
155
+ if (no_ground_pointcloud) planner_data_.no_ground_pointcloud = *no_ground_pointcloud;
156
+ }
157
+
158
+ const auto occupancy_grid_ptr = sub_occupancy_grid_.takeData ();
159
+ if (check_with_log (occupancy_grid_ptr, " Waiting for the occupancy grid" ))
160
+ planner_data_.occupancy_grid = *occupancy_grid_ptr;
161
+
162
+ // here we use bitwise operator to not short-circuit the logging messages
163
+ is_ready &= check_with_log (map_ptr_, " Waiting for the map" );
164
+ is_ready &= check_with_log (
165
+ planner_data_.velocity_smoother_ , " Waiting for the initialization of the velocity smoother" );
166
+
167
+ // optional data
168
+ const auto traffic_signals_ptr = sub_traffic_signals_.takeData ();
169
+ if (traffic_signals_ptr) process_traffic_signals (traffic_signals_ptr);
170
+ const auto virtual_traffic_light_states_ptr = sub_virtual_traffic_light_states_.takeData ();
171
+ if (virtual_traffic_light_states_ptr)
172
+ planner_data_.virtual_traffic_light_states = *virtual_traffic_light_states_ptr;
173
+
174
+ return is_ready;
190
175
}
191
176
192
- void MotionVelocityPlannerNode::on_no_ground_pointcloud (
177
+ std::optional<pcl::PointCloud<pcl::PointXYZ>>
178
+ MotionVelocityPlannerNode::process_no_ground_pointcloud (
193
179
const sensor_msgs::msg::PointCloud2::ConstSharedPtr msg)
194
180
{
195
181
geometry_msgs::msg::TransformStamped transform;
@@ -198,44 +184,16 @@ void MotionVelocityPlannerNode::on_no_ground_pointcloud(
198
184
" map" , msg->header .frame_id , msg->header .stamp , rclcpp::Duration::from_seconds (0.1 ));
199
185
} catch (tf2::TransformException & e) {
200
186
RCLCPP_WARN (get_logger (), " no transform found for no_ground_pointcloud: %s" , e.what ());
201
- return ;
187
+ return {} ;
202
188
}
203
189
204
190
pcl::PointCloud<pcl::PointXYZ> pc;
205
191
pcl::fromROSMsg (*msg, pc);
206
192
207
193
Eigen::Affine3f affine = tf2::transformToEigen (transform.transform ).cast <float >();
208
194
pcl::PointCloud<pcl::PointXYZ>::Ptr pc_transformed (new pcl::PointCloud<pcl::PointXYZ>);
209
- if (!pc.empty ()) {
210
- tier4_autoware_utils::transformPointCloud (pc, *pc_transformed, affine);
211
- }
212
-
213
- {
214
- std::lock_guard<std::mutex> lock (mutex_);
215
- planner_data_.no_ground_pointcloud = pc_transformed;
216
- }
217
- }
218
-
219
- void MotionVelocityPlannerNode::on_odometry (const nav_msgs::msg::Odometry::ConstSharedPtr msg)
220
- {
221
- std::lock_guard<std::mutex> lock (mutex_);
222
-
223
- auto current_odometry = std::make_shared<geometry_msgs::msg::PoseStamped>();
224
- current_odometry->header = msg->header ;
225
- current_odometry->pose = msg->pose .pose ;
226
- planner_data_.current_odometry = current_odometry;
227
-
228
- auto current_velocity = std::make_shared<geometry_msgs::msg::TwistStamped>();
229
- current_velocity->header = msg->header ;
230
- current_velocity->twist = msg->twist .twist ;
231
- planner_data_.current_velocity = current_velocity;
232
- }
233
-
234
- void MotionVelocityPlannerNode::on_acceleration (
235
- const geometry_msgs::msg::AccelWithCovarianceStamped::ConstSharedPtr msg)
236
- {
237
- std::lock_guard<std::mutex> lock (mutex_);
238
- planner_data_.current_acceleration = msg;
195
+ if (!pc.empty ()) tier4_autoware_utils::transformPointCloud (pc, *pc_transformed, affine);
196
+ return *pc_transformed;
239
197
}
240
198
241
199
void MotionVelocityPlannerNode::set_velocity_smoother_params ()
@@ -253,11 +211,9 @@ void MotionVelocityPlannerNode::on_lanelet_map(
253
211
has_received_map_ = true ;
254
212
}
255
213
256
- void MotionVelocityPlannerNode::on_traffic_signals (
214
+ void MotionVelocityPlannerNode::process_traffic_signals (
257
215
const autoware_perception_msgs::msg::TrafficLightGroupArray::ConstSharedPtr msg)
258
216
{
259
- std::lock_guard<std::mutex> lock (mutex_);
260
-
261
217
// clear previous observation
262
218
planner_data_.traffic_light_id_map_raw_ .clear ();
263
219
const auto traffic_light_id_map_last_observed_old =
@@ -290,19 +246,12 @@ void MotionVelocityPlannerNode::on_traffic_signals(
290
246
}
291
247
}
292
248
293
- void MotionVelocityPlannerNode::on_virtual_traffic_light_states (
294
- const tier4_v2x_msgs::msg::VirtualTrafficLightStateArray::ConstSharedPtr msg)
295
- {
296
- std::lock_guard<std::mutex> lock (mutex_);
297
- planner_data_.virtual_traffic_light_states = msg;
298
- }
299
-
300
249
void MotionVelocityPlannerNode::on_trajectory (
301
250
const autoware_planning_msgs::msg::Trajectory::ConstSharedPtr input_trajectory_msg)
302
251
{
303
252
std::unique_lock<std::mutex> lk (mutex_);
304
253
305
- if (!is_data_ready ()) {
254
+ if (!update_planner_data ()) {
306
255
return ;
307
256
}
308
257
@@ -367,9 +316,9 @@ autoware::motion_velocity_planner::TrajectoryPoints MotionVelocityPlannerNode::s
367
316
const autoware::motion_velocity_planner::TrajectoryPoints & trajectory_points,
368
317
const autoware::motion_velocity_planner::PlannerData & planner_data) const
369
318
{
370
- const geometry_msgs::msg::Pose current_pose = planner_data.current_odometry -> pose ;
371
- const double v0 = planner_data.current_velocity -> twist .linear .x ;
372
- const double a0 = planner_data.current_acceleration -> accel .accel .linear .x ;
319
+ const geometry_msgs::msg::Pose current_pose = planner_data.current_odometry . pose . pose ;
320
+ const double v0 = planner_data.current_odometry . twist . twist .linear .x ;
321
+ const double a0 = planner_data.current_acceleration . accel .accel .linear .x ;
373
322
const auto & external_v_limit = planner_data.external_velocity_limit ;
374
323
const auto & smoother = planner_data.velocity_smoother_ ;
375
324
0 commit comments