-
Notifications
You must be signed in to change notification settings - Fork 667
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 interface version (#704)
* feat(default_ad_api): add interface version Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): add http server Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): add message readme Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): modify message readme Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): fix message type Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): fix message type Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): remove unused message Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(component_interface_utils): use full path Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(component_interface_utils): rename package Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(autoware_ad_api_msgs): remove unused message Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(component_interface_utils): add readme and comments Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * feat(default_ad_api): fix api name Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * Update common/autoware_ad_api_msgs/README.md Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> * add test Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix server name Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * Add comment Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix typo * rename version api * Update system/default_ad_api/package.xml Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> * Update common/component_interface_utils/include/component_interface_utils/rclcpp/create_interface.hpp Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> * Update system/default_ad_api/launch/default_ad_api.launch.py Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com> * Fix for renaming web server script * Fix test script for readability * Fix test script for readability * Add comment Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com>
- Loading branch information
1 parent
57e6774
commit 065be60
Showing
19 changed files
with
654 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(autoware_ad_api_msgs) | ||
|
||
find_package(ament_cmake_auto REQUIRED) | ||
ament_auto_find_build_dependencies() | ||
|
||
rosidl_generate_interfaces(${PROJECT_NAME} | ||
srv/InterfaceVersion.srv | ||
DEPENDENCIES | ||
builtin_interfaces | ||
std_msgs | ||
geometry_msgs | ||
) | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
ament_auto_package() |
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,17 @@ | ||
# autoware_ad_api_msgs | ||
|
||
## InterfaceVersion | ||
|
||
This API provides the interface version of the set of AD APIs. | ||
It follows [Semantic Versioning][semver] in order to provide an intuitive understanding of the changes between versions. | ||
|
||
### Use cases | ||
|
||
Considering the product life cycle, there will be multiple vehicles that use different versions of the AD API due to changes in requirements or some improvements. | ||
For example, a vehicle uses `v1` for stability and another vehicle uses `v2` for more functionality. | ||
|
||
In that situation, the AD API users such as developers of a Web service have to switch the application behavior based on the version that each vehicle uses. | ||
|
||
<!-- link --> | ||
|
||
[semver]: https://semver.org/ |
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,29 @@ | ||
<?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_msgs</name> | ||
<version>0.0.0</version> | ||
<description>The autoware_ad_api_msgs package</description> | ||
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<buildtool_depend>ament_cmake_auto</buildtool_depend> | ||
|
||
<depend>geometry_msgs</depend> | ||
<depend>std_msgs</depend> | ||
|
||
<build_depend>builtin_interfaces</build_depend> | ||
<build_depend>rosidl_default_generators</build_depend> | ||
|
||
<exec_depend>builtin_interfaces</exec_depend> | ||
<exec_depend>rosidl_default_runtime</exec_depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>ament_lint_common</test_depend> | ||
|
||
<member_of_group>rosidl_interface_packages</member_of_group> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
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,4 @@ | ||
--- | ||
uint16 major | ||
uint16 minor | ||
uint16 patch |
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,22 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(component_interface_utils) | ||
|
||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
endif() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic -Werror) | ||
endif() | ||
|
||
find_package(ament_cmake_auto REQUIRED) | ||
ament_auto_find_build_dependencies() | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
ament_auto_package() |
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,26 @@ | ||
# component_interface_utils | ||
|
||
## Features | ||
|
||
This is a utility package that provides the following features: | ||
|
||
- Logging for service and client | ||
|
||
## Usage | ||
|
||
1. This package requires interface information in this format. | ||
|
||
```cpp | ||
struct SampleService | ||
{ | ||
using Service = sample_msgs::srv::ServiceType; | ||
static constexpr char name[] = "/sample/service"; | ||
}; | ||
``` | ||
2. Create a wrapper using the above definition as follows. | ||
```cpp | ||
component_interface_utils::Service<SampleService>::SharedPtr srv_; | ||
srv_ = component_interface_utils::create_service<SampleService>(node, ...); | ||
``` |
21 changes: 21 additions & 0 deletions
21
common/component_interface_utils/include/component_interface_utils/rclcpp.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,21 @@ | ||
// 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_HPP_ | ||
#define COMPONENT_INTERFACE_UTILS__RCLCPP_HPP_ | ||
|
||
#include <component_interface_utils/rclcpp/create_interface.hpp> | ||
#include <component_interface_utils/rclcpp/service_server.hpp> | ||
|
||
#endif // COMPONENT_INTERFACE_UTILS__RCLCPP_HPP_ |
61 changes: 61 additions & 0 deletions
61
...n/component_interface_utils/include/component_interface_utils/rclcpp/create_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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__CREATE_INTERFACE_HPP_ | ||
#define COMPONENT_INTERFACE_UTILS__RCLCPP__CREATE_INTERFACE_HPP_ | ||
|
||
#include <component_interface_utils/rclcpp/service_server.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
#include <utility> | ||
|
||
namespace component_interface_utils | ||
{ | ||
|
||
/// Create a service wrapper for logging. This is a private implementation. | ||
template <class SpecT, class NodeT, class CallbackT> | ||
typename Service<SpecT>::SharedPtr create_service_impl( | ||
NodeT * node, CallbackT && callback, rclcpp::CallbackGroup::SharedPtr group = nullptr) | ||
{ | ||
// Use a node pointer because shared_from_this cannot be used in constructor. | ||
// This function is a wrapper for the following. | ||
// https://github.com/ros2/rclcpp/blob/48068130edbb43cdd61076dc1851672ff1a80408/rclcpp/include/rclcpp/node.hpp#L267-L281 | ||
auto wrapped = Service<SpecT>::wrap(callback, node->get_logger()); | ||
auto service = node->template create_service<typename SpecT::Service>( | ||
SpecT::name, wrapped, rmw_qos_profile_services_default, group); | ||
return Service<SpecT>::make_shared(service); | ||
} | ||
|
||
/// Create a service wrapper for logging. This is for lambda or bound function. | ||
template <class SpecT, class NodeT, class CallbackT> | ||
typename Service<SpecT>::SharedPtr create_service( | ||
NodeT * node, CallbackT && callback, rclcpp::CallbackGroup::SharedPtr group = nullptr) | ||
{ | ||
return create_service_impl<SpecT>(node, std::forward<CallbackT>(callback), group); | ||
} | ||
|
||
/// Create a service wrapper for logging. This is for member function of node. | ||
template <class SpecT, class NodeT> | ||
typename Service<SpecT>::SharedPtr create_service( | ||
NodeT * node, typename Service<SpecT>::template CallbackType<NodeT> callback, | ||
rclcpp::CallbackGroup::SharedPtr group = nullptr) | ||
{ | ||
using std::placeholders::_1; | ||
using std::placeholders::_2; | ||
return create_service_impl<SpecT>(node, std::bind(callback, node, _1, _2), group); | ||
} | ||
|
||
} // namespace component_interface_utils | ||
|
||
#endif // COMPONENT_INTERFACE_UTILS__RCLCPP__CREATE_INTERFACE_HPP_ |
62 changes: 62 additions & 0 deletions
62
common/component_interface_utils/include/component_interface_utils/rclcpp/service_server.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,62 @@ | ||
// 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_SERVER_HPP_ | ||
#define COMPONENT_INTERFACE_UTILS__RCLCPP__SERVICE_SERVER_HPP_ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
namespace component_interface_utils | ||
{ | ||
|
||
/// The wrapper class of rclcpp::Service for logging. | ||
template <class SpecT> | ||
class Service | ||
{ | ||
public: | ||
RCLCPP_SMART_PTR_DEFINITIONS(Service) | ||
|
||
template <class NodeT> | ||
using CallbackType = void (NodeT::*)( | ||
typename SpecT::Service::Request::SharedPtr, typename SpecT::Service::Response::SharedPtr); | ||
|
||
/// Constructor. | ||
explicit Service(typename rclcpp::Service<typename SpecT::Service>::SharedPtr service) | ||
{ | ||
service_ = service; // to keep the reference count | ||
} | ||
|
||
/// Create a service callback with logging added. | ||
template <class CallbackT> | ||
static auto wrap(CallbackT && callback, const rclcpp::Logger & logger) | ||
{ | ||
auto wrapped = [logger, callback]( | ||
typename SpecT::Service::Request::SharedPtr request, | ||
typename SpecT::Service::Response::SharedPtr response) { | ||
using rosidl_generator_traits::to_yaml; | ||
RCLCPP_INFO_STREAM(logger, "service call: " << SpecT::name << "\n" << to_yaml(*request)); | ||
callback(request, response); | ||
RCLCPP_INFO_STREAM(logger, "service exit: " << SpecT::name << "\n" << to_yaml(*response)); | ||
}; | ||
return wrapped; | ||
} | ||
|
||
private: | ||
RCLCPP_DISABLE_COPY(Service) | ||
typename rclcpp::Service<typename SpecT::Service>::SharedPtr service_; | ||
}; | ||
|
||
} // namespace component_interface_utils | ||
|
||
#endif // COMPONENT_INTERFACE_UTILS__RCLCPP__SERVICE_SERVER_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,22 @@ | ||
<?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>component_interface_utils</name> | ||
<version>0.0.0</version> | ||
<description>The component_interface_utils package</description> | ||
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<buildtool_depend>ament_cmake_auto</buildtool_depend> | ||
|
||
<depend>autoware_ad_api_msgs</depend> | ||
<depend>rclcpp</depend> | ||
<depend>rclcpp_components</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>autoware_lint_common</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
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,35 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(default_ad_api) | ||
|
||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
endif() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic -Werror) | ||
endif() | ||
|
||
find_package(ament_cmake_auto REQUIRED) | ||
ament_auto_find_build_dependencies() | ||
|
||
ament_auto_add_library(${PROJECT_NAME} SHARED | ||
src/interface_version.cpp | ||
) | ||
|
||
rclcpp_components_register_nodes(${PROJECT_NAME} "default_ad_api::InterfaceVersionNode") | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
ament_lint_auto_find_test_dependencies() | ||
find_package(launch_testing_ament_cmake) | ||
add_launch_test(test/main.test.py) | ||
endif() | ||
|
||
install( | ||
PROGRAMS script/web_server.py | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
ament_auto_package(INSTALL_TO_SHARE launch test) |
42 changes: 42 additions & 0 deletions
42
system/default_ad_api/include/default_ad_api/nodes/interface_version.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,42 @@ | ||
// 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 DEFAULT_AD_API__NODES__INTERFACE_VERSION_HPP_ | ||
#define DEFAULT_AD_API__NODES__INTERFACE_VERSION_HPP_ | ||
|
||
#include "default_ad_api/specs/interface/version.hpp" | ||
|
||
#include <component_interface_utils/rclcpp.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
|
||
namespace default_ad_api | ||
{ | ||
|
||
class InterfaceVersionNode : public rclcpp::Node | ||
{ | ||
public: | ||
explicit InterfaceVersionNode(const rclcpp::NodeOptions & options); | ||
|
||
private: | ||
using InterfaceVersion = autoware_ad_api_msgs::srv::InterfaceVersion; | ||
|
||
component_interface_utils::Service<ad_api::interface::version::T>::SharedPtr srv_; | ||
void onInterfaceVersion( | ||
const InterfaceVersion::Request::SharedPtr request, | ||
const InterfaceVersion::Response::SharedPtr response); | ||
}; | ||
|
||
} // namespace default_ad_api | ||
|
||
#endif // DEFAULT_AD_API__NODES__INTERFACE_VERSION_HPP_ |
Oops, something went wrong.