Skip to content

Commit 9a63f6f

Browse files
committed
structure change and add reset function
Signed-off-by: Berkay Karaman <brkay54@gmail.com>
1 parent a7aad75 commit 9a63f6f

6 files changed

+1246
-1119
lines changed

tools/reaction_analyzer/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ find_package(Eigen3 REQUIRED)
1010
ament_auto_add_library(reaction_analyzer SHARED
1111
include/reaction_analyzer_node.hpp
1212
src/reaction_analyzer_node.cpp
13+
include/topic_publisher.hpp
14+
src/topic_publisher.cpp
1315
)
1416

1517
target_include_directories(reaction_analyzer

tools/reaction_analyzer/include/reaction_analyzer_node.hpp

+25-152
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <rosbag2_cpp/reader.hpp>
2121
#include <tier4_autoware_utils/geometry/geometry.hpp>
2222
#include <tier4_autoware_utils/math/unit_conversion.hpp>
23+
#include <topic_publisher.hpp>
2324

2425
#include <autoware_adapi_v1_msgs/msg/localization_initialization_state.hpp>
2526
#include <autoware_adapi_v1_msgs/msg/operation_mode_state.hpp>
@@ -29,18 +30,8 @@
2930
#include <autoware_auto_perception_msgs/msg/detected_objects.hpp>
3031
#include <autoware_auto_perception_msgs/msg/predicted_objects.hpp>
3132
#include <autoware_auto_planning_msgs/msg/trajectory.hpp>
32-
#include <autoware_auto_vehicle_msgs/msg/control_mode_report.hpp>
33-
#include <autoware_auto_vehicle_msgs/msg/gear_report.hpp>
34-
#include <autoware_auto_vehicle_msgs/msg/hazard_lights_report.hpp>
35-
#include <autoware_auto_vehicle_msgs/msg/steering_report.hpp>
36-
#include <autoware_auto_vehicle_msgs/msg/turn_indicators_report.hpp>
37-
#include <autoware_auto_vehicle_msgs/msg/velocity_report.hpp>
3833
#include <geometry_msgs/msg/pose_with_covariance_stamped.hpp>
3934
#include <nav_msgs/msg/odometry.hpp>
40-
#include <sensor_msgs/msg/camera_info.hpp>
41-
#include <sensor_msgs/msg/image.hpp>
42-
#include <sensor_msgs/msg/imu.hpp>
43-
#include <sensor_msgs/msg/point_cloud2.hpp>
4435

4536
#include <pcl/common/distances.h>
4637
#include <pcl/point_types.h>
@@ -75,6 +66,7 @@ using TrajectoryBuffer = std::optional<Trajectory>;
7566
using PointCloud2Buffer = std::optional<PointCloud2>;
7667
using PredictedObjectsBuffer = std::optional<PredictedObjects>;
7768
using DetectedObjectsBuffer = std::optional<DetectedObjects>;
69+
7870
using BufferVariant = std::variant<
7971
ControlCommandBuffer, TrajectoryBuffer, PointCloud2Buffer, PredictedObjectsBuffer,
8072
DetectedObjectsBuffer>;
@@ -88,21 +80,6 @@ enum class SubscriberMessageType {
8880
PredictedObjects = 5,
8981
};
9082

91-
enum class PublisherMessageType {
92-
Unknown = 0,
93-
CameraInfo = 1,
94-
Image = 2,
95-
PointCloud2 = 3,
96-
PoseWithCovarianceStamped = 4,
97-
Imu = 5,
98-
ControlModeReport = 6,
99-
GearReport = 7,
100-
HazardLightsReport = 8,
101-
SteeringReport = 9,
102-
TurnIndicatorsReport = 10,
103-
VelocityReport = 11,
104-
};
105-
10683
enum class RunningMode {
10784
PerceptionPlanning = 0,
10885
PlanningControl = 1,
@@ -140,124 +117,23 @@ struct EntityParams
140117
double z_l;
141118
};
142119

143-
struct GeneralParams
120+
struct NodeParams
144121
{
145122
std::string running_mode;
146123
double timer_period;
147124
double object_search_radius_offset;
148-
EntityParams entity_params;
149-
PoseParams goal_pose;
150-
};
151-
152-
struct PerceptionPlanningModeParams
153-
{
154-
std::string path_bag_without_object;
155-
std::string path_bag_with_object;
156-
bool publish_pointcloud_synchronically;
157-
double synchronic_pointcloud_publishing_period;
158125
double spawn_time_after_init;
159-
};
160-
161-
struct PlanningControlModeParams
162-
{
163126
double spawn_distance_threshold;
164127
double spawned_pointcloud_sampling_distance;
128+
double dummy_perception_publisher_period;
165129
double control_cmd_buffer_time_interval;
166130
double min_jerk_for_brake_cmd;
167131
size_t min_number_descending_order_control_cmd;
168132
PoseParams initial_pose;
133+
PoseParams goal_pose;
134+
EntityParams entity_params;
169135
};
170136

171-
template <typename MessageType>
172-
struct PublisherVariables
173-
{
174-
double period_ns{0.0};
175-
typename MessageType::SharedPtr empty_area_message;
176-
typename MessageType::SharedPtr object_spawned_message;
177-
typename rclcpp::Publisher<MessageType>::SharedPtr publisher;
178-
rclcpp::TimerBase::SharedPtr timer;
179-
};
180-
181-
struct PublisherVarAccessor
182-
{
183-
template <typename T, typename = std::void_t<>>
184-
struct has_header : std::false_type
185-
{
186-
};
187-
188-
template <typename T>
189-
struct has_header<T, std::void_t<decltype(T::header)>> : std::true_type
190-
{
191-
};
192-
template <typename T, typename = std::void_t<>>
193-
struct has_stamp : std::false_type
194-
{
195-
};
196-
197-
template <typename T>
198-
struct has_stamp<T, std::void_t<decltype(T::stamp)>> : std::true_type
199-
{
200-
};
201-
template <typename MessageType>
202-
void publishWithCurrentTime(
203-
const PublisherVariables<MessageType> & publisherVar, const rclcpp::Time & current_time,
204-
const bool is_object_spawned) const
205-
{
206-
std::unique_ptr<MessageType> msg_to_be_published = std::make_unique<MessageType>();
207-
208-
if (is_object_spawned) {
209-
*msg_to_be_published = *publisherVar.object_spawned_message;
210-
} else {
211-
*msg_to_be_published = *publisherVar.empty_area_message;
212-
}
213-
if constexpr (has_header<MessageType>::value) {
214-
msg_to_be_published->header.stamp = current_time;
215-
} else if constexpr (has_stamp<MessageType>::value) {
216-
msg_to_be_published->stamp = current_time;
217-
}
218-
publisherVar.publisher->publish(std::move(msg_to_be_published));
219-
}
220-
// Set Period
221-
template <typename T>
222-
void setPeriod(T & publisherVar, double newPeriod)
223-
{
224-
publisherVar.period_ns = newPeriod;
225-
}
226-
227-
// Get Period
228-
template <typename T>
229-
double getPeriod(const T & publisherVar) const
230-
{
231-
return publisherVar.period_ns;
232-
}
233-
234-
// Get Empty Area Message
235-
template <typename T>
236-
std::shared_ptr<void> getEmptyAreaMessage(const T & publisherVar) const
237-
{
238-
return std::static_pointer_cast<void>(publisherVar.empty_area_message);
239-
}
240-
241-
// Get Object Spawned Message
242-
template <typename T>
243-
std::shared_ptr<void> getObjectSpawnedMessage(const T & publisherVar) const
244-
{
245-
return std::static_pointer_cast<void>(publisherVar.object_spawned_message);
246-
}
247-
};
248-
249-
using PublisherVariablesVariant = std::variant<
250-
PublisherVariables<PointCloud2>, PublisherVariables<sensor_msgs::msg::CameraInfo>,
251-
PublisherVariables<sensor_msgs::msg::Image>,
252-
PublisherVariables<geometry_msgs::msg::PoseWithCovarianceStamped>,
253-
PublisherVariables<sensor_msgs::msg::Imu>,
254-
PublisherVariables<autoware_auto_vehicle_msgs::msg::ControlModeReport>,
255-
PublisherVariables<autoware_auto_vehicle_msgs::msg::GearReport>,
256-
PublisherVariables<autoware_auto_vehicle_msgs::msg::HazardLightsReport>,
257-
PublisherVariables<autoware_auto_vehicle_msgs::msg::SteeringReport>,
258-
PublisherVariables<autoware_auto_vehicle_msgs::msg::TurnIndicatorsReport>,
259-
PublisherVariables<autoware_auto_vehicle_msgs::msg::VelocityReport>>;
260-
261137
class ReactionAnalyzerNode : public rclcpp::Node
262138
{
263139
public:
@@ -270,17 +146,7 @@ class ReactionAnalyzerNode : public rclcpp::Node
270146
RunningMode node_running_mode_;
271147

272148
// Parameters
273-
GeneralParams general_params_;
274-
PerceptionPlanningModeParams perception_planning_mode_params_;
275-
PlanningControlModeParams planning_control_mode_params_;
276-
277-
// TEMP
278-
void genericMessagePublisher(const std::string & topic_name);
279-
std::unordered_map<std::string, PublisherVariablesVariant> topic_publisher_map_;
280-
std::vector<PublisherVariables<PointCloud2>> sync_pointcloud_publishers_;
281-
void syncPointcloudPublisher();
282-
rclcpp::TimerBase::SharedPtr sync_pointcloud_publish_timer_;
283-
void initRosbagPublishers();
149+
NodeParams node_params_;
284150

285151
// Initialization Variables
286152
geometry_msgs::msg::Pose entity_pose_;
@@ -324,8 +190,9 @@ class ReactionAnalyzerNode : public rclcpp::Node
324190
void initPredictedObjects();
325191

326192
void initEgoForTest(
327-
LocalizationInitializationState::ConstSharedPtr initialization_state_ptr,
328-
RouteState::ConstSharedPtr route_state_ptr);
193+
const LocalizationInitializationState::ConstSharedPtr & initialization_state_ptr,
194+
const RouteState::ConstSharedPtr & route_state_ptr,
195+
const OperationModeState::ConstSharedPtr & operation_mode_ptr);
329196

330197
void setControlCommandToBuffer(
331198
std::vector<AckermannControlCommand> & buffer, const AckermannControlCommand & cmd);
@@ -334,13 +201,16 @@ class ReactionAnalyzerNode : public rclcpp::Node
334201
const std::vector<AckermannControlCommand> & cmd_array,
335202
const std::optional<rclcpp::Time> & spawn_cmd_time);
336203

337-
void spawnObstacle(
338-
const geometry_msgs::msg::Point & ego_pose, std::optional<rclcpp::Time> & spawn_cmd_time);
204+
void spawnObstacle(const geometry_msgs::msg::Point & ego_pose);
339205

340206
void printResults(const std::unordered_map<std::string, BufferVariant> & message_buffers);
341207

342208
void onTimer();
343209

210+
void dummyPerceptionPublisher();
211+
212+
void reset();
213+
344214
// Callbacks
345215
void vehiclePoseCallback(Odometry::ConstSharedPtr msg_ptr);
346216

@@ -350,7 +220,7 @@ class ReactionAnalyzerNode : public rclcpp::Node
350220

351221
void operationModeCallback(OperationModeState::ConstSharedPtr msg_ptr);
352222

353-
// Callbacks for modules are observed
223+
// Callbacks for modules are subscribed
354224
void controlCommandOutputCallback(
355225
const std::string & node_name, const AckermannControlCommand::ConstSharedPtr & msg_ptr);
356226

@@ -369,23 +239,26 @@ class ReactionAnalyzerNode : public rclcpp::Node
369239
// Variables
370240
std::vector<rclcpp::SubscriptionBase::SharedPtr> subscribers_;
371241
std::unordered_map<std::string, BufferVariant> message_buffers_;
372-
std::optional<rclcpp::Time> last_test_environment_init_time_;
242+
std::optional<rclcpp::Time> last_test_environment_init_request_time_;
243+
std::optional<rclcpp::Time> test_environment_init_time_;
373244
std::optional<rclcpp::Time> spawn_cmd_time_;
374-
std::atomic<bool> is_object_spawned_{false};
375-
bool is_test_environment_created_{false};
376-
bool is_ego_initialized_{false};
377-
bool is_route_set_{false};
245+
std::atomic<bool> spawn_object_cmd_{false};
246+
std::atomic<bool> is_object_spawned_message_published_{false};
378247
bool is_output_printed_{false};
379-
248+
bool is_vehicle_initialized_{false};
249+
bool is_route_set_{false};
380250
// Timer
381251
rclcpp::TimerBase::SharedPtr timer_;
252+
rclcpp::TimerBase::SharedPtr dummy_perception_timer_;
382253

383254
// Client
384255
rclcpp::Client<ChangeOperationMode>::SharedPtr client_change_to_autonomous_;
385256

386257
void callOperationModeServiceWithoutResponse();
387258

388259
// Pointers
260+
std::shared_ptr<topic_publisher::TopicPublisher> topic_publisher_ptr_;
261+
389262
PointCloud2::SharedPtr entity_pointcloud_ptr_;
390263
PredictedObjects::SharedPtr predicted_objects_ptr_;
391264
Odometry::ConstSharedPtr odometry_;

0 commit comments

Comments
 (0)