Skip to content

Commit

Permalink
feat(autoware_ad_api_specs): modify interface version api to use spec…
Browse files Browse the repository at this point in the history
… package (#1677)

Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
  • Loading branch information
isamu-takagi authored Aug 24, 2022
1 parent 7b94ead commit d434e87
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 29 deletions.
7 changes: 7 additions & 0 deletions common/autoware_ad_api_specs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.14)
project(autoware_ad_api_specs)

find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_package()
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef DEFAULT_AD_API__SPECS__INTERFACE__VERSION_HPP_
#define DEFAULT_AD_API__SPECS__INTERFACE__VERSION_HPP_
#ifndef AUTOWARE_AD_API_SPECS__INTERFACE_HPP_
#define AUTOWARE_AD_API_SPECS__INTERFACE_HPP_

#include "autoware_ad_api_msgs/srv/interface_version.hpp"
#include <autoware_ad_api_msgs/srv/interface_version.hpp>

namespace ad_api::interface::version
namespace autoware_ad_api::interface
{

struct T
struct Version
{
using Service = autoware_ad_api_msgs::srv::InterfaceVersion;
static constexpr char name[] = "/api/interface/version";
};

} // namespace ad_api::interface::version
} // namespace autoware_ad_api::interface

#endif // DEFAULT_AD_API__SPECS__INTERFACE__VERSION_HPP_
#endif // AUTOWARE_AD_API_SPECS__INTERFACE_HPP_
20 changes: 20 additions & 0 deletions common/autoware_ad_api_specs/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>autoware_ad_api_specs</name>
<version>0.0.0</version>
<description>The autoware_ad_api_specs package</description>
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>

<build_depend>autoware_cmake</build_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
1 change: 1 addition & 0 deletions system/default_ad_api/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<build_depend>autoware_cmake</build_depend>

<depend>autoware_ad_api_msgs</depend>
<depend>autoware_ad_api_specs</depend>
<depend>component_interface_utils</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
Expand Down
14 changes: 6 additions & 8 deletions system/default_ad_api/src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ namespace default_ad_api

InterfaceNode::InterfaceNode(const rclcpp::NodeOptions & options) : Node("interface", options)
{
using InterfaceVersion = autoware_ad_api_msgs::srv::InterfaceVersion;

const auto on_interface_version = [](SERVICE_ARG_NO_REQ(InterfaceVersion)) {
response->major = 0;
response->minor = 1;
response->patch = 0;
const auto on_interface_version = [](auto, auto res) {
res->major = 0;
res->minor = 1;
res->patch = 0;
};

const auto node = component_interface_utils::NodeAdaptor(this);
node.init_srv(srv_, on_interface_version);
const auto adaptor = component_interface_utils::NodeAdaptor(this);
adaptor.init_srv(srv_, on_interface_version);
}

} // namespace default_ad_api
Expand Down
9 changes: 5 additions & 4 deletions system/default_ad_api/src/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#ifndef INTERFACE_HPP_
#define INTERFACE_HPP_

#include "default_ad_api/specs/interface/version.hpp"
#include "utils/types.hpp"

#include <autoware_ad_api_specs/interface.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
{

Expand All @@ -30,7 +31,7 @@ class InterfaceNode : public rclcpp::Node
explicit InterfaceNode(const rclcpp::NodeOptions & options);

private:
Service<ad_api::interface::version::T>::SharedPtr srv_;
Srv<autoware_ad_api::interface::Version> srv_;
};

} // namespace default_ad_api
Expand Down
14 changes: 4 additions & 10 deletions system/default_ad_api/src/utils/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,17 @@

#include <component_interface_utils/rclcpp.hpp>

#define MESSAGE_ARG(Type) const Type::ConstSharedPtr message
#define SERVICE_ARG(Type) \
const Type::Request::SharedPtr request, const Type::Response::SharedPtr response
#define SERVICE_ARG_NO_REQ(Type) \
const Type::Request::SharedPtr, const Type::Response::SharedPtr response

namespace default_ad_api
{

template <class T>
using Publisher = component_interface_utils::Publisher<T>;
using Pub = typename component_interface_utils::Publisher<T>::SharedPtr;
template <class T>
using Subscription = component_interface_utils::Subscription<T>;
using Sub = typename component_interface_utils::Subscription<T>::SharedPtr;
template <class T>
using Client = component_interface_utils::Client<T>;
using Cli = typename component_interface_utils::Client<T>::SharedPtr;
template <class T>
using Service = component_interface_utils::Service<T>;
using Srv = typename component_interface_utils::Service<T>::SharedPtr;

} // namespace default_ad_api

Expand Down

0 comments on commit d434e87

Please sign in to comment.