Skip to content

Commit

Permalink
feat(autoware_node): add AutowareNode base class
Browse files Browse the repository at this point in the history
Signed-off-by: M. Fatih Cırıt <mfc@leodrive.ai>
  • Loading branch information
xmfcx committed Jan 12, 2023
1 parent 6bafedf commit df7e483
Show file tree
Hide file tree
Showing 30 changed files with 661 additions and 0 deletions.
20 changes: 20 additions & 0 deletions common/autoware_control_center/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.8)
project(autoware_control_center)

find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

autoware_package()

ament_auto_add_executable(${PROJECT_NAME} src/autoware_control_center_node.cpp
src/autoware_control_center.cpp)
#target_link_libraries(${PROJECT_NAME})

#if (BUILD_TESTING)
# find_package(ament_lint_auto REQUIRED)
# ament_lint_auto_find_test_dependencies()
# ament_add_ros_isolated_gtest(test_autoware_control_center test/test_autoware_control_center.cpp)
# target_link_libraries(test_autoware_control_center ${PROJECT_NAME})
#endif ()

ament_auto_package()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
//
// 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 AUTOWARE_CONTROL_CENTER__AUTOWARE_CONTROL_CENTER_HPP_
#define AUTOWARE_CONTROL_CENTER__AUTOWARE_CONTROL_CENTER_HPP_

#include "autoware_control_center/visibility_control.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"

#include "autoware_control_center_msgs/msg/autoware_control_center_json.hpp"

namespace autoware_control_center
{

class AutowareControlCenter : public rclcpp_lifecycle::LifecycleNode
{
public:
AutowareControlCenter(const rclcpp::NodeOptions & options);

private:
using AutowareControlCenterJson = autoware_control_center_msgs::msg::AutowareControlCenterJson;
rclcpp::Subscription<AutowareControlCenterJson>::SharedPtr sub_global_;

void callback_acc_json_global(const AutowareControlCenterJson::ConstSharedPtr & msg);
};

} // namespace autoware_control_center

#endif // AUTOWARE_CONTROL_CENTER__AUTOWARE_CONTROL_CENTER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
//
// 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 AUTOWARE_CONTROL_CENTER__VISIBILITY_CONTROL_HPP_
#define AUTOWARE_CONTROL_CENTER__VISIBILITY_CONTROL_HPP_

#include "rcutils/visibility_control_macros.h"

#ifdef AUTOWARE_CONTROL_CENTER_BUILDING_DLL
#define AUTOWARE_CONTROL_CENTER_PUBLIC RCUTILS_EXPORT
#else
#define AUTOWARE_CONTROL_CENTER_PUBLIC RCUTILS_IMPORT
#endif // !AUTOWARE_CONTROL_CENTER_BUILDING_DLL
#define AUTOWARE_CONTROL_CENTER_LOCAL RCUTILS_LOCAL

#endif // AUTOWARE_CONTROL_CENTER__VISIBILITY_CONTROL_HPP_
29 changes: 29 additions & 0 deletions common/autoware_control_center/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_control_center</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="mfc@leodrive.ai">M. Fatih Cırıt</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>autoware_control_center_msgs</depend>
<depend>bond</depend>
<depend>bondcpp</depend>
<depend>lifecycle_msgs</depend>
<depend>nlohmann-json-dev</depend>
<depend>rclcpp_components</depend>
<depend>rclcpp_lifecycle</depend>
<depend>rcutils</depend>

<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
34 changes: 34 additions & 0 deletions common/autoware_control_center/src/autoware_control_center.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
//
// 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.

#include "autoware_control_center/autoware_control_center.hpp"

namespace autoware_control_center
{
AutowareControlCenter::AutowareControlCenter(const rclcpp::NodeOptions & options)
: LifecycleNode("autoware_control_center", options)
{
// log info
RCLCPP_INFO(get_logger(), "AutowareControlCenter is initialized");
}

void AutowareControlCenter::callback_acc_json_global(
const autoware_control_center_msgs::msg::AutowareControlCenterJson::ConstSharedPtr & msg)
{
// log message
RCLCPP_INFO(get_logger(), "AutowareControlCenterJson received %s", msg->json_message.c_str());
}

} // namespace autoware_control_center
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
//
// 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.

#include "autoware_control_center/autoware_control_center.hpp"

#include <rclcpp/rclcpp.hpp>

#include <memory>

int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
auto autoware_control_center =
std::make_shared<autoware_control_center::AutowareControlCenter>(rclcpp::NodeOptions());
rclcpp::executors::MultiThreadedExecutor exec;
exec.add_node(autoware_control_center->get_node_base_interface());
exec.spin();
rclcpp::shutdown();

return 0;
}

#include <rclcpp_components/register_node_macro.hpp>
RCLCPP_COMPONENTS_REGISTER_NODE(autoware_control_center::AutowareControlCenter)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
//
// 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.

#include "test_autoware_control_center.hpp"
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
//
// 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 TEST_AUTOWARE_CONTROL_CENTER_HPP_
#define TEST_AUTOWARE_CONTROL_CENTER_HPP_

class test_autoware_control_center
{
};

#endif // TEST_AUTOWARE_CONTROL_CENTER_HPP_
15 changes: 15 additions & 0 deletions common/autoware_control_center_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.14)
project(autoware_control_center_msgs)

find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()
set(msg_dependencies
unique_identifier_msgs)

rosidl_generate_interfaces(${PROJECT_NAME}
"msg/StatusRegistration.msg"
"srv/AutowareNodeRegister.srv"
DEPENDENCIES ${msg_dependencies}
ADD_LINTER_TESTS)

ament_auto_package()
3 changes: 3 additions & 0 deletions common/autoware_control_center_msgs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# autoware_msgs

Before contributing, review [the message guidelines](https://autowarefoundation.github.io/autoware-documentation/main/contributing/coding-guidelines/ros-nodes/message-guidelines/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Status States
uint8 FAILURE=0
uint8 SUCCESS=1

# Status
uint8 status
23 changes: 23 additions & 0 deletions common/autoware_control_center_msgs/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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_control_center_msgs</name>
<version>1.0.0</version>
<description>autoware_control_center_msgs package.</description>
<maintainer email="mfc@leodrive.ai">M. Fatih Cırıt</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>

<depend>rosidl_default_generators</depend>
<depend>unique_identifier_msgs</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>
17 changes: 17 additions & 0 deletions common/autoware_control_center_msgs/srv/AutowareNodeRegister.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Request

## Name of the registering AutowareNode
string name_node

---

# Response

## Status
autoware_control_center_msgs/StatusRegistration status

## UUID
unique_identifier_msgs/UUID uuid_node

## Response Log
string log_response
18 changes: 18 additions & 0 deletions common/autoware_node/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.8)
project(autoware_node)

find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

autoware_package()

ament_auto_add_library(${PROJECT_NAME} src/autoware_node.cpp)

if (BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
ament_add_ros_isolated_gtest(test_autoware_node test/test_autoware_node.cpp)
target_link_libraries(test_autoware_node ${PROJECT_NAME})
endif ()

ament_auto_package()
Empty file added common/autoware_node/README.md
Empty file.
42 changes: 42 additions & 0 deletions common/autoware_node/include/autoware_node/autoware_node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
//
// 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 AUTOWARE_NODE__AUTOWARE_NODE_HPP_
#define AUTOWARE_NODE__AUTOWARE_NODE_HPP_

#include "autoware_node/visibility_control.hpp"
#include "rclcpp_lifecycle/lifecycle_node.hpp"

#include "autoware_control_center_msgs/srv/autoware_node_register.hpp"

namespace autoware_node
{

class AutowareNode : public rclcpp_lifecycle::LifecycleNode
{
public:
AUTOWARE_NODE_PUBLIC
AutowareNode(
const std::string & node_name, const std::string & ns = "",
const rclcpp::NodeOptions & options = rclcpp::NodeOptions());

rclcpp::CallbackGroup::SharedPtr callback_group_mut_ex_;

rclcpp::Client<autoware_control_center_msgs::srv::AutowareNodeRegister>::SharedPtr cli_register_;
};

} // namespace autoware_node

#endif // AUTOWARE_NODE__AUTOWARE_NODE_HPP_
27 changes: 27 additions & 0 deletions common/autoware_node/include/autoware_node/visibility_control.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 The Autoware Contributors
// SPDX-License-Identifier: Apache-2.0
//
// 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 AUTOWARE_NODE__VISIBILITY_CONTROL_HPP_
#define AUTOWARE_NODE__VISIBILITY_CONTROL_HPP_

#include "rcutils/visibility_control_macros.h"
#ifdef AUTOWARE_NODE_BUILDING_DLL
#define AUTOWARE_NODE_PUBLIC RCUTILS_EXPORT
#else
#define AUTOWARE_NODE_PUBLIC RCUTILS_IMPORT
#endif // !AUTOWARE_NODE_BUILDING_DLL
#define AUTOWARE_NODE_LOCAL RCUTILS_LOCAL

#endif // AUTOWARE_NODE__VISIBILITY_CONTROL_HPP_
Loading

0 comments on commit df7e483

Please sign in to comment.