forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(redundancy_switcher_interface): add reset_converter
Signed-off-by: TetsuKawa <[email protected]>
- Loading branch information
Showing
10 changed files
with
215 additions
and
17 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
14 changes: 9 additions & 5 deletions
14
system/redundancy_switcher_interface/config/redundancy_switcher_interface.param.yaml
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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
/**: | ||
ros__parameters: | ||
availability_dest_ip: "127.0.0.1" | ||
availability_dest_port: "9000" | ||
availability_dest_port: "59000" | ||
mrm_state_dest_ip: "127.0.0.1" | ||
mrm_state_dest_port: "9001" | ||
mrm_state_dest_port: "59001" | ||
mrm_request_src_ip: "127.0.0.1" | ||
mrm_request_src_port: "9002" | ||
mrm_request_src_port: "59002" | ||
election_communication_src_ip: "127.0.0.1" | ||
election_communication_src_port: "9003" | ||
election_communication_src_port: "59003" | ||
election_status_src_ip: "127.0.0.1" | ||
election_status_src_port: "9004" | ||
election_status_src_port: "59004" | ||
reset_request_dest_ip: "127.0.0.1" | ||
reset_request_dest_port: "59005" | ||
reset_response_src_ip: "127.0.0.1" | ||
reset_response_src_port: "59006" |
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
84 changes: 84 additions & 0 deletions
84
system/redundancy_switcher_interface/src/common/converter/reset_converter.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,84 @@ | ||
// Copyright 2024 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 "reset_converter.hpp" | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
|
||
#include <autoware_adapi_v1_msgs/msg/response_status.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace redundancy_switcher_interface | ||
{ | ||
|
||
ResetConverter::ResetConverter(rclcpp::Node * node) : node_(node) | ||
{ | ||
} | ||
|
||
void ResetConverter::setUdpSender(const std::string & dest_ip, const std::string & dest_port) | ||
{ | ||
udp_reset_request_sender_ = std::make_unique<UdpSender<ResetRequest>>(dest_ip, dest_port); | ||
} | ||
|
||
void ResetConverter::setUdpReceiver(const std::string & src_ip, const std::string & src_port) | ||
{ | ||
udp_reset_response_receiver_ = std::make_unique<UdpReceiver<ResetResponse>>(src_ip, src_port, false); | ||
} | ||
|
||
void ResetConverter::setService() | ||
{ | ||
srv_reset_ = node_->create_service<autoware_adapi_v1_msgs::srv::RedundancySwitcherReset>( | ||
"~/service/reset", std::bind(&ResetConverter::onResetRequest, this, std::placeholders::_1, std::placeholders::_2)); | ||
} | ||
|
||
void ResetConverter::onResetRequest( | ||
const autoware_adapi_v1_msgs::srv::RedundancySwitcherReset::Request::SharedPtr, | ||
const autoware_adapi_v1_msgs::srv::RedundancySwitcherReset::Response::SharedPtr response) | ||
{ | ||
auto async_task = std::async(std::launch::async, [this, response]() { | ||
ResetRequest reset_request; | ||
reset_request.request = true; | ||
udp_reset_request_sender_->send(reset_request); | ||
RCLCPP_INFO(node_->get_logger(), "Reset request sent."); | ||
|
||
ResetResponse udp_response; | ||
try { | ||
bool result = udp_reset_response_receiver_->receive(udp_response, 30);; | ||
if (!result) { | ||
response->status.success = false; | ||
response->status.code = autoware_adapi_v1_msgs::msg::ResponseStatus::SERVICE_TIMEOUT; | ||
response->status.message = "Timed out waiting for response."; | ||
RCLCPP_WARN(node_->get_logger(), "Timed out waiting for response."); | ||
} else if (!udp_response.response) { | ||
response->status.success = false; | ||
response->status.code = autoware_adapi_v1_msgs::msg::ResponseStatus::NO_EFFECT; | ||
response->status.message = "Failed to reset in redundancy switcher."; | ||
RCLCPP_WARN(node_->get_logger(), "Failed to reset in redundancy switcher."); | ||
} else { | ||
response->status.success = true; | ||
response->status.message = "Reset successfully."; | ||
RCLCPP_INFO(node_->get_logger(), "Reset successfully."); | ||
} | ||
} catch (const std::exception &e) { | ||
response->status.success = false; | ||
response->status.code = autoware_adapi_v1_msgs::msg::ResponseStatus::TRANSFORM_ERROR; | ||
response->status.message = "Failed to receive UDP response."; | ||
RCLCPP_WARN(node_->get_logger(), "Failed to receive UDP response: %s", e.what()); | ||
} | ||
}); | ||
} | ||
|
||
} // namespace redundancy_switcher_interface |
63 changes: 63 additions & 0 deletions
63
system/redundancy_switcher_interface/src/common/converter/reset_converter.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,63 @@ | ||
// Copyright 2024 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 RESET__CONVERTER__RESET_CONVERTER_HPP_ | ||
#define RESET__CONVERTER__RESET_CONVERTER_HPP_ | ||
|
||
#include "udp_sender.hpp" | ||
#include "udp_receiver.hpp" | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <autoware_adapi_v1_msgs/srv/redundancy_switcher_reset.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
namespace redundancy_switcher_interface | ||
{ | ||
|
||
struct ResetRequest | ||
{ | ||
bool request; | ||
}; | ||
|
||
struct ResetResponse | ||
{ | ||
bool response; | ||
}; | ||
|
||
class ResetConverter | ||
{ | ||
public: | ||
explicit ResetConverter(rclcpp::Node * node); | ||
|
||
void setUdpSender(const std::string & dest_ip, const std::string & dest_port); | ||
void setUdpReceiver(const std::string & src_ip, const std::string & src_port); | ||
void setService(); | ||
|
||
private: | ||
rclcpp::Node * node_; | ||
std::unique_ptr<UdpSender<ResetRequest>> udp_reset_request_sender_; | ||
std::unique_ptr<UdpReceiver<ResetResponse>> udp_reset_response_receiver_; | ||
rclcpp::Service<autoware_adapi_v1_msgs::srv::RedundancySwitcherReset>::SharedPtr srv_reset_; | ||
|
||
void onResetRequest( | ||
const autoware_adapi_v1_msgs::srv::RedundancySwitcherReset::Request::SharedPtr, | ||
const autoware_adapi_v1_msgs::srv::RedundancySwitcherReset::Response::SharedPtr response); | ||
}; | ||
|
||
} // namespace redundancy_switcher_interface | ||
|
||
#endif // RESET__CONVERTER__RESET_CONVERTER_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