Skip to content

Commit

Permalink
add file and folder structure for ros2_python_pkg template
Browse files Browse the repository at this point in the history
  • Loading branch information
lreiher committed Sep 10, 2024
1 parent 21b3174 commit 84d03f7
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 13 deletions.
26 changes: 13 additions & 13 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ template:
help: Template
type: str
default: ros2_cpp_pkg
choices: [ros2_cpp_pkg, ros2_interfaces_pkg]
choices: [ros2_cpp_pkg, ros2_interfaces_pkg, ros2_python_pkg]

package_name:
help: Package name
type: str
placeholder: ros2_cpp_pkg
placeholder: "{{ template }}"
validator: "{% if not package_name %}Package name is required{% endif %}"

description:
Expand Down Expand Up @@ -53,13 +53,13 @@ license:

node_name:
help: Node name
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: str
default: "{{ package_name }}"

node_class_name:
help: Class name of node
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: str
default: "{{ node_name | to_camel }}"

Expand All @@ -77,56 +77,56 @@ is_lifecycle:

has_launch_file:
help: Add a launch file?
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: bool
default: true

launch_file_type:
help: Type of launch file
when: "{{ template == 'ros2_cpp_pkg' and has_launch_file }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: str
default: py
choices: [py, xml, yml]

has_params:
help: Add parameter loading?
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: bool
default: true

has_subscriber:
help: Add a subscriber?
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: bool
default: true

has_publisher:
help: Add a publisher?
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: bool
default: true

has_service_server:
help: Add a service server?
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: bool
default: false

has_action_server:
help: Add an action server?
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: bool
default: false

has_timer:
help: Add a timer callback?
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
type: bool
default: false

auto_shutdown:
help: Automatically shutdown the node after launch (useful in CI/CD)?
when: "{{ template == 'ros2_cpp_pkg' }}"
when: "{{ template == 'ros2_cpp_pkg' or template == 'ros2_python_pkg' }}"
when: false
type: bool
default: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.8)
project({{ package_name }}_interfaces)

find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
action/Fibonacci.action
)

ament_export_dependencies(rosidl_default_runtime)

ament_package()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int32 order
---
int32[] sequence
---
int32[] partial_sequence
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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>{{ package_name }}_interfaces</name>
<version>0.0.0</version>
<description>ROS interface definitions for {{ package_name }}</description>

<maintainer email="{{ maintainer_email }}">{{ maintainer }}</maintainer>
<author email="{{ author_email }}">{{ author }}</author>

<license>{{ license }}</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>rosidl_default_generators</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>

<member_of_group>rosidl_interface_packages</member_of_group>

<export>
<build_type>ament_cmake</build_type>
</export>

</package>
22 changes: 22 additions & 0 deletions templates/ros2_python_pkg/{{ package_name }}/package.xml.jinja
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>{{ package_name }}</name>
<version>0.0.0</version>
<description>{{ description }}</description>

<maintainer email="{{ maintainer_email }}">{{ maintainer }}</maintainer>
<author email="{{ author_email }}">{{ author }}</author>

<license>{{ license }}</license>

<buildtool_depend>ament_python</buildtool_depend>

<depend>rclpy</depend>

<export>
<build_type>ament_python</build_type>
</export>

</package>
Empty file.
4 changes: 4 additions & 0 deletions templates/ros2_python_pkg/{{ package_name }}/setup.cfg.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/{{ package_name }}
[install]
install_scripts=$base/lib/{{ package_name }}
29 changes: 29 additions & 0 deletions templates/ros2_python_pkg/{{ package_name }}/setup.py.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
from glob import glob
from setuptools import setup

package_name = '{{ package_name }}'

setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[('share/ament_index/resource_index/packages',
['resource/' + package_name]),
(os.path.join('share', package_name), ['package.xml']),
(os.path.join('share', package_name,
'launch'), glob('launch/*launch.[pxy][yma]*')),
(os.path.join('share', package_name,
'config'), glob('config/*.yaml'))],
install_requires=['setuptools'],
zip_safe=True,
maintainer='root',
maintainer_email='root@todo.todo',
description='TODO: Package description',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts':
['{{ node_name }} = {{ package_name }}.{{ node_name }}:main'],
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include:
- remote: https://raw.githubusercontent.com/ika-rwth-aachen/docker-ros/main/.gitlab-ci/docker-ros.yml

variables:
PLATFORM: amd64,arm64
TARGET: dev,run
BASE_IMAGE: rwthika/ros2:latest
COMMAND: ros2 run {{ package_name }} {{ node_name }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python3

import os

from ament_index_python import get_package_share_directory
from launch import LaunchDescription
{% if is_lifecycle %}
from launch.actions import DeclareLaunchArgument, GroupAction
from launch.conditions import LaunchConfigurationNotEquals
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import LifecycleNode, SetParameter
{% else %}
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
{% endif %}


def generate_launch_description():

arg_name = DeclareLaunchArgument("name", default_value="{{ node_name }}", description="node name")
arg_namespace = DeclareLaunchArgument("namespace", default_value="", description="node namespace")

node = Node(
package="{{ package_name }}",
executable="{{ node_name }}",
namespace=LaunchConfiguration("namespace"),
name=LaunchConfiguration("name"),
{% if has_params %}
parameters=[
os.path.join(get_package_share_directory("{{ package_name }}"), "config", "params.yml"),
],
{% endif %}
output="screen",
emulate_tty=True,
)

return LaunchDescription([
arg_name,
arg_namespace,
node
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<launch>

<arg name="name" default="{{ node_name }}" description="node name" />
<arg name="namespace" default="" description="node namespace" />

<node pkg="{{ package_name }}" exec="{{ node_name }}" namespace="$(var namespace)" name="$(var name)" output="screen">
{% if has_params %}
<param from="$(find-pkg-share {{ package_name }})/config/params.yml" />
{% endif %}
</node>

</launch>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
launch:
- arg:
name: name
default: {{ node_name }}
description: node name
- arg:
name: namespace
default: ""
description: node namespace
- node:
pkg: {{ package_name }}
exec: {{ node_name }}
namespace: "$(var namespace)"
name: "$(var name)"
output: screen
{% if has_params %}
param:
- name: param
value: 1.0
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**/*:
ros__parameters:
param: 1.0
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import rclpy

from rclpy import Node


class {{ node_class_name }}(Node):
def __init__(self):
pass


def main():

rclpy.init()
rclpy.spin({{ node_class_name }}())
rclpy.shutdown()


if __name__ == "__main__":
main()

0 comments on commit 84d03f7

Please sign in to comment.