forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(default_ad_api): add fail-safe api (autowarefoundation#2295)
Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> Signed-off-by: Kotaro Yoshimoto <pythagora.yoshimoto@gmail.com>
- Loading branch information
1 parent
4916e60
commit 2e14347
Showing
6 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
common/autoware_ad_api_specs/include/autoware_ad_api_specs/fail_safe.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,36 @@ | ||
// Copyright 2022 TIER IV, Inc. | ||
// | ||
// 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 AUTOWARE_AD_API_SPECS__FAIL_SAFE_HPP_ | ||
#define AUTOWARE_AD_API_SPECS__FAIL_SAFE_HPP_ | ||
|
||
#include <rclcpp/qos.hpp> | ||
|
||
#include <autoware_adapi_v1_msgs/msg/mrm_state.hpp> | ||
|
||
namespace autoware_ad_api::fail_safe | ||
{ | ||
|
||
struct MrmState | ||
{ | ||
using Message = autoware_adapi_v1_msgs::msg::MrmState; | ||
static constexpr char name[] = "/api/fail_safe/mrm_state"; | ||
static constexpr size_t depth = 1; | ||
static constexpr auto reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE; | ||
static constexpr auto durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL; | ||
}; | ||
|
||
} // namespace autoware_ad_api::fail_safe | ||
|
||
#endif // AUTOWARE_AD_API_SPECS__FAIL_SAFE_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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2022 TIER IV, Inc. | ||
// | ||
// 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 "fail_safe.hpp" | ||
|
||
namespace default_ad_api | ||
{ | ||
|
||
FailSafeNode::FailSafeNode(const rclcpp::NodeOptions & options) : Node("fail_safe", options) | ||
{ | ||
const auto adaptor = component_interface_utils::NodeAdaptor(this); | ||
adaptor.init_pub(pub_mrm_state_); | ||
adaptor.init_sub(sub_mrm_state_, this, &FailSafeNode::on_state); | ||
|
||
prev_state_.state = MrmState::UNKNOWN; | ||
} | ||
|
||
void FailSafeNode::on_state(const MrmState::ConstSharedPtr msg) | ||
{ | ||
prev_state_.stamp = msg->stamp; | ||
if (prev_state_ != *msg) { | ||
prev_state_ = *msg; | ||
pub_mrm_state_->publish(*msg); | ||
} | ||
} | ||
|
||
} // namespace default_ad_api | ||
|
||
#include <rclcpp_components/register_node_macro.hpp> | ||
RCLCPP_COMPONENTS_REGISTER_NODE(default_ad_api::FailSafeNode) |
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,44 @@ | ||
// Copyright 2022 TIER IV, Inc. | ||
// | ||
// 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 FAIL_SAFE_HPP_ | ||
#define FAIL_SAFE_HPP_ | ||
|
||
#include <autoware_ad_api_specs/fail_safe.hpp> | ||
#include <component_interface_specs/system.hpp> | ||
#include <component_interface_utils/rclcpp.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
// This file should be included after messages. | ||
#include "utils/types.hpp" | ||
|
||
namespace default_ad_api | ||
{ | ||
|
||
class FailSafeNode : public rclcpp::Node | ||
{ | ||
public: | ||
explicit FailSafeNode(const rclcpp::NodeOptions & options); | ||
|
||
private: | ||
using MrmState = autoware_ad_api::fail_safe::MrmState::Message; | ||
Pub<autoware_ad_api::fail_safe::MrmState> pub_mrm_state_; | ||
Sub<system_interface::MrmState> sub_mrm_state_; | ||
MrmState prev_state_; | ||
void on_state(const MrmState::ConstSharedPtr msg); | ||
}; | ||
|
||
} // namespace default_ad_api | ||
|
||
#endif // FAIL_SAFE_HPP_ |