|
| 1 | +// Copyright 2025 The Autoware Contributors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "command_mode_decider_redundancy.hpp" |
| 16 | + |
| 17 | +#include <string> |
| 18 | + |
| 19 | +namespace autoware::command_mode_decider |
| 20 | +{ |
| 21 | + |
| 22 | + CommandModeDeciderRedundancy::CommandModeDeciderRedundancy(const rclcpp::NodeOptions & options) |
| 23 | +: CommandModeDeciderBase(options) |
| 24 | +{ |
| 25 | +} |
| 26 | + |
| 27 | +std::string CommandModeDeciderRedundancy::decide_command_mode() |
| 28 | +{ |
| 29 | + const auto command_mode_status = get_command_mode_status(); |
| 30 | + const auto request_mode_status = get_request_mode_status(); |
| 31 | + |
| 32 | + // Use the requested MRM if available. |
| 33 | + { |
| 34 | + const auto status = command_mode_status.get(request_mode_status.mrm); |
| 35 | + if (status.available) { |
| 36 | + return request_mode_status.mrm; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + // Use the specified operation mode if available. |
| 41 | + { |
| 42 | + const auto status = command_mode_status.get(request_mode_status.operation_mode); |
| 43 | + if (status.available) { |
| 44 | + return request_mode_status.operation_mode; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + // TODO(Takagi, Isamu): Use the available MRM according to the state transitions at the |
| 49 | + // following. |
| 50 | + // https://autowarefoundation.github.io/autoware-documentation/main/design/autoware-interfaces/ad-api/features/fail-safe/#behavior |
| 51 | + const auto comfortable_stop = "comfortable_stop"; |
| 52 | + const auto main_ecu_in_lane_stop_0_4g = "main_ecu_in_lane_stop_0_4g"; |
| 53 | + const auto main_ecu_in_lane_stop_0_6g = "main_ecu_in_lane_stop_0_6g"; |
| 54 | + const auto sub_ecu_in_lane_stop_0_4g = "sub_ecu_in_lane_stop_0_4g"; |
| 55 | + |
| 56 | + // TODO(Takagi, Isamu): check command_modes parameter |
| 57 | + if (command_mode_status.get(comfortable_stop).available /*&& use_comfortable_stop_*/) { |
| 58 | + return comfortable_stop; |
| 59 | + } |
| 60 | + if (command_mode_status.get(main_ecu_in_lane_stop_0_4g).available /*&& use_main_ecu_in_lane_stop_0_4g_*/) { |
| 61 | + return main_ecu_in_lane_stop_0_4g; |
| 62 | + } |
| 63 | + if (command_mode_status.get(main_ecu_in_lane_stop_0_6g).available /*&& use_main_ecu_in_lane_stop_0_6g_*/) { |
| 64 | + return main_ecu_in_lane_stop_0_6g; |
| 65 | + } |
| 66 | + if (command_mode_status.get(sub_ecu_in_lane_stop_0_4g).available /*&& use_sub_ecu_in_lane_stop_0_4g_*/) { |
| 67 | + return sub_ecu_in_lane_stop_0_4g; |
| 68 | + } |
| 69 | + // FIXME(TetsuKawa): How to handle the case where no MRM is available. |
| 70 | + |
| 71 | + // Use an empty string to delegate to switcher node. |
| 72 | + RCLCPP_WARN_THROTTLE( |
| 73 | + get_logger(), *get_clock(), 5000, "no mrm available: delegate to switcher node"); |
| 74 | + return std::string(); |
| 75 | +} |
| 76 | + |
| 77 | +} // namespace autoware::command_mode_decider |
| 78 | + |
| 79 | +#include <rclcpp_components/register_node_macro.hpp> |
| 80 | +RCLCPP_COMPONENTS_REGISTER_NODE(autoware::command_mode_decider::CommandModeDeciderRedundancy) |
0 commit comments