@@ -87,69 +87,6 @@ VehicleCmdGate::VehicleCmdGate(const rclcpp::NodeOptions & node_options)
87
87
external_emergency_stop_heartbeat_sub_ = create_subscription<Heartbeat>(
88
88
" input/external_emergency_stop_heartbeat" , 1 ,
89
89
std::bind (&VehicleCmdGate::onExternalEmergencyStopHeartbeat, this , _1));
90
- gate_mode_sub_ = create_subscription<GateMode>(
91
- " input/gate_mode" , 1 , std::bind (&VehicleCmdGate::onGateMode, this , _1));
92
- engage_sub_ = create_subscription<EngageMsg>(
93
- " input/engage" , 1 , std::bind (&VehicleCmdGate::onEngage, this , _1));
94
- kinematics_sub_ = create_subscription<Odometry>(
95
- " /localization/kinematic_state" , 1 ,
96
- [this ](Odometry::SharedPtr msg) { current_kinematics_ = *msg; });
97
- acc_sub_ = create_subscription<AccelWithCovarianceStamped>(
98
- " input/acceleration" , 1 , [this ](AccelWithCovarianceStamped::SharedPtr msg) {
99
- current_acceleration_ = msg->accel .accel .linear .x ;
100
- });
101
- steer_sub_ = create_subscription<SteeringReport>(
102
- " input/steering" , 1 ,
103
- [this ](SteeringReport::SharedPtr msg) { current_steer_ = msg->steering_tire_angle ; });
104
- operation_mode_sub_ = create_subscription<OperationModeState>(
105
- " input/operation_mode" , rclcpp::QoS (1 ).transient_local (),
106
- [this ](const OperationModeState::SharedPtr msg) { current_operation_mode_ = *msg; });
107
- mrm_state_sub_ = create_subscription<MrmState>(
108
- " input/mrm_state" , 1 , std::bind (&VehicleCmdGate::onMrmState, this , _1));
109
-
110
- // Subscriber for auto
111
- auto_control_cmd_sub_ = create_subscription<Control>(
112
- " input/auto/control_cmd" , 1 , std::bind (&VehicleCmdGate::onAutoCtrlCmd, this , _1));
113
-
114
- auto_turn_indicator_cmd_sub_ = create_subscription<TurnIndicatorsCommand>(
115
- " input/auto/turn_indicators_cmd" , 1 ,
116
- [this ](TurnIndicatorsCommand::ConstSharedPtr msg) { auto_commands_.turn_indicator = *msg; });
117
-
118
- auto_hazard_light_cmd_sub_ = create_subscription<HazardLightsCommand>(
119
- " input/auto/hazard_lights_cmd" , 1 ,
120
- [this ](HazardLightsCommand::ConstSharedPtr msg) { auto_commands_.hazard_light = *msg; });
121
-
122
- auto_gear_cmd_sub_ = create_subscription<GearCommand>(
123
- " input/auto/gear_cmd" , 1 ,
124
- [this ](GearCommand::ConstSharedPtr msg) { auto_commands_.gear = *msg; });
125
-
126
- // Subscriber for external
127
- remote_control_cmd_sub_ = create_subscription<Control>(
128
- " input/external/control_cmd" , 1 , std::bind (&VehicleCmdGate::onRemoteCtrlCmd, this , _1));
129
-
130
- remote_turn_indicator_cmd_sub_ = create_subscription<TurnIndicatorsCommand>(
131
- " input/external/turn_indicators_cmd" , 1 ,
132
- [this ](TurnIndicatorsCommand::ConstSharedPtr msg) { remote_commands_.turn_indicator = *msg; });
133
-
134
- remote_hazard_light_cmd_sub_ = create_subscription<HazardLightsCommand>(
135
- " input/external/hazard_lights_cmd" , 1 ,
136
- [this ](HazardLightsCommand::ConstSharedPtr msg) { remote_commands_.hazard_light = *msg; });
137
-
138
- remote_gear_cmd_sub_ = create_subscription<GearCommand>(
139
- " input/external/gear_cmd" , 1 ,
140
- [this ](GearCommand::ConstSharedPtr msg) { remote_commands_.gear = *msg; });
141
-
142
- // Subscriber for emergency
143
- emergency_control_cmd_sub_ = create_subscription<Control>(
144
- " input/emergency/control_cmd" , 1 , std::bind (&VehicleCmdGate::onEmergencyCtrlCmd, this , _1));
145
-
146
- emergency_hazard_light_cmd_sub_ = create_subscription<HazardLightsCommand>(
147
- " input/emergency/hazard_lights_cmd" , 1 ,
148
- [this ](HazardLightsCommand::ConstSharedPtr msg) { emergency_commands_.hazard_light = *msg; });
149
-
150
- emergency_gear_cmd_sub_ = create_subscription<GearCommand>(
151
- " input/emergency/gear_cmd" , 1 ,
152
- [this ](GearCommand::ConstSharedPtr msg) { emergency_commands_.gear = *msg; });
153
90
154
91
// Parameter
155
92
use_emergency_handling_ = declare_parameter<bool >(" use_emergency_handling" );
@@ -354,29 +291,32 @@ bool VehicleCmdGate::isDataReady()
354
291
}
355
292
356
293
// for auto
357
- void VehicleCmdGate::onAutoCtrlCmd (Control::ConstSharedPtr msg )
294
+ void VehicleCmdGate::onAutoCtrlCmd ()
358
295
{
359
- auto_commands_.control = *msg;
296
+ const auto msg = auto_control_cmd_sub_.takeData ();
297
+ if (msg) auto_commands_.control = *msg;
360
298
361
299
if (current_gate_mode_.data == GateMode::AUTO) {
362
300
publishControlCommands (auto_commands_);
363
301
}
364
302
}
365
303
366
304
// for remote
367
- void VehicleCmdGate::onRemoteCtrlCmd (Control::ConstSharedPtr msg )
305
+ void VehicleCmdGate::onRemoteCtrlCmd ()
368
306
{
369
- remote_commands_.control = *msg;
307
+ const auto msg = remote_control_cmd_sub_.takeData ();
308
+ if (msg) remote_commands_.control = *msg;
370
309
371
310
if (current_gate_mode_.data == GateMode::EXTERNAL) {
372
311
publishControlCommands (remote_commands_);
373
312
}
374
313
}
375
314
376
315
// for emergency
377
- void VehicleCmdGate::onEmergencyCtrlCmd (Control::ConstSharedPtr msg )
316
+ void VehicleCmdGate::onEmergencyCtrlCmd ()
378
317
{
379
- emergency_commands_.control = *msg;
318
+ const auto msg = emergency_control_cmd_sub_.takeData ();
319
+ if (msg) emergency_commands_.control = *msg;
380
320
381
321
if (use_emergency_handling_ && is_system_emergency_) {
382
322
publishControlCommands (emergency_commands_);
@@ -385,6 +325,61 @@ void VehicleCmdGate::onEmergencyCtrlCmd(Control::ConstSharedPtr msg)
385
325
386
326
void VehicleCmdGate::onTimer ()
387
327
{
328
+ onGateMode ();
329
+
330
+ const auto msg_kinematics = kinematics_sub_.takeData ();
331
+ if (msg_kinematics) current_kinematics_ = *msg_kinematics;
332
+
333
+ const auto msg_acceleration = acc_sub_.takeData ();
334
+ if (msg_acceleration) current_acceleration_ = msg_acceleration->accel .accel .linear .x ;
335
+
336
+ const auto msg_steer = steer_sub_.takeData ();
337
+ if (msg_steer) current_steer_ = msg_steer->steering_tire_angle ;
338
+
339
+ const auto msg_operation_mode = operation_mode_sub_.takeData ();
340
+ if (msg_operation_mode) current_operation_mode_ = *msg_operation_mode;
341
+
342
+ onMrmState ();
343
+
344
+ // Subscriber for auto
345
+ onAutoCtrlCmd ();
346
+
347
+ const auto msg_auto_command_turn_indicator = auto_turn_indicator_cmd_sub_.takeData ();
348
+ if (msg_auto_command_turn_indicator)
349
+ auto_commands_.turn_indicator = *msg_auto_command_turn_indicator;
350
+
351
+ const auto msg_auto_command_hazard_light = auto_hazard_light_cmd_sub_.takeData ();
352
+ if (msg_auto_command_hazard_light) auto_commands_.hazard_light = *msg_auto_command_hazard_light;
353
+
354
+ const auto msg_auto_command_gear = auto_gear_cmd_sub_.takeData ();
355
+ if (msg_auto_command_gear) auto_commands_.gear = *msg_auto_command_gear;
356
+
357
+ // Subscribe for external
358
+ onRemoteCtrlCmd ();
359
+
360
+ const auto msg_remote_command_turn_indicator = remote_turn_indicator_cmd_sub_.takeData ();
361
+ if (msg_remote_command_turn_indicator)
362
+ remote_commands_.turn_indicator = *msg_remote_command_turn_indicator;
363
+
364
+ const auto msg_remote_command_hazard_light = remote_hazard_light_cmd_sub_.takeData ();
365
+ if (msg_remote_command_hazard_light)
366
+ remote_commands_.hazard_light = *msg_remote_command_hazard_light;
367
+
368
+ const auto msg_remote_command_gear = remote_gear_cmd_sub_.takeData ();
369
+ if (msg_remote_command_gear) remote_commands_.gear = *msg_remote_command_gear;
370
+
371
+ // Subscribe for emergency
372
+ onEmergencyCtrlCmd ();
373
+
374
+ const auto msg_emergency_command_hazard_light = emergency_hazard_light_cmd_sub_.takeData ();
375
+ if (msg_emergency_command_hazard_light)
376
+ emergency_commands_.hazard_light = *msg_emergency_command_hazard_light;
377
+
378
+ const auto msg_emergency_command_gear = emergency_gear_cmd_sub_.takeData ();
379
+ if (msg_emergency_command_gear) emergency_commands_.gear = *msg_emergency_command_gear;
380
+
381
+ onEngage ();
382
+
388
383
updater_.force_update ();
389
384
390
385
if (!isDataReady ()) {
@@ -710,10 +705,12 @@ void VehicleCmdGate::onExternalEmergencyStopHeartbeat(
710
705
external_emergency_stop_heartbeat_received_time_ = std::make_shared<rclcpp::Time>(this ->now ());
711
706
}
712
707
713
- void VehicleCmdGate::onGateMode (GateMode::ConstSharedPtr msg )
708
+ void VehicleCmdGate::onGateMode ()
714
709
{
710
+ const auto msg = gate_mode_sub_.takeData ();
711
+ if (!msg) return ;
712
+
715
713
const auto prev_gate_mode = current_gate_mode_;
716
- current_gate_mode_ = *msg;
717
714
718
715
if (current_gate_mode_.data != prev_gate_mode.data ) {
719
716
RCLCPP_INFO (
@@ -722,9 +719,10 @@ void VehicleCmdGate::onGateMode(GateMode::ConstSharedPtr msg)
722
719
}
723
720
}
724
721
725
- void VehicleCmdGate::onEngage (EngageMsg::ConstSharedPtr msg )
722
+ void VehicleCmdGate::onEngage ()
726
723
{
727
- is_engaged_ = msg->engage ;
724
+ const auto msg = engage_sub_.takeData ();
725
+ if (msg) is_engaged_ = msg->engage ;
728
726
}
729
727
730
728
void VehicleCmdGate::onEngageService (
@@ -734,8 +732,11 @@ void VehicleCmdGate::onEngageService(
734
732
response->status = tier4_api_utils::response_success ();
735
733
}
736
734
737
- void VehicleCmdGate::onMrmState (MrmState::ConstSharedPtr msg )
735
+ void VehicleCmdGate::onMrmState ()
738
736
{
737
+ const auto msg = mrm_state_sub_.takeData ();
738
+ if (!msg) return ;
739
+
739
740
is_system_emergency_ =
740
741
(msg->state == MrmState::MRM_OPERATING || msg->state == MrmState::MRM_SUCCEEDED ||
741
742
msg->state == MrmState::MRM_FAILED) &&
0 commit comments