From b69cd7da3f19c27538f34033960d665a9717a549 Mon Sep 17 00:00:00 2001 From: Burak Ozter Date: Thu, 10 Oct 2024 18:00:33 -0300 Subject: [PATCH] first commit - cpp package working --- answers.meta.yml | 4 ++ copier.yml | 32 +++++++++++++++ src/CMakeLists.txt.jinja | 39 +++++++++++++++++++ src/package.xml.jinja | 23 +++++++++++ .../{{PACKAGE_NAME}}/my_node.hpp | 1 + .../my_node.cpp.jinja | 10 +++++ .../__init__.py | 0 .../my_node.py | 39 +++++++++++++++++++ ... 'Python' in LANGUAGES%}setup.cfg{%endif%} | 4 ++ ...hon' in LANGUAGES%}setup.py.jinja{%endif%} | 31 +++++++++++++++ {{_copier_conf.answers_file}}.jinja | 2 + 11 files changed, 185 insertions(+) create mode 100644 answers.meta.yml create mode 100644 copier.yml create mode 100644 src/CMakeLists.txt.jinja create mode 100644 src/package.xml.jinja create mode 100644 src/{%if 'CPP' in LANGUAGES%}include{%endif%}/{{PACKAGE_NAME}}/my_node.hpp create mode 100644 src/{%if 'CPP' in LANGUAGES%}src{%endif%}/my_node.cpp.jinja create mode 100644 src/{%if 'Python' in LANGUAGES%}scripts{%endif%}/__init__.py create mode 100644 src/{%if 'Python' in LANGUAGES%}scripts{%endif%}/my_node.py create mode 100644 src/{%if 'Python' in LANGUAGES%}setup.cfg{%endif%} create mode 100644 src/{%if 'Python' in LANGUAGES%}setup.py.jinja{%endif%} create mode 100644 {{_copier_conf.answers_file}}.jinja diff --git a/answers.meta.yml b/answers.meta.yml new file mode 100644 index 0000000..17cd9df --- /dev/null +++ b/answers.meta.yml @@ -0,0 +1,4 @@ +# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY +_commit: v1.0.0 +_src_path: https://git.spirirobotics.com/Spiri/template-meta.git +project_name: service-ros2-ament_cmake \ No newline at end of file diff --git a/copier.yml b/copier.yml new file mode 100644 index 0000000..3fb7139 --- /dev/null +++ b/copier.yml @@ -0,0 +1,32 @@ +_subdirectory: src +_answers_file: .copier/answers.service-ros2-ament_cmake.yml +PACKAGE_NAME: + default: myproject + type: str + help: The folder your package lives in. Please avoid spaces. + +PACKAGE_DESCRIPTION: + default: The {{PACKAGE_NAME}} package + type: str + multiline: true + +MAINTAINER_NAME: No Reply +MAINTAINER_EMAIL: "{{MAINTAINER_NAME|lower|replace(' ', '.')}}@spirirobotics.com" +LICENSE: BSD +#We use a custom launch script to ensure that rosrun logs to console and have it not accidently launch the master node itself, which can be hard to diagnose +LANGUAGES: + type: str + multiselect: true + help: Which langauges do you want to use? + choices: + - Python + - CPP + +RUN_COMMAND: ros2 run {{ PACKAGE_NAME }} {{ "my_node.py" if 'Python' in LANGUAGES else "my_node" if "CPP" in LANGUAGES else "yourcommandGoes here" }} + +HEALTHCHECK: + defualt: HEALTHCHECK --start-period=60s --start-interval=1s CMD /ros_entrypoint.sh ros2 topic list + type: str + help: | + Set a health check. + This stub health check just sees if we can talk to the ROS master \ No newline at end of file diff --git a/src/CMakeLists.txt.jinja b/src/CMakeLists.txt.jinja new file mode 100644 index 0000000..7f87d25 --- /dev/null +++ b/src/CMakeLists.txt.jinja @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.8) +project({{PACKAGE_NAME}}) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +{% if "CPP" in LANGUAGES %} +# find dependencies +find_package(ament_cmake REQUIRED) +# uncomment the following section in order to fill in +# further dependencies manually. +# find_package( REQUIRED) + +include_directories(include) +add_executable(my_node src/my_node.cpp) +target_include_directories(my_node PUBLIC + $ + $) +target_compile_features(my_node PUBLIC c_std_99 cxx_std_17) # Require C99 and C++17 + +install(TARGETS my_node + DESTINATION lib/${PROJECT_NAME}) + +{% endif %} + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + # the following line skips the linter which checks for copyrights + # comment the line when a copyright and license is added to all source files + set(ament_cmake_copyright_FOUND TRUE) + # the following line skips cpplint (only works in a git repo) + # comment the line when this package is in a git repo and when + # a copyright and license is added to all source files + set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() +endif() + +ament_package() diff --git a/src/package.xml.jinja b/src/package.xml.jinja new file mode 100644 index 0000000..92b004d --- /dev/null +++ b/src/package.xml.jinja @@ -0,0 +1,23 @@ + + + + {{PACKAGE_NAME}} + 0.0.0 + {{PACKAGE_DESCRIPTION}} + {{MAINTAINER_NAME}} + {{LICENSE}} + + ament_cmake + + ament_lint_auto + ament_lint_common + + {% if "Python" in LANGUAGES %} + rclpy + std_msgs + {% endif %} + + + ament_cmake + + diff --git a/src/{%if 'CPP' in LANGUAGES%}include{%endif%}/{{PACKAGE_NAME}}/my_node.hpp b/src/{%if 'CPP' in LANGUAGES%}include{%endif%}/{{PACKAGE_NAME}}/my_node.hpp new file mode 100644 index 0000000..7b9637e --- /dev/null +++ b/src/{%if 'CPP' in LANGUAGES%}include{%endif%}/{{PACKAGE_NAME}}/my_node.hpp @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/src/{%if 'CPP' in LANGUAGES%}src{%endif%}/my_node.cpp.jinja b/src/{%if 'CPP' in LANGUAGES%}src{%endif%}/my_node.cpp.jinja new file mode 100644 index 0000000..a58086a --- /dev/null +++ b/src/{%if 'CPP' in LANGUAGES%}src{%endif%}/my_node.cpp.jinja @@ -0,0 +1,10 @@ +#include +#include "{{PACKAGE_NAME}}/my_node.hpp" +int main(int argc, char ** argv) +{ + (void) argc; + (void) argv; + + printf("hello world {{PACKAGE_NAME}} package\n"); + return 0; +} diff --git a/src/{%if 'Python' in LANGUAGES%}scripts{%endif%}/__init__.py b/src/{%if 'Python' in LANGUAGES%}scripts{%endif%}/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/{%if 'Python' in LANGUAGES%}scripts{%endif%}/my_node.py b/src/{%if 'Python' in LANGUAGES%}scripts{%endif%}/my_node.py new file mode 100644 index 0000000..fff0ae1 --- /dev/null +++ b/src/{%if 'Python' in LANGUAGES%}scripts{%endif%}/my_node.py @@ -0,0 +1,39 @@ +import rclpy +from rclpy.node import Node + +from std_msgs.msg import String + + +class MinimalPublisher(Node): + + def __init__(self): + super().__init__('minimal_publisher') + self.publisher_ = self.create_publisher(String, 'topic', 10) + timer_period = 0.5 # seconds + self.timer = self.create_timer(timer_period, self.timer_callback) + self.i = 0 + + def timer_callback(self): + msg = String() + msg.data = 'Hello World: %d' % self.i + self.publisher_.publish(msg) + self.get_logger().info('Publishing: "%s"' % msg.data) + self.i += 1 + + +def main(args=None): + rclpy.init(args=args) + + minimal_publisher = MinimalPublisher() + + rclpy.spin(minimal_publisher) + + # Destroy the node explicitly + # (optional - otherwise it will be done automatically + # when the garbage collector destroys the node object) + minimal_publisher.destroy_node() + rclpy.shutdown() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/src/{%if 'Python' in LANGUAGES%}setup.cfg{%endif%} b/src/{%if 'Python' in LANGUAGES%}setup.cfg{%endif%} new file mode 100644 index 0000000..8d8c058 --- /dev/null +++ b/src/{%if 'Python' in LANGUAGES%}setup.cfg{%endif%} @@ -0,0 +1,4 @@ +[develop] +script_dir=$base/lib/my_node +[install] +install_scripts=$base/lib/my_node \ No newline at end of file diff --git a/src/{%if 'Python' in LANGUAGES%}setup.py.jinja{%endif%} b/src/{%if 'Python' in LANGUAGES%}setup.py.jinja{%endif%} new file mode 100644 index 0000000..439fc1f --- /dev/null +++ b/src/{%if 'Python' in LANGUAGES%}setup.py.jinja{%endif%} @@ -0,0 +1,31 @@ +from setuptools import find_packages, setup +import os +from glob import glob +package_name = {{PACKAGE_NAME}} + +setup( + name=package_name, + version='0.0.0', + packages=find_packages(exclude=['test']), + data_files=[ + ('share/ament_index/resource_index/packages', + ['resource/' + package_name]), + ('share/' + package_name, ['package.xml']), + ( + os.path.join("share", package_name, "launch"), + glob(os.path.join("launch", "*launch.[pxy][yma]*")), #Include launch files + ), + ], + install_requires=['setuptools'], + zip_safe=True, + maintainer={{MAINTAINER_NAME}}, + maintainer_email={{MAINTAINER_EMAIL}}, + description={{PACKAGE_DESCRIPTION}}, + license={{LICENSE}}, + tests_require=['pytest'], + entry_points={ + 'console_scripts': [ + 'minimal_publisher = scripts.my_node:main' + ], + }, +) diff --git a/{{_copier_conf.answers_file}}.jinja b/{{_copier_conf.answers_file}}.jinja new file mode 100644 index 0000000..ea97bd4 --- /dev/null +++ b/{{_copier_conf.answers_file}}.jinja @@ -0,0 +1,2 @@ +# Changes here will be overwritten by Copier +{{ _copier_answers|to_nice_yaml -}} \ No newline at end of file