Skip to content

Commit 7adc3d0

Browse files
go-sakayoriKhalilSelyan
authored and
KhalilSelyan
committed
fix(vehicle_cmd_gate): put back subscriber rather than using polling subsriber (#7500)
put back polling subscribers to subscribers in neccesary cases Signed-off-by: Go Sakayori <go.sakayori@tier4.jp> Signed-off-by: Go Sakayori <gsakayori@gmail.com>
1 parent 0110e8f commit 7adc3d0

File tree

2 files changed

+60
-71
lines changed

2 files changed

+60
-71
lines changed

control/autoware_vehicle_cmd_gate/src/vehicle_cmd_gate.cpp

+43-45
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,37 @@ VehicleCmdGate::VehicleCmdGate(const rclcpp::NodeOptions & node_options)
8787
external_emergency_stop_heartbeat_sub_ = create_subscription<Heartbeat>(
8888
"input/external_emergency_stop_heartbeat", 1,
8989
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+
// Subscriber for external
115+
remote_control_cmd_sub_ = create_subscription<Control>(
116+
"input/external/control_cmd", 1, std::bind(&VehicleCmdGate::onRemoteCtrlCmd, this, _1));
117+
118+
// Subscriber for emergency
119+
emergency_control_cmd_sub_ = create_subscription<Control>(
120+
"input/emergency/control_cmd", 1, std::bind(&VehicleCmdGate::onEmergencyCtrlCmd, this, _1));
90121

91122
// Parameter
92123
use_emergency_handling_ = declare_parameter<bool>("use_emergency_handling");
@@ -291,32 +322,29 @@ bool VehicleCmdGate::isDataReady()
291322
}
292323

293324
// for auto
294-
void VehicleCmdGate::onAutoCtrlCmd()
325+
void VehicleCmdGate::onAutoCtrlCmd(Control::ConstSharedPtr msg)
295326
{
296-
const auto msg = auto_control_cmd_sub_.takeData();
297-
if (msg) auto_commands_.control = *msg;
327+
auto_commands_.control = *msg;
298328

299329
if (current_gate_mode_.data == GateMode::AUTO) {
300330
publishControlCommands(auto_commands_);
301331
}
302332
}
303333

304334
// for remote
305-
void VehicleCmdGate::onRemoteCtrlCmd()
335+
void VehicleCmdGate::onRemoteCtrlCmd(Control::ConstSharedPtr msg)
306336
{
307-
const auto msg = remote_control_cmd_sub_.takeData();
308-
if (msg) remote_commands_.control = *msg;
337+
remote_commands_.control = *msg;
309338

310339
if (current_gate_mode_.data == GateMode::EXTERNAL) {
311340
publishControlCommands(remote_commands_);
312341
}
313342
}
314343

315344
// for emergency
316-
void VehicleCmdGate::onEmergencyCtrlCmd()
345+
void VehicleCmdGate::onEmergencyCtrlCmd(Control::ConstSharedPtr msg)
317346
{
318-
const auto msg = emergency_control_cmd_sub_.takeData();
319-
if (msg) emergency_commands_.control = *msg;
347+
emergency_commands_.control = *msg;
320348

321349
if (use_emergency_handling_ && is_system_emergency_) {
322350
publishControlCommands(emergency_commands_);
@@ -325,25 +353,7 @@ void VehicleCmdGate::onEmergencyCtrlCmd()
325353

326354
void VehicleCmdGate::onTimer()
327355
{
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-
344356
// Subscriber for auto
345-
onAutoCtrlCmd();
346-
347357
const auto msg_auto_command_turn_indicator = auto_turn_indicator_cmd_sub_.takeData();
348358
if (msg_auto_command_turn_indicator)
349359
auto_commands_.turn_indicator = *msg_auto_command_turn_indicator;
@@ -355,8 +365,6 @@ void VehicleCmdGate::onTimer()
355365
if (msg_auto_command_gear) auto_commands_.gear = *msg_auto_command_gear;
356366

357367
// Subscribe for external
358-
onRemoteCtrlCmd();
359-
360368
const auto msg_remote_command_turn_indicator = remote_turn_indicator_cmd_sub_.takeData();
361369
if (msg_remote_command_turn_indicator)
362370
remote_commands_.turn_indicator = *msg_remote_command_turn_indicator;
@@ -369,17 +377,13 @@ void VehicleCmdGate::onTimer()
369377
if (msg_remote_command_gear) remote_commands_.gear = *msg_remote_command_gear;
370378

371379
// Subscribe for emergency
372-
onEmergencyCtrlCmd();
373-
374380
const auto msg_emergency_command_hazard_light = emergency_hazard_light_cmd_sub_.takeData();
375381
if (msg_emergency_command_hazard_light)
376382
emergency_commands_.hazard_light = *msg_emergency_command_hazard_light;
377383

378384
const auto msg_emergency_command_gear = emergency_gear_cmd_sub_.takeData();
379385
if (msg_emergency_command_gear) emergency_commands_.gear = *msg_emergency_command_gear;
380386

381-
onEngage();
382-
383387
updater_.force_update();
384388

385389
if (!isDataReady()) {
@@ -705,11 +709,8 @@ void VehicleCmdGate::onExternalEmergencyStopHeartbeat(
705709
external_emergency_stop_heartbeat_received_time_ = std::make_shared<rclcpp::Time>(this->now());
706710
}
707711

708-
void VehicleCmdGate::onGateMode()
712+
void VehicleCmdGate::onGateMode(GateMode::ConstSharedPtr msg)
709713
{
710-
const auto msg = gate_mode_sub_.takeData();
711-
if (!msg) return;
712-
713714
const auto prev_gate_mode = current_gate_mode_;
714715
current_gate_mode_ = *msg;
715716

@@ -720,10 +721,9 @@ void VehicleCmdGate::onGateMode()
720721
}
721722
}
722723

723-
void VehicleCmdGate::onEngage()
724+
void VehicleCmdGate::onEngage(EngageMsg::ConstSharedPtr msg)
724725
{
725-
const auto msg = engage_sub_.takeData();
726-
if (msg) is_engaged_ = msg->engage;
726+
is_engaged_ = msg->engage;
727727
}
728728

729729
void VehicleCmdGate::onEngageService(
@@ -733,11 +733,8 @@ void VehicleCmdGate::onEngageService(
733733
response->status = tier4_api_utils::response_success();
734734
}
735735

736-
void VehicleCmdGate::onMrmState()
736+
void VehicleCmdGate::onMrmState(MrmState::ConstSharedPtr msg)
737737
{
738-
const auto msg = mrm_state_sub_.takeData();
739-
if (!msg) return;
740-
741738
is_system_emergency_ =
742739
(msg->state == MrmState::MRM_OPERATING || msg->state == MrmState::MRM_SUCCEEDED ||
743740
msg->state == MrmState::MRM_FAILED) &&
@@ -830,7 +827,8 @@ void VehicleCmdGate::checkExternalEmergencyStop(diagnostic_updater::DiagnosticSt
830827
} else if (is_external_emergency_stop_) {
831828
status.level = DiagnosticStatus::ERROR;
832829
status.message =
833-
"external_emergency_stop is required. Please call `clear_external_emergency_stop` service to "
830+
"external_emergency_stop is required. Please call `clear_external_emergency_stop` service "
831+
"to "
834832
"clear state.";
835833
} else {
836834
status.level = DiagnosticStatus::OK;

control/autoware_vehicle_cmd_gate/src/vehicle_cmd_gate.hpp

+17-26
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,16 @@ class VehicleCmdGate : public rclcpp::Node
119119
const std::vector<rclcpp::Parameter> & parameters);
120120
// Subscription
121121
rclcpp::Subscription<Heartbeat>::SharedPtr external_emergency_stop_heartbeat_sub_;
122-
tier4_autoware_utils::InterProcessPollingSubscriber<GateMode> gate_mode_sub_{
123-
this, "input/gate_mode"};
124-
tier4_autoware_utils::InterProcessPollingSubscriber<OperationModeState> operation_mode_sub_{
125-
this, "input/operation_mode", rclcpp::QoS(1).transient_local()};
126-
tier4_autoware_utils::InterProcessPollingSubscriber<MrmState> mrm_state_sub_{
127-
this, "input/mrm_state"};
128-
tier4_autoware_utils::InterProcessPollingSubscriber<Odometry> kinematics_sub_{
129-
this, "/localization/kinematic_state"}; // for filter
130-
tier4_autoware_utils::InterProcessPollingSubscriber<AccelWithCovarianceStamped> acc_sub_{
131-
this, "input/acceleration"}; // for filter
132-
tier4_autoware_utils::InterProcessPollingSubscriber<SteeringReport> steer_sub_{
133-
this, "input/steering"}; // for filter
134-
135-
void onGateMode();
122+
rclcpp::Subscription<GateMode>::SharedPtr gate_mode_sub_;
123+
rclcpp::Subscription<OperationModeState>::SharedPtr operation_mode_sub_;
124+
rclcpp::Subscription<MrmState>::SharedPtr mrm_state_sub_;
125+
rclcpp::Subscription<Odometry>::SharedPtr kinematics_sub_; // for filter
126+
rclcpp::Subscription<AccelWithCovarianceStamped>::SharedPtr acc_sub_; // for filter
127+
rclcpp::Subscription<SteeringReport>::SharedPtr steer_sub_; // for filter
128+
129+
void onGateMode(GateMode::ConstSharedPtr msg);
136130
void onExternalEmergencyStopHeartbeat(Heartbeat::ConstSharedPtr msg);
137-
void onMrmState();
131+
void onMrmState(MrmState::ConstSharedPtr msg);
138132

139133
bool is_engaged_;
140134
bool is_system_emergency_ = false;
@@ -160,37 +154,34 @@ class VehicleCmdGate : public rclcpp::Node
160154

161155
// Subscriber for auto
162156
Commands auto_commands_;
163-
tier4_autoware_utils::InterProcessPollingSubscriber<Control> auto_control_cmd_sub_{
164-
this, "input/auto/control_cmd"};
157+
rclcpp::Subscription<Control>::SharedPtr auto_control_cmd_sub_;
165158
tier4_autoware_utils::InterProcessPollingSubscriber<TurnIndicatorsCommand>
166159
auto_turn_indicator_cmd_sub_{this, "input/auto/turn_indicators_cmd"};
167160
tier4_autoware_utils::InterProcessPollingSubscriber<HazardLightsCommand>
168161
auto_hazard_light_cmd_sub_{this, "input/auto/hazard_lights_cmd"};
169162
tier4_autoware_utils::InterProcessPollingSubscriber<GearCommand> auto_gear_cmd_sub_{
170163
this, "input/auto/gear_cmd"};
171-
void onAutoCtrlCmd();
164+
void onAutoCtrlCmd(Control::ConstSharedPtr msg);
172165

173166
// Subscription for external
174167
Commands remote_commands_;
175-
tier4_autoware_utils::InterProcessPollingSubscriber<Control> remote_control_cmd_sub_{
176-
this, "input/external/control_cmd"};
168+
rclcpp::Subscription<Control>::SharedPtr remote_control_cmd_sub_;
177169
tier4_autoware_utils::InterProcessPollingSubscriber<TurnIndicatorsCommand>
178170
remote_turn_indicator_cmd_sub_{this, "input/external/turn_indicators_cmd"};
179171
tier4_autoware_utils::InterProcessPollingSubscriber<HazardLightsCommand>
180172
remote_hazard_light_cmd_sub_{this, "input/external/hazard_lights_cmd"};
181173
tier4_autoware_utils::InterProcessPollingSubscriber<GearCommand> remote_gear_cmd_sub_{
182174
this, "input/external/gear_cmd"};
183-
void onRemoteCtrlCmd();
175+
void onRemoteCtrlCmd(Control::ConstSharedPtr msg);
184176

185177
// Subscription for emergency
186178
Commands emergency_commands_;
187-
tier4_autoware_utils::InterProcessPollingSubscriber<Control> emergency_control_cmd_sub_{
188-
this, "input/emergency/control_cmd"};
179+
rclcpp::Subscription<Control>::SharedPtr emergency_control_cmd_sub_;
189180
tier4_autoware_utils::InterProcessPollingSubscriber<HazardLightsCommand>
190181
emergency_hazard_light_cmd_sub_{this, "input/emergency/hazard_lights_cmd"};
191182
tier4_autoware_utils::InterProcessPollingSubscriber<GearCommand> emergency_gear_cmd_sub_{
192183
this, "input/emergency/gear_cmd"};
193-
void onEmergencyCtrlCmd();
184+
void onEmergencyCtrlCmd(Control::ConstSharedPtr msg);
194185

195186
// Parameter
196187
bool use_emergency_handling_;
@@ -216,10 +207,10 @@ class VehicleCmdGate : public rclcpp::Node
216207
const SetEmergency::Response::SharedPtr response);
217208

218209
// TODO(Takagi, Isamu): deprecated
219-
tier4_autoware_utils::InterProcessPollingSubscriber<EngageMsg> engage_sub_{this, "input/engage"};
210+
rclcpp::Subscription<EngageMsg>::SharedPtr engage_sub_;
220211
rclcpp::Service<Trigger>::SharedPtr srv_external_emergency_stop_;
221212
rclcpp::Service<Trigger>::SharedPtr srv_clear_external_emergency_stop_;
222-
void onEngage();
213+
void onEngage(EngageMsg::ConstSharedPtr msg);
223214
bool onSetExternalEmergencyStopService(
224215
const std::shared_ptr<rmw_request_id_t> req_header, const Trigger::Request::SharedPtr req,
225216
const Trigger::Response::SharedPtr res);

0 commit comments

Comments
 (0)