forked from tier4/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(component_interface_utils): add interface classes (tier4#899)
* feat(component_interface_utils): add interface classes Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): apply the changes of interface utils Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix(component_interface_utils): remove old comment Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix(component_interface_utils): add client log Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix(component_interface_utils): remove unimplemented message Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * docs(component_interface_utils): add design policy Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * docs(component_interface_utils): add comment Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
- Loading branch information
1 parent
37ac2ce
commit 1023803
Showing
13 changed files
with
366 additions
and
48 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
76 changes: 76 additions & 0 deletions
76
common/component_interface_utils/include/component_interface_utils/rclcpp/service_client.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,76 @@ | ||
// 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 COMPONENT_INTERFACE_UTILS__RCLCPP__SERVICE_CLIENT_HPP_ | ||
#define COMPONENT_INTERFACE_UTILS__RCLCPP__SERVICE_CLIENT_HPP_ | ||
|
||
#include <rclcpp/client.hpp> | ||
#include <rclcpp/logger.hpp> | ||
#include <rclcpp/logging.hpp> | ||
|
||
#include <utility> | ||
|
||
namespace component_interface_utils | ||
{ | ||
|
||
/// The wrapper class of rclcpp::Client for logging. | ||
template <class SpecT> | ||
class Client | ||
{ | ||
public: | ||
RCLCPP_SMART_PTR_DEFINITIONS(Client) | ||
using SpecType = SpecT; | ||
using WrapType = rclcpp::Client<typename SpecT::Service>; | ||
|
||
/// Constructor. | ||
explicit Client(typename WrapType::SharedPtr client, const rclcpp::Logger & logger) | ||
: logger_(logger) | ||
{ | ||
client_ = client; // to keep the reference count | ||
} | ||
|
||
/// Send request. | ||
typename WrapType::SharedFuture async_send_request(typename WrapType::SharedRequest request) | ||
{ | ||
const auto callback = [this](typename WrapType::SharedFuture future) {}; | ||
return this->async_send_request(request, callback); | ||
} | ||
|
||
/// Send request. | ||
template <class CallbackT> | ||
typename WrapType::SharedFuture async_send_request( | ||
typename WrapType::SharedRequest request, CallbackT && callback) | ||
{ | ||
#ifdef ROS_DISTRO_GALACTIC | ||
using rosidl_generator_traits::to_yaml; | ||
#endif | ||
|
||
const auto wrapped = [this, callback](typename WrapType::SharedFuture future) { | ||
RCLCPP_INFO_STREAM(logger_, "client exit: " << SpecT::name << "\n" << to_yaml(*future.get())); | ||
callback(future); | ||
}; | ||
|
||
RCLCPP_INFO_STREAM(logger_, "client call: " << SpecT::name << "\n" << to_yaml(*request)); | ||
return client_->async_send_request(request, wrapped); | ||
} | ||
|
||
private: | ||
RCLCPP_DISABLE_COPY(Client) | ||
typename WrapType::SharedPtr client_; | ||
rclcpp::Logger logger_; | ||
}; | ||
|
||
} // namespace component_interface_utils | ||
|
||
#endif // COMPONENT_INTERFACE_UTILS__RCLCPP__SERVICE_CLIENT_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
48 changes: 48 additions & 0 deletions
48
...on/component_interface_utils/include/component_interface_utils/rclcpp/topic_publisher.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,48 @@ | ||
// 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 COMPONENT_INTERFACE_UTILS__RCLCPP__TOPIC_PUBLISHER_HPP_ | ||
#define COMPONENT_INTERFACE_UTILS__RCLCPP__TOPIC_PUBLISHER_HPP_ | ||
|
||
#include <rclcpp/publisher.hpp> | ||
|
||
namespace component_interface_utils | ||
{ | ||
|
||
/// The wrapper class of rclcpp::Publisher. This is for future use and no functionality now. | ||
template <class SpecT> | ||
class Publisher | ||
{ | ||
public: | ||
RCLCPP_SMART_PTR_DEFINITIONS(Publisher) | ||
using SpecType = SpecT; | ||
using WrapType = rclcpp::Publisher<typename SpecT::Message>; | ||
|
||
/// Constructor. | ||
explicit Publisher(typename WrapType::SharedPtr publisher) | ||
{ | ||
publisher_ = publisher; // to keep the reference count | ||
} | ||
|
||
/// Publish a message. | ||
void publish(const typename SpecT::Message & msg) { publisher_->publish(msg); } | ||
|
||
private: | ||
RCLCPP_DISABLE_COPY(Publisher) | ||
typename WrapType::SharedPtr publisher_; | ||
}; | ||
|
||
} // namespace component_interface_utils | ||
|
||
#endif // COMPONENT_INTERFACE_UTILS__RCLCPP__TOPIC_PUBLISHER_HPP_ |
45 changes: 45 additions & 0 deletions
45
...component_interface_utils/include/component_interface_utils/rclcpp/topic_subscription.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,45 @@ | ||
// 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 COMPONENT_INTERFACE_UTILS__RCLCPP__TOPIC_SUBSCRIPTION_HPP_ | ||
#define COMPONENT_INTERFACE_UTILS__RCLCPP__TOPIC_SUBSCRIPTION_HPP_ | ||
|
||
#include <rclcpp/subscription.hpp> | ||
|
||
namespace component_interface_utils | ||
{ | ||
|
||
/// The wrapper class of rclcpp::Subscription. This is for future use and no functionality now. | ||
template <class SpecT> | ||
class Subscription | ||
{ | ||
public: | ||
RCLCPP_SMART_PTR_DEFINITIONS(Subscription) | ||
using SpecType = SpecT; | ||
using WrapType = rclcpp::Subscription<typename SpecT::Message>; | ||
|
||
/// Constructor. | ||
explicit Subscription(typename WrapType::SharedPtr subscription) | ||
{ | ||
subscription_ = subscription; // to keep the reference count | ||
} | ||
|
||
private: | ||
RCLCPP_DISABLE_COPY(Subscription) | ||
typename WrapType::SharedPtr subscription_; | ||
}; | ||
|
||
} // namespace component_interface_utils | ||
|
||
#endif // COMPONENT_INTERFACE_UTILS__RCLCPP__TOPIC_SUBSCRIPTION_HPP_ |
34 changes: 34 additions & 0 deletions
34
common/component_interface_utils/include/component_interface_utils/specs.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,34 @@ | ||
// 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 COMPONENT_INTERFACE_UTILS__SPECS_HPP_ | ||
#define COMPONENT_INTERFACE_UTILS__SPECS_HPP_ | ||
|
||
#include <rclcpp/qos.hpp> | ||
|
||
namespace component_interface_utils | ||
{ | ||
|
||
template <class SpecT> | ||
rclcpp::QoS get_qos() | ||
{ | ||
rclcpp::QoS qos(SpecT::depth); | ||
qos.reliability(SpecT::reliability); | ||
qos.durability(SpecT::durability); | ||
return qos; | ||
} | ||
|
||
} // namespace component_interface_utils | ||
|
||
#endif // COMPONENT_INTERFACE_UTILS__SPECS_HPP_ |
Oops, something went wrong.