Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(default_ad_api): add interface version #704

Merged
merged 25 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b9916cf
feat(default_ad_api): add interface version
isamu-takagi Apr 13, 2022
013ab58
feat(default_ad_api): add http server
isamu-takagi Apr 18, 2022
c7ab03d
feat(default_ad_api): add message readme
isamu-takagi Apr 20, 2022
c9eee0b
feat(default_ad_api): modify message readme
isamu-takagi Apr 20, 2022
7f1b1e2
feat(default_ad_api): fix message type
isamu-takagi Apr 20, 2022
a898588
feat(default_ad_api): fix message type
isamu-takagi Apr 20, 2022
fe37b6b
feat(default_ad_api): remove unused message
isamu-takagi Apr 20, 2022
c9af6c4
feat(component_interface_utils): use full path
isamu-takagi Apr 20, 2022
f127980
feat(component_interface_utils): rename package
isamu-takagi Apr 20, 2022
9919317
feat(autoware_ad_api_msgs): remove unused message
isamu-takagi Apr 20, 2022
99264a4
feat(component_interface_utils): add readme and comments
isamu-takagi Apr 21, 2022
534ac3c
feat(default_ad_api): fix api name
isamu-takagi Apr 21, 2022
8469a78
Update common/autoware_ad_api_msgs/README.md
isamu-takagi Apr 25, 2022
67a63b4
add test
isamu-takagi Apr 25, 2022
ef29b63
fix server name
isamu-takagi Apr 25, 2022
f65eecf
Add comment
isamu-takagi Apr 25, 2022
b992aa9
fix typo
isamu-takagi Apr 25, 2022
e9f1d50
rename version api
isamu-takagi Apr 26, 2022
d3b66d7
Update system/default_ad_api/package.xml
isamu-takagi Apr 26, 2022
295ab74
Update common/component_interface_utils/include/component_interface_u…
isamu-takagi Apr 26, 2022
f76e156
Update system/default_ad_api/launch/default_ad_api.launch.py
isamu-takagi Apr 26, 2022
0253a00
Fix for renaming web server script
isamu-takagi Apr 26, 2022
9724eb2
Fix test script for readability
isamu-takagi Apr 26, 2022
31e270a
Fix test script for readability
isamu-takagi Apr 26, 2022
58e93bb
Add comment
isamu-takagi Apr 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions common/autoware_ad_api_msgs/CMakeLists.txt
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()
12 changes: 12 additions & 0 deletions common/autoware_ad_api_msgs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# autoware_ad_api_msgs

## InterfaceVersion

The interface should be stable, but it also needs to be improved on demand. This requires version control.
The application needs to check compatibility with the interface version and to switch the processing depending on that.
For that, this service provides an interface version based on [Semantic Versioning][semver].
Unlike others, this interface should be especially stable because it needs to be backwards and forwards compatible across major versions.
isamu-takagi marked this conversation as resolved.
Show resolved Hide resolved

<!-- link -->

[semver]: https://semver.org/
29 changes: 29 additions & 0 deletions common/autoware_ad_api_msgs/package.xml
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>
4 changes: 4 additions & 0 deletions common/autoware_ad_api_msgs/srv/InterfaceVersion.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
uint16 major
uint16 minor
uint16 patch
22 changes: 22 additions & 0 deletions common/component_interface_utils/CMakeLists.txt
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()
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_
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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
{

// Use a node pointer because shared_from_this cannot be used in constructor.
template <class SpecT, class NodeT, class CallbackT>
typename Service<SpecT>::SharedPtr create_service_impl(
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
NodeT * node, CallbackT && callback, rclcpp::CallbackGroup::SharedPtr group = nullptr)
{
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);
}

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);
}

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_
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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
{

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);

explicit Service(typename rclcpp::Service<typename SpecT::Service>::SharedPtr service)
{
service_ = service;
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
}

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;
Copy link
Contributor

@kenji-miyake kenji-miyake Apr 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must switch the usage of to_yaml in Humble.

Related: https://github.com/autowarefoundation/autoware.universe/pull/762/files#r855682896

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, so from Humble, I think just write to_yaml then ADL works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I guess so. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if rosidl_generator_traits::to_yaml still exists, there is no need to fix the code.
If not, I think we have to remove it in Humble.

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));
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
};
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_
22 changes: 22 additions & 0 deletions common/component_interface_utils/package.xml
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>
33 changes: 33 additions & 0 deletions system/default_ad_api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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()
endif()

install(
PROGRAMS script/server.py
DESTINATION lib/${PROJECT_NAME}
)

ament_auto_package()
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_
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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__SPECS__INTERFACE__VERSION_HPP_
#define DEFAULT_AD_API__SPECS__INTERFACE__VERSION_HPP_

#include "autoware_ad_api_msgs/srv/interface_version.hpp"

namespace ad_api::interface::version
{

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

} // namespace ad_api::interface::version

#endif // DEFAULT_AD_API__SPECS__INTERFACE__VERSION_HPP_
25 changes: 25 additions & 0 deletions system/default_ad_api/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>default_ad_api</name>
<version>0.0.0</version>
isamu-takagi marked this conversation as resolved.
Show resolved Hide resolved
<description>The default_ad_api 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>component_interface_utils</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>

<exec_depend>python3-flask</exec_depend>

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

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading