-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(autoware_hazard_status_converter): ignore errors during initializ…
…ation Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
- Loading branch information
1 parent
4649cf6
commit 47f84ba
Showing
5 changed files
with
163 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
system/autoware_hazard_status_converter/src/mode_interface.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2025 The Autoware Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "mode_interface.hpp" | ||
|
||
namespace autoware::hazard_status_converter | ||
{ | ||
|
||
ModeInterface::ModeInterface(rclcpp::Node & node) : node_(node) | ||
{ | ||
sub_operation_mode_state_ = node.create_subscription<OperationModeState>( | ||
"/api/operation_mode/state", rclcpp::QoS(1).transient_local(), | ||
[this](const OperationModeState & msg) { operation_mode_state_ = msg; }); | ||
sub_autoware_state_ = node.create_subscription<AutowareState>( | ||
"/autoware/state", rclcpp::QoS(1), | ||
[this](const AutowareState & msg) { autoware_state_ = msg; }); | ||
} | ||
|
||
RootModeStatus ModeInterface::get_root() const | ||
{ | ||
const auto is_not_autoware_running = [this]() { | ||
if (autoware_state_->state == AutowareState::INITIALIZING) return true; | ||
if (autoware_state_->state == AutowareState::FINALIZING) return true; | ||
return false; | ||
}; | ||
|
||
const auto is_not_autonomous_ready = [this]() { | ||
if (autoware_state_->state == AutowareState::WAITING_FOR_ROUTE) return true; | ||
if (autoware_state_->state == AutowareState::PLANNING) return true; | ||
return false; | ||
}; | ||
|
||
// Returns unknown before receiving state messages. | ||
if (!operation_mode_state_ || !autoware_state_) { | ||
return {RootModeStatus::Mode::UNKNOWN, false}; | ||
} | ||
|
||
// During stop mode refer to autonomous mode diagnostics. | ||
if (operation_mode_state_->mode == OperationModeState::STOP) { | ||
return {RootModeStatus::Mode::AUTO, is_not_autoware_running() || is_not_autonomous_ready()}; | ||
} | ||
if (operation_mode_state_->mode == OperationModeState::AUTONOMOUS) { | ||
return {RootModeStatus::Mode::AUTO, is_not_autoware_running() || is_not_autonomous_ready()}; | ||
} | ||
if (operation_mode_state_->mode == OperationModeState::REMOTE) { | ||
return {RootModeStatus::Mode::REMOTE, is_not_autoware_running()}; | ||
} | ||
if (operation_mode_state_->mode == OperationModeState::LOCAL) { | ||
return {RootModeStatus::Mode::LOCAL, is_not_autoware_running()}; | ||
} | ||
return {RootModeStatus::Mode::UNKNOWN, false}; | ||
} | ||
Check warning on line 63 in system/autoware_hazard_status_converter/src/mode_interface.cpp
|
||
|
||
} // namespace autoware::hazard_status_converter |
59 changes: 59 additions & 0 deletions
59
system/autoware_hazard_status_converter/src/mode_interface.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2025 The Autoware Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef MODE_INTERFACE_HPP_ | ||
#define MODE_INTERFACE_HPP_ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <autoware_adapi_v1_msgs/msg/operation_mode_state.hpp> | ||
#include <autoware_system_msgs/msg/autoware_state.hpp> | ||
|
||
#include <optional> | ||
|
||
namespace autoware::hazard_status_converter | ||
{ | ||
|
||
struct RootModeStatus | ||
{ | ||
enum class Mode { | ||
UNKNOWN, | ||
AUTO, | ||
REMOTE, | ||
LOCAL, | ||
}; | ||
Mode mode; | ||
bool ignore; | ||
}; | ||
|
||
class ModeInterface | ||
{ | ||
public: | ||
explicit ModeInterface(rclcpp::Node & node); | ||
RootModeStatus get_root() const; | ||
|
||
private: | ||
using OperationModeState = autoware_adapi_v1_msgs::msg::OperationModeState; | ||
using AutowareState = autoware_system_msgs::msg::AutowareState; | ||
rclcpp::Node & node_; | ||
rclcpp::Subscription<OperationModeState>::SharedPtr sub_operation_mode_state_; | ||
rclcpp::Subscription<AutowareState>::SharedPtr sub_autoware_state_; | ||
|
||
std::optional<OperationModeState> operation_mode_state_; | ||
std::optional<AutowareState> autoware_state_; | ||
}; | ||
|
||
} // namespace autoware::hazard_status_converter | ||
|
||
#endif // MODE_INTERFACE_HPP_ |