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 3 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
22 changes: 22 additions & 0 deletions common/autoware_ad_api_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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
msg/ResponseStatus.msg
msg/ResponseStatusDetail.msg
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()
22 changes: 22 additions & 0 deletions common/autoware_ad_api_msgs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# autoware_ad_api_msgs

## InterfaceVersion

This service provides an interface version based on [Semantic Versioning](SemVer).
Unlike others, this interface must be backwards and forwards compatible across major versions.

## ResponseStatus

This status is commonly used in software to unify error handling. The field `summary` is the overall result and processing is based on it.
The field `details` is used to pass the result of the interface used internally. This is for analysis and is mainly used by developers.

## ResponseStatusDetail

This is the content of ResponseStatus. The `code` is the information for the program to process the result, and the rest are the text for the user.
The `message` is an error summary and the application first displays this to the user.
The `description` is an error detail such as solution tips and URL to the documentation. It is displayed when requested by the user.
The `component`indicates where the error occurred. which is mainly used when contacting the developer.

<!-- link -->

[semver]: https://semver.org/
2 changes: 2 additions & 0 deletions common/autoware_ad_api_msgs/msg/ResponseStatus.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
autoware_ad_api_msgs/ResponseStatusDetail summary
autoware_ad_api_msgs/ResponseStatusDetail[] details
7 changes: 7 additions & 0 deletions common/autoware_ad_api_msgs/msg/ResponseStatusDetail.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
uint32 UNKNOWN=0x0000
uint32 SUCCESS=0x1001

uint32 code
string component
string message
string description
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>
6 changes: 6 additions & 0 deletions common/autoware_ad_api_msgs/srv/InterfaceVersion.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
autoware_ad_api_msgs/ResponseStatus status
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
string version
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
uint32 major
uint32 minor
uint32 patch
kenji-miyake marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions common/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(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()
22 changes: 22 additions & 0 deletions common/interface_utils/include/interface_utils/interface_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 INTERFACE_UTILS__INTERFACE_UTILS_HPP_
#define INTERFACE_UTILS__INTERFACE_UTILS_HPP_

#include "./rclcpp/create_interface.hpp"
#include "./rclcpp/service_server.hpp"
#include "./response.hpp"

#endif // INTERFACE_UTILS__INTERFACE_UTILS_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 INTERFACE_UTILS__RCLCPP__CREATE_INTERFACE_HPP_
#define INTERFACE_UTILS__RCLCPP__CREATE_INTERFACE_HPP_

#include "./service_server.hpp"

#include <rclcpp/rclcpp.hpp>

#include <utility>

namespace 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(
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 interface_utils

#endif // 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 INTERFACE_UTILS__RCLCPP__SERVICE_SERVER_HPP_
#define INTERFACE_UTILS__RCLCPP__SERVICE_SERVER_HPP_

#include <rclcpp/rclcpp.hpp>

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

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 interface_utils

#endif // INTERFACE_UTILS__RCLCPP__SERVICE_SERVER_HPP_
35 changes: 35 additions & 0 deletions common/interface_utils/include/interface_utils/response.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 INTERFACE_UTILS__RESPONSE_HPP_
#define INTERFACE_UTILS__RESPONSE_HPP_

#include "autoware_ad_api_msgs/msg/response_status.hpp"
#include "autoware_ad_api_msgs/msg/response_status_detail.hpp"

namespace interface_utils::response
{

using ResponseStatusDetail = autoware_ad_api_msgs::msg::ResponseStatusDetail;

ResponseStatusDetail success()
{
ResponseStatusDetail status;
status.code = ResponseStatusDetail::SUCCESS;
return status;
}

} // namespace interface_utils::response

#endif // INTERFACE_UTILS__RESPONSE_HPP_
22 changes: 22 additions & 0 deletions common/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>interface_utils</name>
<version>0.0.0</version>
<description>The 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 "interface_utils/interface_utils.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;

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_
Loading