Skip to content

Commit a7aad75

Browse files
pre-commit-ci[bot]brkay54
authored andcommitted
clean up
Signed-off-by: Berkay Karaman <brkay54@gmail.com>
1 parent fd6766a commit a7aad75

File tree

4 files changed

+989
-918
lines changed

4 files changed

+989
-918
lines changed

tools/reaction_analyzer/include/reaction_analyzer_node.hpp

+95-110
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ using BufferVariant = std::variant<
7979
ControlCommandBuffer, TrajectoryBuffer, PointCloud2Buffer, PredictedObjectsBuffer,
8080
DetectedObjectsBuffer>;
8181

82-
enum class MessageType {
82+
enum class SubscriberMessageType {
8383
Unknown = 0,
8484
AckermannControlCommand = 1,
8585
Trajectory = 2,
@@ -88,11 +88,31 @@ enum class MessageType {
8888
PredictedObjects = 5,
8989
};
9090

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+
106+
enum class RunningMode {
107+
PerceptionPlanning = 0,
108+
PlanningControl = 1,
109+
};
110+
91111
struct TopicConfig
92112
{
93113
std::string node_name;
94114
std::string topic_address;
95-
MessageType message_type;
115+
SubscriberMessageType message_type;
96116
};
97117

98118
using ChainModules = std::vector<TopicConfig>;
@@ -120,76 +140,83 @@ struct EntityParams
120140
double z_l;
121141
};
122142

123-
struct NodeParams
143+
struct GeneralParams
124144
{
145+
std::string running_mode;
125146
double timer_period;
147+
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;
158+
double spawn_time_after_init;
159+
};
160+
161+
struct PlanningControlModeParams
162+
{
126163
double spawn_distance_threshold;
164+
double spawned_pointcloud_sampling_distance;
127165
double control_cmd_buffer_time_interval;
128166
double min_jerk_for_brake_cmd;
129-
int min_number_descending_order_control_cmd;
130-
bool run_from_bag;
131-
};
132-
133-
enum class PublisherMessageType {
134-
Unknown = 0,
135-
CameraInfo = 1,
136-
Image = 2,
137-
PointCloud2 = 3,
138-
PoseWithCovarianceStamped = 4,
139-
Imu = 5,
140-
ControlModeReport = 6,
141-
GearReport = 7,
142-
HazardLightsReport = 8,
143-
SteeringReport = 9,
144-
TurnIndicatorsReport = 10,
145-
VelocityReport = 11,
167+
size_t min_number_descending_order_control_cmd;
168+
PoseParams initial_pose;
146169
};
147170

148171
template <typename MessageType>
149172
struct PublisherVariables
150173
{
151-
double period_ns;
174+
double period_ns{0.0};
152175
typename MessageType::SharedPtr empty_area_message;
153176
typename MessageType::SharedPtr object_spawned_message;
154177
typename rclcpp::Publisher<MessageType>::SharedPtr publisher;
155178
rclcpp::TimerBase::SharedPtr timer;
156179
};
157180

158-
template <typename T>
159-
struct PublisherVariablesMessageTypeExtractor;
160-
161-
template <typename MessageType>
162-
struct PublisherVariablesMessageTypeExtractor<PublisherVariables<MessageType>>
163-
{
164-
using Type = MessageType;
165-
};
166-
167-
template <typename T, typename = std::void_t<>>
168-
struct has_header : std::false_type
181+
struct PublisherVarAccessor
169182
{
170-
};
183+
template <typename T, typename = std::void_t<>>
184+
struct has_header : std::false_type
185+
{
186+
};
171187

172-
template <typename T>
173-
struct has_header<T, std::void_t<decltype(T::header)>> : std::true_type
174-
{
175-
};
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+
};
176196

177-
struct PublisherVarAccessor
178-
{
179-
// Method to set header time if available
180197
template <typename T>
181-
void setHeaderTimeIfAvailable(T & publisherVar, const rclcpp::Time & time)
198+
struct has_stamp<T, std::void_t<decltype(T::stamp)>> : std::true_type
182199
{
183-
if constexpr (has_header<typename T::MessageType>::value) {
184-
if (publisherVar.empty_area_message) {
185-
publisherVar.empty_area_message->header.stamp = time;
186-
}
187-
if (publisherVar.object_spawned_message) {
188-
publisherVar.object_spawned_message->header.stamp = time;
189-
}
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;
190212
}
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));
191219
}
192-
193220
// Set Period
194221
template <typename T>
195222
void setPeriod(T & publisherVar, double newPeriod)
@@ -204,62 +231,19 @@ struct PublisherVarAccessor
204231
return publisherVar.period_ns;
205232
}
206233

207-
// Set Empty Area Message
208-
template <typename T, typename Message>
209-
void setEmptyAreaMessage(T & publisherVar, typename Message::SharedPtr message)
210-
{
211-
publisherVar.empty_area_message = message;
212-
}
213-
214234
// Get Empty Area Message
215235
template <typename T>
216236
std::shared_ptr<void> getEmptyAreaMessage(const T & publisherVar) const
217237
{
218238
return std::static_pointer_cast<void>(publisherVar.empty_area_message);
219239
}
220240

221-
// Set Object Spawned Message
222-
template <typename T, typename Message>
223-
void setObjectSpawnedMessage(T & publisherVar, typename Message::SharedPtr message)
224-
{
225-
publisherVar.object_spawned_message = message;
226-
}
227-
228241
// Get Object Spawned Message
229242
template <typename T>
230243
std::shared_ptr<void> getObjectSpawnedMessage(const T & publisherVar) const
231244
{
232245
return std::static_pointer_cast<void>(publisherVar.object_spawned_message);
233246
}
234-
235-
// Set Publisher
236-
template <typename T, typename PublisherType>
237-
void setPublisher(
238-
T & publisherVar, typename rclcpp::Publisher<PublisherType>::SharedPtr publisher)
239-
{
240-
publisherVar.publisher = publisher;
241-
}
242-
243-
// Get Publisher
244-
template <typename T>
245-
std::shared_ptr<void> getPublisher(const T & publisherVar) const
246-
{
247-
return std::static_pointer_cast<void>(publisherVar.publisher);
248-
}
249-
250-
// Set Timer
251-
template <typename T>
252-
void setTimer(T & publisherVar, rclcpp::TimerBase::SharedPtr newTimer)
253-
{
254-
publisherVar.timer = newTimer;
255-
}
256-
257-
// Get Timer
258-
template <typename T>
259-
std::shared_ptr<void> getTimer(const T & publisherVar) const
260-
{
261-
return std::static_pointer_cast<void>(publisherVar.timer);
262-
}
263247
};
264248

265249
using PublisherVariablesVariant = std::variant<
@@ -283,26 +267,26 @@ class ReactionAnalyzerNode : public rclcpp::Node
283267

284268
private:
285269
std::mutex mutex_;
270+
RunningMode node_running_mode_;
286271

287272
// Parameters
288-
EntityParams entity_params_;
289-
PoseParams initial_pose_params_;
290-
PoseParams goal_pose_params_;
291-
NodeParams node_params_;
292-
double entity_search_radius_;
273+
GeneralParams general_params_;
274+
PerceptionPlanningModeParams perception_planning_mode_params_;
275+
PlanningControlModeParams planning_control_mode_params_;
293276

294277
// TEMP
295-
void genericMessagePublisherTimer(const std::string & topic_name);
278+
void genericMessagePublisher(const std::string & topic_name);
296279
std::unordered_map<std::string, PublisherVariablesVariant> topic_publisher_map_;
297280
std::vector<PublisherVariables<PointCloud2>> sync_pointcloud_publishers_;
298-
bool publish_pointcloud_sync_{true};
299-
void publishAllPointClouds();
281+
void syncPointcloudPublisher();
300282
rclcpp::TimerBase::SharedPtr sync_pointcloud_publish_timer_;
283+
void initRosbagPublishers();
301284

302285
// Initialization Variables
303286
geometry_msgs::msg::Pose entity_pose_;
304287
geometry_msgs::msg::PoseWithCovarianceStamped init_pose_;
305288
geometry_msgs::msg::PoseStamped goal_pose_;
289+
double entity_search_radius_;
306290

307291
// Subscribers
308292
rclcpp::Subscription<Odometry>::SharedPtr sub_kinematics_;
@@ -331,7 +315,7 @@ class ReactionAnalyzerNode : public rclcpp::Node
331315

332316
bool loadChainModules();
333317

334-
bool initObservers(const ChainModules & modules);
318+
bool initSubscribers(const reaction_analyzer::ChainModules & modules);
335319

336320
void initAnalyzerVariables();
337321

@@ -358,35 +342,36 @@ class ReactionAnalyzerNode : public rclcpp::Node
358342
void onTimer();
359343

360344
// Callbacks
361-
void vehiclePoseCallback(const Odometry::ConstSharedPtr msg_ptr);
345+
void vehiclePoseCallback(Odometry::ConstSharedPtr msg_ptr);
362346

363-
void initializationStateCallback(const LocalizationInitializationState::ConstSharedPtr msg_ptr);
347+
void initializationStateCallback(LocalizationInitializationState::ConstSharedPtr msg_ptr);
364348

365-
void routeStateCallback(const RouteState::ConstSharedPtr msg);
349+
void routeStateCallback(RouteState::ConstSharedPtr msg);
366350

367-
void operationModeCallback(const OperationModeState::ConstSharedPtr msg_ptr);
351+
void operationModeCallback(OperationModeState::ConstSharedPtr msg_ptr);
368352

369353
// Callbacks for modules are observed
370354
void controlCommandOutputCallback(
371-
const std::string & node_name, const AckermannControlCommand::ConstSharedPtr msg_ptr);
355+
const std::string & node_name, const AckermannControlCommand::ConstSharedPtr & msg_ptr);
372356

373357
void trajectoryOutputCallback(
374-
const std::string & node_name, const Trajectory::ConstSharedPtr msg_ptr);
358+
const std::string & node_name, const Trajectory::ConstSharedPtr & msg_ptr);
375359

376360
void pointcloud2OutputCallback(
377-
const std::string & node_name, const PointCloud2::ConstSharedPtr msg_ptr);
361+
const std::string & node_name, const PointCloud2::ConstSharedPtr & msg_ptr);
378362

379363
void predictedObjectsOutputCallback(
380-
const std::string & node_name, const PredictedObjects::ConstSharedPtr msg_ptr);
364+
const std::string & node_name, const PredictedObjects::ConstSharedPtr & msg_ptr);
381365

382366
void detectedObjectsOutputCallback(
383-
const std::string & node_name, const DetectedObjects::ConstSharedPtr msg_ptr);
367+
const std::string & node_name, const DetectedObjects::ConstSharedPtr & msg_ptr);
384368

385369
// Variables
386370
std::vector<rclcpp::SubscriptionBase::SharedPtr> subscribers_;
387371
std::unordered_map<std::string, BufferVariant> message_buffers_;
388372
std::optional<rclcpp::Time> last_test_environment_init_time_;
389373
std::optional<rclcpp::Time> spawn_cmd_time_;
374+
std::atomic<bool> is_object_spawned_{false};
390375
bool is_test_environment_created_{false};
391376
bool is_ego_initialized_{false};
392377
bool is_route_set_{false};

tools/reaction_analyzer/launch/reaction_analyzer.launch.xml

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
<launch>
22
<arg name="reaction_analyzer_param_path" default="$(find-pkg-share reaction_analyzer)/param/reaction_analyzer.param.yaml"/>
3+
<arg name="running_mode" default="perception_planning"/>
4+
<!-- planning_control or perception_planning -->
5+
<!-- Essential parameters -->
6+
<arg name="map_path" description="point cloud and lanelet2 map directory path"/>
7+
<arg name="vehicle_model" default="sample_vehicle" description="vehicle model name"/>
8+
<arg name="sensor_model" default="sample_sensor_kit" description="sensor model name"/>
9+
10+
<!-- <group if="$(eval &quot;'$(var running_mode)'=='perception_planning'&quot;)">-->
11+
<!-- <include file="$(find-pkg-share autoware_launch)/launch/e2e_simulator.launch.xml">-->
12+
<!-- <arg name="map_path" value="$(var map_path)"/>-->
13+
<!-- <arg name="vehicle_model" value="$(var vehicle_model)"/>-->
14+
<!-- <arg name="sensor_model" value="$(var sensor_model)"/>-->
15+
<!-- <arg name="use_sim_time" value="false"/>-->
16+
<!-- <arg name="enable_image_decompressor" value="false"/>-->
17+
<!-- </include>-->
18+
<!-- </group>-->
19+
<!-- <group if="$(eval &quot;'$(var running_mode)'=='planning_control'&quot;)">-->
20+
<!-- <include file="$(find-pkg-share autoware_launch)/launch/planning_simulator.launch.xml">-->
21+
<!-- <arg name="map_path" value="$(var map_path)"/>-->
22+
<!-- <arg name="vehicle_model" value="$(var vehicle_model)"/>-->
23+
<!-- <arg name="sensor_model" value="$(var sensor_model)"/>-->
24+
<!-- <arg name="use_sim_time" value="false"/>-->
25+
<!-- </include>-->
26+
<!-- </group>-->
27+
328
<node_container pkg="rclcpp_components" exec="component_container_mt" name="reaction_analyzer_container" namespace="" args="" output="screen">
429
<composable_node pkg="reaction_analyzer" plugin="reaction_analyzer::ReactionAnalyzerNode" name="reaction_analyzer" namespace="">
530
<param from="$(var reaction_analyzer_param_path)"/>
6-
<!-- <remap from="output/points_raw" to="/perception/obstacle_segmentation/pointcloud"/>-->
31+
<remap from="output/pointcloud" to="/perception/obstacle_segmentation/pointcloud"/>
732
<remap from="output/objects" to="/perception/object_recognition/objects"/>
833
<remap from="output/initialpose" to="/initialpose"/>
934
<remap from="output/goal" to="/planning/mission_planning/goal"/>
@@ -12,6 +37,7 @@
1237
<remap from="input/localization_initialization_state" to="/api/localization/initialization_state"/>
1338
<remap from="input/routing_state" to="/api/routing/state"/>
1439
<remap from="input/operation_mode_state" to="/api/operation_mode/state"/>
40+
<param name="running_mode" value="$(var running_mode)"/>
1541
<extra_arg name="use_intra_process_comms" value="false"/>
1642
</composable_node>
1743
</node_container>

0 commit comments

Comments
 (0)