Skip to content

Commit edbd6e9

Browse files
committed
feat: add wrong initialize localization protection, improve code readability
Signed-off-by: Berkay Karaman <brkay54@gmail.com>
1 parent 1b6768c commit edbd6e9

6 files changed

+689
-574
lines changed

tools/reaction_analyzer/include/reaction_analyzer_node.hpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ using autoware_adapi_v1_msgs::srv::ChangeOperationMode;
5959
using autoware_auto_perception_msgs::msg::PredictedObject;
6060
using autoware_auto_perception_msgs::msg::PredictedObjects;
6161
using geometry_msgs::msg::Pose;
62+
using geometry_msgs::msg::PoseStamped;
6263
using nav_msgs::msg::Odometry;
6364
using sensor_msgs::msg::PointCloud2;
6465

@@ -112,8 +113,7 @@ class ReactionAnalyzerNode : public rclcpp::Node
112113
explicit ReactionAnalyzerNode(rclcpp::NodeOptions options);
113114
~ReactionAnalyzerNode() = default;
114115

115-
Odometry::ConstSharedPtr odometry_;
116-
116+
Odometry::ConstSharedPtr odometry_ptr_;
117117
private:
118118
std::mutex mutex_;
119119
RunningMode node_running_mode_;
@@ -131,6 +131,7 @@ class ReactionAnalyzerNode : public rclcpp::Node
131131
rclcpp::Subscription<RouteState>::SharedPtr sub_route_state_;
132132
rclcpp::Subscription<LocalizationInitializationState>::SharedPtr sub_localization_init_state_;
133133
rclcpp::Subscription<OperationModeState>::SharedPtr sub_operation_mode_;
134+
rclcpp::Subscription<PoseStamped>::SharedPtr sub_ground_truth_pose_;
134135

135136
// Publishers
136137
rclcpp::Publisher<PointCloud2>::SharedPtr pub_pointcloud_;
@@ -163,7 +164,9 @@ class ReactionAnalyzerNode : public rclcpp::Node
163164
void initEgoForTest(
164165
const LocalizationInitializationState::ConstSharedPtr & initialization_state_ptr,
165166
const RouteState::ConstSharedPtr & route_state_ptr,
166-
const OperationModeState::ConstSharedPtr & operation_mode_ptr);
167+
const OperationModeState::ConstSharedPtr & operation_mode_ptr,
168+
const PoseStamped::ConstSharedPtr & ground_truth_pose_ptr,
169+
const Odometry::ConstSharedPtr & odometry_ptr);
167170

168171
void callOperationModeServiceWithoutResponse();
169172

@@ -186,10 +189,11 @@ class ReactionAnalyzerNode : public rclcpp::Node
186189

187190
void initializationStateCallback(LocalizationInitializationState::ConstSharedPtr msg_ptr);
188191

189-
void routeStateCallback(RouteState::ConstSharedPtr msg);
192+
void routeStateCallback(RouteState::ConstSharedPtr msg_ptr);
190193

191194
void operationModeCallback(OperationModeState::ConstSharedPtr msg_ptr);
192195

196+
void groundTruthPoseCallback(PoseStamped::ConstSharedPtr msg_ptr);
193197
// Timer
194198
rclcpp::TimerBase::SharedPtr timer_;
195199
rclcpp::TimerBase::SharedPtr dummy_perception_timer_;
@@ -205,6 +209,7 @@ class ReactionAnalyzerNode : public rclcpp::Node
205209
LocalizationInitializationState::ConstSharedPtr initialization_state_ptr_;
206210
RouteState::ConstSharedPtr current_route_state_ptr_;
207211
OperationModeState::ConstSharedPtr operation_mode_ptr_;
212+
PoseStamped::ConstSharedPtr ground_truth_pose_ptr_;
208213
};
209214
} // namespace reaction_analyzer
210215

tools/reaction_analyzer/include/topic_publisher.hpp

+17-7
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ enum class PublisherMessageType {
5959
IMAGE = 2,
6060
POINTCLOUD2 = 3,
6161
POSE_WITH_COVARIANCE_STAMPED = 4,
62-
IMU = 5,
63-
CONTROL_MODE_REPORT = 6,
64-
GEAR_REPORT = 7,
65-
HAZARD_LIGHTS_REPORT = 8,
66-
STEERING_REPORT = 9,
67-
TURN_INDICATORS_REPORT = 10,
68-
VELOCITY_REPORT = 11,
62+
POSE_STAMPED = 5,
63+
ODOMETRY = 6,
64+
IMU = 7,
65+
CONTROL_MODE_REPORT = 8,
66+
GEAR_REPORT = 9,
67+
HAZARD_LIGHTS_REPORT = 10,
68+
STEERING_REPORT = 11,
69+
TURN_INDICATORS_REPORT = 12,
70+
VELOCITY_REPORT = 13,
6971
};
7072

7173
struct TopicPublisherParams
@@ -173,6 +175,7 @@ using PublisherVariablesVariant = std::variant<
173175
PublisherVariables<PointCloud2>, PublisherVariables<sensor_msgs::msg::CameraInfo>,
174176
PublisherVariables<sensor_msgs::msg::Image>,
175177
PublisherVariables<geometry_msgs::msg::PoseWithCovarianceStamped>,
178+
PublisherVariables<geometry_msgs::msg::PoseStamped>, PublisherVariables<nav_msgs::msg::Odometry>,
176179
PublisherVariables<sensor_msgs::msg::Imu>,
177180
PublisherVariables<autoware_auto_vehicle_msgs::msg::ControlModeReport>,
178181
PublisherVariables<autoware_auto_vehicle_msgs::msg::GearReport>,
@@ -207,6 +210,13 @@ class TopicPublisher
207210
TopicPublisherParams topic_publisher_params_;
208211

209212
// Functions
213+
void setMessageToVariableMap(
214+
const PublisherMessageType & message_type, const std::string & topic_name,
215+
rosbag2_storage::SerializedBagMessage & bag_message, const bool is_empty_area_message);
216+
void setPeriodToVariableMap(
217+
const std::unordered_map<std::string, std::vector<rclcpp::Time>> & time_map);
218+
bool setPublishersAndTimersToVariableMap();
219+
bool checkPublishersInitializedCorrectly();
210220
void initRosbagPublishers();
211221
void pointcloudMessagesSyncPublisher(const PointcloudPublisherType type);
212222
void genericMessagePublisher(const std::string & topic_name);

tools/reaction_analyzer/launch/reaction_analyzer.launch.xml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<remap from="input/localization_initialization_state" to="/api/localization/initialization_state"/>
3838
<remap from="input/routing_state" to="/api/routing/state"/>
3939
<remap from="input/operation_mode_state" to="/api/operation_mode/state"/>
40+
<remap from="input/ground_truth_pose" to="/awsim/ground_truth/vehicle/pose"/>
4041
<param name="running_mode" value="$(var running_mode)"/>
4142
<extra_arg name="use_intra_process_comms" value="false"/>
4243
</composable_node>

tools/reaction_analyzer/param/reaction_analyzer.param.yaml

+52-52
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@
5555
topic_name: /planning/scenario_planning/lane_driving/trajectory
5656
time_debug_topic_name: /planning/scenario_planning/lane_driving/trajectory/debug/published_time
5757
message_type: autoware_auto_planning_msgs/msg/Trajectory
58-
scenario_selector:
59-
topic_name: /planning/scenario_planning/scenario_selector/trajectory
60-
time_debug_topic_name: /planning/scenario_planning/scenario_selector/trajectory/debug/published_time
61-
message_type: autoware_auto_planning_msgs/msg/Trajectory
62-
motion_velocity_smoother:
63-
topic_name: /planning/scenario_planning/motion_velocity_smoother/trajectory
64-
time_debug_topic_name: /planning/scenario_planning/motion_velocity_smoother/trajectory/debug/published_time
65-
message_type: autoware_auto_planning_msgs/msg/Trajectory
66-
planning_validator:
67-
topic_name: /planning/scenario_planning/trajectory
68-
time_debug_topic_name: /planning/scenario_planning/trajectory/debug/published_time
69-
message_type: autoware_auto_planning_msgs/msg/Trajectory
58+
# scenario_selector:
59+
# topic_name: /planning/scenario_planning/scenario_selector/trajectory
60+
# time_debug_topic_name: /planning/scenario_planning/scenario_selector/trajectory/debug/published_time
61+
# message_type: autoware_auto_planning_msgs/msg/Trajectory
62+
# motion_velocity_smoother:
63+
# topic_name: /planning/scenario_planning/motion_velocity_smoother/trajectory
64+
# time_debug_topic_name: /planning/scenario_planning/motion_velocity_smoother/trajectory/debug/published_time
65+
# message_type: autoware_auto_planning_msgs/msg/Trajectory
66+
# planning_validator:
67+
# topic_name: /planning/scenario_planning/trajectory
68+
# time_debug_topic_name: /planning/scenario_planning/trajectory/debug/published_time
69+
# message_type: autoware_auto_planning_msgs/msg/Trajectory
7070
# trajectory_follower:
7171
# topic_name: /control/trajectory_follower/control_cmd
7272
# time_debug_topic_name: /control/trajectory_follower/control_cmd/debug/published_time
@@ -75,43 +75,43 @@
7575
# topic_name: /control/command/control_cmd
7676
# time_debug_topic_name: /control/command/control_cmd/debug/published_time
7777
# message_type: autoware_auto_control_msgs/msg/AckermannControlCommand
78-
common_ground_filter:
79-
topic_name: /perception/obstacle_segmentation/single_frame/pointcloud_raw
80-
time_debug_topic_name: /perception/obstacle_segmentation/single_frame/pointcloud_raw/debug/published_time
81-
message_type: sensor_msgs/msg/PointCloud2
82-
occupancy_grid_map_outlier:
83-
topic_name: /perception/obstacle_segmentation/pointcloud
84-
time_debug_topic_name: /perception/obstacle_segmentation/pointcloud/debug/published_time
85-
message_type: sensor_msgs/msg/PointCloud2
86-
multi_object_tracker:
87-
topic_name: /perception/object_recognition/tracking/near_objects
88-
time_debug_topic_name: /perception/object_recognition/tracking/near_objects/debug/published_time
89-
message_type: autoware_auto_perception_msgs/msg/TrackedObjects
90-
lidar_centerpoint:
91-
topic_name: /perception/object_recognition/detection/centerpoint/objects
92-
time_debug_topic_name: /perception/object_recognition/detection/centerpoint/objects/debug/published_time
93-
message_type: autoware_auto_perception_msgs/msg/DetectedObjects
94-
obstacle_pointcloud_based_validator:
95-
topic_name: /perception/object_recognition/detection/centerpoint/validation/objects
96-
time_debug_topic_name: /perception/object_recognition/detection/centerpoint/validation/objects/debug/published_time
97-
message_type: autoware_auto_perception_msgs/msg/DetectedObjects
98-
decorative_tracker_merger:
99-
topic_name: /perception/object_recognition/tracking/objects
100-
time_debug_topic_name: /perception/object_recognition/tracking/objects/debug/published_time
101-
message_type: autoware_auto_perception_msgs/msg/TrackedObjects
102-
detected_object_feature_remover:
103-
topic_name: /perception/object_recognition/detection/clustering/objects
104-
time_debug_topic_name: /perception/object_recognition/detection/clustering/objects/debug/published_time
105-
message_type: autoware_auto_perception_msgs/msg/DetectedObjects
106-
detection_by_tracker:
107-
topic_name: /perception/object_recognition/detection/detection_by_tracker/objects
108-
time_debug_topic_name: /perception/object_recognition/detection/detection_by_tracker/objects/debug/published_time
109-
message_type: autoware_auto_perception_msgs/msg/DetectedObjects
110-
object_lanelet_filter:
111-
topic_name: /perception/object_recognition/detection/objects
112-
time_debug_topic_name: /perception/object_recognition/detection/objects/debug/published_time
113-
message_type: autoware_auto_perception_msgs/msg/DetectedObjects
114-
map_based_prediction:
115-
topic_name: /perception/object_recognition/objects
116-
time_debug_topic_name: /perception/object_recognition/objects/debug/published_time
117-
message_type: autoware_auto_perception_msgs/msg/PredictedObjects
78+
# common_ground_filter:
79+
# topic_name: /perception/obstacle_segmentation/single_frame/pointcloud_raw
80+
# time_debug_topic_name: /perception/obstacle_segmentation/single_frame/pointcloud_raw/debug/published_time
81+
# message_type: sensor_msgs/msg/PointCloud2
82+
# occupancy_grid_map_outlier:
83+
# topic_name: /perception/obstacle_segmentation/pointcloud
84+
# time_debug_topic_name: /perception/obstacle_segmentation/pointcloud/debug/published_time
85+
# message_type: sensor_msgs/msg/PointCloud2
86+
# multi_object_tracker:
87+
# topic_name: /perception/object_recognition/tracking/near_objects
88+
# time_debug_topic_name: /perception/object_recognition/tracking/near_objects/debug/published_time
89+
# message_type: autoware_auto_perception_msgs/msg/TrackedObjects
90+
# lidar_centerpoint:
91+
# topic_name: /perception/object_recognition/detection/centerpoint/objects
92+
# time_debug_topic_name: /perception/object_recognition/detection/centerpoint/objects/debug/published_time
93+
# message_type: autoware_auto_perception_msgs/msg/DetectedObjects
94+
# obstacle_pointcloud_based_validator:
95+
# topic_name: /perception/object_recognition/detection/centerpoint/validation/objects
96+
# time_debug_topic_name: /perception/object_recognition/detection/centerpoint/validation/objects/debug/published_time
97+
# message_type: autoware_auto_perception_msgs/msg/DetectedObjects
98+
# decorative_tracker_merger:
99+
# topic_name: /perception/object_recognition/tracking/objects
100+
# time_debug_topic_name: /perception/object_recognition/tracking/objects/debug/published_time
101+
# message_type: autoware_auto_perception_msgs/msg/TrackedObjects
102+
# detected_object_feature_remover:
103+
# topic_name: /perception/object_recognition/detection/clustering/objects
104+
# time_debug_topic_name: /perception/object_recognition/detection/clustering/objects/debug/published_time
105+
# message_type: autoware_auto_perception_msgs/msg/DetectedObjects
106+
# detection_by_tracker:
107+
# topic_name: /perception/object_recognition/detection/detection_by_tracker/objects
108+
# time_debug_topic_name: /perception/object_recognition/detection/detection_by_tracker/objects/debug/published_time
109+
# message_type: autoware_auto_perception_msgs/msg/DetectedObjects
110+
# object_lanelet_filter:
111+
# topic_name: /perception/object_recognition/detection/objects
112+
# time_debug_topic_name: /perception/object_recognition/detection/objects/debug/published_time
113+
# message_type: autoware_auto_perception_msgs/msg/DetectedObjects
114+
# map_based_prediction:
115+
# topic_name: /perception/object_recognition/objects
116+
# time_debug_topic_name: /perception/object_recognition/objects/debug/published_time
117+
# message_type: autoware_auto_perception_msgs/msg/PredictedObjects

tools/reaction_analyzer/src/reaction_analyzer_node.cpp

+58-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void ReactionAnalyzerNode::routeStateCallback(RouteState::ConstSharedPtr msg_ptr
3535
void ReactionAnalyzerNode::vehiclePoseCallback(Odometry::ConstSharedPtr msg_ptr)
3636
{
3737
std::lock_guard<std::mutex> lock(mutex_);
38-
odometry_ = msg_ptr;
38+
odometry_ptr_ = msg_ptr;
3939
}
4040

4141
void ReactionAnalyzerNode::initializationStateCallback(
@@ -45,6 +45,12 @@ void ReactionAnalyzerNode::initializationStateCallback(
4545
initialization_state_ptr_ = std::move(msg_ptr);
4646
}
4747

48+
void ReactionAnalyzerNode::groundTruthPoseCallback(PoseStamped::ConstSharedPtr msg_ptr)
49+
{
50+
std::lock_guard<std::mutex> lock(mutex_);
51+
ground_truth_pose_ptr_ = std::move(msg_ptr);
52+
}
53+
4854
ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
4955
: Node("reaction_analyzer_node", options.automatically_declare_parameters_from_overrides(true))
5056
{
@@ -130,6 +136,7 @@ ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
130136
// init dummy perception publisher
131137
const auto period_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
132138
std::chrono::duration<double>(node_params_.dummy_perception_publisher_period));
139+
133140
dummy_perception_timer_ = rclcpp::create_timer(
134141
this, get_clock(), period_ns,
135142
std::bind(&ReactionAnalyzerNode::dummyPerceptionPublisher, this));
@@ -138,12 +145,19 @@ ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
138145
// Create topic publishers
139146
topic_publisher_ptr_ =
140147
std::make_shared<topic_publisher::TopicPublisher>(this, spawn_object_cmd_, spawn_cmd_time_);
148+
149+
// Subscribe to the ground truth position
150+
sub_ground_truth_pose_ = create_subscription<PoseStamped>(
151+
"input/ground_truth_pose", rclcpp::QoS{1},
152+
std::bind(&ReactionAnalyzerNode::groundTruthPoseCallback, this, _1),
153+
createSubscriptionOptions(this));
141154
}
142155

143156
// Load the subscriber to listen the topics for reactions
144-
odometry_ = std::make_shared<Odometry>(); // initialize the odometry before init the subscriber
145-
subscriber_ptr_ =
146-
std::make_unique<subscriber::SubscriberBase>(this, odometry_, entity_pose_, spawn_object_cmd_);
157+
odometry_ptr_ =
158+
std::make_shared<Odometry>(); // initialize the odometry before init the subscriber
159+
subscriber_ptr_ = std::make_unique<subscriber::SubscriberBase>(
160+
this, odometry_ptr_, entity_pose_, spawn_object_cmd_);
147161

148162
const auto period_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
149163
std::chrono::duration<double>(node_params_.timer_period));
@@ -154,16 +168,19 @@ ReactionAnalyzerNode::ReactionAnalyzerNode(rclcpp::NodeOptions options)
154168
void ReactionAnalyzerNode::onTimer()
155169
{
156170
mutex_.lock();
157-
const auto current_odometry_ptr = odometry_;
171+
const auto current_odometry_ptr = odometry_ptr_;
158172
const auto initialization_state_ptr = initialization_state_ptr_;
159173
const auto route_state_ptr = current_route_state_ptr_;
160174
const auto operation_mode_ptr = operation_mode_ptr_;
175+
const auto ground_truth_pose_ptr = ground_truth_pose_ptr_;
161176
const auto spawn_cmd_time = spawn_cmd_time_;
162177
mutex_.unlock();
163178

164179
// Init the test environment
165180
if (!test_environment_init_time_) {
166-
initEgoForTest(initialization_state_ptr, route_state_ptr, operation_mode_ptr);
181+
initEgoForTest(
182+
initialization_state_ptr, route_state_ptr, operation_mode_ptr, ground_truth_pose_ptr,
183+
current_odometry_ptr);
167184
return;
168185
}
169186

@@ -437,11 +454,13 @@ void ReactionAnalyzerNode::initPredictedObjects()
437454
void ReactionAnalyzerNode::initEgoForTest(
438455
const LocalizationInitializationState::ConstSharedPtr & initialization_state_ptr,
439456
const RouteState::ConstSharedPtr & route_state_ptr,
440-
const OperationModeState::ConstSharedPtr & operation_mode_ptr)
457+
const OperationModeState::ConstSharedPtr & operation_mode_ptr,
458+
const PoseStamped::ConstSharedPtr & ground_truth_pose_ptr,
459+
const Odometry::ConstSharedPtr & odometry_ptr)
441460
{
442461
const auto current_time = this->now();
443462

444-
// Initialize the vehicle
463+
// Initialize the test environment
445464
constexpr double initialize_call_period = 1.0; // sec
446465

447466
if (
@@ -450,6 +469,7 @@ void ReactionAnalyzerNode::initEgoForTest(
450469
initialize_call_period) {
451470
last_test_environment_init_request_time_ = current_time;
452471

472+
// Pose initialization of the ego
453473
if (
454474
initialization_state_ptr &&
455475
(initialization_state_ptr->state != LocalizationInitializationState::INITIALIZED ||
@@ -466,6 +486,35 @@ void ReactionAnalyzerNode::initEgoForTest(
466486
return;
467487
}
468488

489+
// Wait until odometry_ptr is initialized
490+
if (!odometry_ptr) {
491+
RCLCPP_WARN_ONCE(get_logger(), "Odometry is not received. Waiting for odometry...");
492+
return;
493+
}
494+
495+
// Check is position initialized accurately, if node is running PerceptionPlanning mode
496+
if (node_running_mode_ == RunningMode::PerceptionPlanning) {
497+
if (!ground_truth_pose_ptr) {
498+
RCLCPP_WARN(
499+
get_logger(), "Ground truth pose is not received. Waiting for Ground truth pose...");
500+
return;
501+
} else {
502+
constexpr double deviation_threshold = 0.1;
503+
const auto deviation = tier4_autoware_utils::calcPoseDeviation(
504+
ground_truth_pose_ptr->pose, odometry_ptr->pose.pose);
505+
if (
506+
deviation.longitudinal > deviation_threshold || deviation.lateral > deviation_threshold ||
507+
deviation.yaw > deviation_threshold) {
508+
RCLCPP_ERROR(
509+
get_logger(),
510+
"Deviation between ground truth position and ego position is high. Node is shutting "
511+
"down. Longitudinal deviation: %f, Lateral deviation: %f, Yaw deviation: %f",
512+
deviation.longitudinal, deviation.lateral, deviation.yaw);
513+
rclcpp::shutdown();
514+
}
515+
}
516+
}
517+
469518
if (route_state_ptr && (route_state_ptr->state != RouteState::SET || !is_route_set_)) {
470519
if (route_state_ptr->state == RouteState::SET) {
471520
is_route_set_ = true;
@@ -477,6 +526,7 @@ void ReactionAnalyzerNode::initEgoForTest(
477526
return;
478527
}
479528

529+
// if node is running PlanningControl mode, change ego to Autonomous mode.
480530
if (node_running_mode_ == RunningMode::PlanningControl) {
481531
// change to autonomous
482532
if (operation_mode_ptr && operation_mode_ptr->mode != OperationModeState::AUTONOMOUS) {

0 commit comments

Comments
 (0)