forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vehicle_cmd_gate): add moderate_stop_interface to make vehicle s…
…top (autowarefoundation#3790) * feat(vehicle_cmd_gate): add moderate_stop_interface to make vehicle stop Signed-off-by: Berkay Karaman <[email protected]> Signed-off-by: Berkay Karaman <[email protected]> * move filter place Signed-off-by: Berkay Karaman <[email protected]> --------- Signed-off-by: Berkay Karaman <[email protected]>
- Loading branch information
Showing
8 changed files
with
162 additions
and
0 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
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,69 @@ | ||
// Copyright 2023 LeoDrive, A.Ş. | ||
// | ||
// 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 "moderate_stop_interface.hpp" | ||
|
||
namespace vehicle_cmd_gate | ||
{ | ||
|
||
ModerateStopInterface::ModerateStopInterface(rclcpp::Node * node) : node_(node) | ||
{ | ||
const auto adaptor = component_interface_utils::NodeAdaptor(node); | ||
adaptor.init_srv(srv_set_stop_, this, &ModerateStopInterface::on_stop_request); | ||
adaptor.init_pub(pub_is_stopped_); | ||
|
||
stop_state_.data = false; | ||
stop_state_.requested_sources.clear(); | ||
publish(); | ||
} | ||
|
||
bool ModerateStopInterface::is_stop_requested() const | ||
{ | ||
return stop_state_.data; | ||
} | ||
|
||
void ModerateStopInterface::publish() | ||
{ | ||
if (prev_stop_map_ != stop_map_) { | ||
pub_is_stopped_->publish(stop_state_); | ||
prev_stop_map_ = stop_map_; | ||
} | ||
} | ||
|
||
void ModerateStopInterface::on_stop_request( | ||
const SetStop::Service::Request::SharedPtr req, const SetStop::Service::Response::SharedPtr res) | ||
{ | ||
stop_map_[req->request_source] = req->stop; | ||
update_stop_state(); | ||
res->status.success = true; | ||
} | ||
|
||
void ModerateStopInterface::update_stop_state() | ||
{ | ||
stop_state_.stamp = node_->now(); | ||
stop_state_.requested_sources.clear(); | ||
stop_state_.data = false; | ||
|
||
if (stop_map_.empty()) { | ||
return; | ||
} | ||
for (auto & itr : stop_map_) { | ||
if (itr.second) { | ||
stop_state_.data = true; | ||
stop_state_.requested_sources.push_back(itr.first); | ||
} | ||
} | ||
} | ||
|
||
} // namespace vehicle_cmd_gate |
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,60 @@ | ||
// Copyright 2023 LeoDrive, A.Ş. | ||
// | ||
// 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 MODERATE_STOP_INTERFACE_HPP_ | ||
#define MODERATE_STOP_INTERFACE_HPP_ | ||
|
||
#include <component_interface_specs/control.hpp> | ||
#include <component_interface_utils/rclcpp.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <autoware_auto_control_msgs/msg/ackermann_control_command.hpp> | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace vehicle_cmd_gate | ||
{ | ||
|
||
class ModerateStopInterface | ||
{ | ||
private: | ||
using SetStop = control_interface::SetStop; | ||
using IsStopped = control_interface::IsStopped; | ||
using IsStartRequested = control_interface::IsStartRequested; | ||
|
||
public: | ||
explicit ModerateStopInterface(rclcpp::Node * node); | ||
bool is_stop_requested() const; | ||
void publish(); | ||
|
||
private: | ||
IsStopped::Message stop_state_; | ||
std::unordered_map<std::string, bool> stop_map_; | ||
std::optional<std::unordered_map<std::string, bool>> prev_stop_map_; | ||
|
||
rclcpp::Node * node_; | ||
component_interface_utils::Service<SetStop>::SharedPtr srv_set_stop_; | ||
component_interface_utils::Publisher<IsStopped>::SharedPtr pub_is_stopped_; | ||
|
||
void on_stop_request( | ||
const SetStop::Service::Request::SharedPtr req, | ||
const SetStop::Service::Response::SharedPtr res); | ||
|
||
void update_stop_state(); | ||
}; | ||
|
||
} // namespace vehicle_cmd_gate | ||
|
||
#endif // MODERATE_STOP_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
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