first commit - cpp package working

This commit is contained in:
Burak Ozter 2024-10-10 18:00:33 -03:00
commit b69cd7da3f
11 changed files with 185 additions and 0 deletions

4
answers.meta.yml Normal file
View File

@ -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

32
copier.yml Normal file
View File

@ -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

39
src/CMakeLists.txt.jinja Normal file
View File

@ -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(<dependency> REQUIRED)
include_directories(include)
add_executable(my_node src/my_node.cpp)
target_include_directories(my_node PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
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()

23
src/package.xml.jinja Normal file
View File

@ -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>{{PACKAGE_NAME}}</name>
<version>0.0.0</version>
<description>{{PACKAGE_DESCRIPTION}}</description>
<maintainer email="{{MAINTAINER_EMAIL}}">{{MAINTAINER_NAME}}</maintainer>
<license>{{LICENSE}}</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
{% if "Python" in LANGUAGES %}
<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>
{% endif %}
<export>
<build_type>ament_cmake</build_type>
</export>
</package>

View File

@ -0,0 +1 @@
#pragma once

View File

@ -0,0 +1,10 @@
#include <cstdio>
#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;
}

View File

@ -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()

View File

@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/my_node
[install]
install_scripts=$base/lib/my_node

View File

@ -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'
],
},
)

View File

@ -0,0 +1,2 @@
# Changes here will be overwritten by Copier
{{ _copier_answers|to_nice_yaml -}}