-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Krauskopf Sebastian (DC-AE/EAR2)
committed
Oct 20, 2024
1 parent
c31bebd
commit 62d07ba
Showing
27 changed files
with
1,066 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build/ | ||
install/ | ||
log/ | ||
__pycache__/ | ||
prime/ | ||
parts/ | ||
stage/ | ||
squashfs-root/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"ros.distro": "humble", | ||
"files.associations": { | ||
"functional": "cpp", | ||
"new": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"tasks": [ | ||
{ | ||
"type": "cppbuild", | ||
"label": "C/C++: gcc build active file", | ||
"command": "/usr/bin/gcc", | ||
"args": [ | ||
"-fdiagnostics-color=always", | ||
"-g", | ||
"${file}", | ||
"-o", | ||
"${fileDirname}/${fileBasenameNoExtension}" | ||
], | ||
"options": { | ||
"cwd": "${fileDirname}" | ||
}, | ||
"problemMatcher": [ | ||
"$gcc" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"detail": "Task generated by Debugger." | ||
} | ||
], | ||
"version": "2.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Simple ROS 2 Subscriber in C++ | ||
|
||
A simple ROS 2 node which subscribes to ROS messages of the topic `ros2_simple_talker_cpp` and publishes the value to the ctrlX Data Layer at the address `ros/listenercpp/mymessage`. From there the value can be used in any ctrlX App. | ||
|
||
## Prerequisites | ||
|
||
* `ros-base` snap. The base snap which provides the ROS 2 runtime binaries. Has to be installed on ctrlX OS. See [ROS 2 Humble Base Snap](../ros2-base-humble-deb/README.md). | ||
* An Ubuntu based build environment to build an app. See [ctrlX Automation SDK](https://github.com/boschrexroth/ctrlx-automation-sdk). | ||
|
||
## Basis for this Project | ||
|
||
This project is based on the official ROS 2 Tutorial: [Writing a simple publisher and subscriber (C++)](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html#writing-a-simple-publisher-and-subscriber-c). | ||
|
||
## Building a Snap | ||
|
||
Building a snap has two steps: | ||
|
||
1. Colcon build: `CMakeLists.txt` defines how compile and link the C++ sources. | ||
2. snap build: `snap/snapcraft.yaml` defines how the compiled binaries are packed into the snap and how they are called on ctrlX OS. | ||
|
||
### Colcon Configuration | ||
|
||
The colcon build tool is configured by `CMakeLists.txt`. | ||
|
||
This section defines the ROS 2 packages needed: | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
|
||
And here the executables and their dependencies are defined: | ||
|
||
add_executable(listener src/subscriber_member_function.cpp) | ||
ament_target_dependencies(listener rclcpp std_msgs) | ||
|
||
### Snapcraft Configuration | ||
|
||
`snap/snapcraft.yaml` defines how the snap will be build: | ||
|
||
* `install/` is dumped into the snap | ||
* also `wrapper/` | ||
* Two apps (talker and listener) are copied into the snap and started as services | ||
* The snap - respectively the executables - uses the content interface of the `ros-base` snap (here the ROS 2 runtime is provided). | ||
|
||
### Build the Snap | ||
|
||
Start this script: | ||
|
||
./build-snap-amd64.sh | ||
|
||
## About | ||
|
||
SPDX-FileCopyrightText: Copyright (c) 2023 Bosch Rexroth AG | ||
|
||
<https://www.boschrexroth.com/en/dc/imprint/> | ||
|
||
## Licenses | ||
|
||
SPDX-License-Identifier: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
source colcon-build.sh | ||
if [ $? -eq 0 ] | ||
then | ||
echo " " | ||
else | ||
exit 1 | ||
fi | ||
|
||
snapcraft clean --destructive-mode | ||
snapcraft --destructive-mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
rosdep install -i --from-path src --rosdistro humble -y | ||
if [ $? -eq 0 ] | ||
then | ||
echo " " | ||
else | ||
exit 1 | ||
fi | ||
|
||
rm -rf install/ | ||
mkdir -p install/app | ||
rm -rf build/ | ||
rm -rf log/ | ||
|
||
source /opt/ros/humble/setup.bash | ||
colcon build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: ros2-simple-listener-dl-cpp | ||
version: '2.2.0' | ||
summary: Snap with simple ROS 2 listener | ||
description: | | ||
A simple ROS 2 listener which receives ROS 2 messages on topic 'ros2_simple_cpp'. | ||
base: core22 | ||
grade: stable | ||
confinement: strict | ||
|
||
parts: | ||
ros-app: | ||
plugin: dump | ||
source: install | ||
stage-packages: | ||
- libzmq5 | ||
- ctrlx-datalayer | ||
override-build: | | ||
snapcraftctl build | ||
wrapper-scripts: | ||
plugin: dump | ||
source: wrapper/ | ||
organize: | ||
./run-listener.sh : usr/bin/run-listener | ||
|
||
apps: | ||
listener: | ||
command: usr/bin/run-listener | ||
plugs: | ||
- ros-base | ||
- network | ||
- network-bind | ||
daemon: simple | ||
passthrough: | ||
restart-condition: always | ||
restart-delay: 10s | ||
|
||
plugs: | ||
ros-base: | ||
interface: content | ||
content: executables | ||
target: $SNAP/rosruntime | ||
|
||
datalayer: | ||
interface: content | ||
content: datalayer | ||
target: $SNAP_DATA/.datalayer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(app) | ||
set(TARGET_PROJECT_NAME listener) | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
# find dependencies | ||
find_package(ament_cmake REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
|
||
|
||
# | ||
# Set link directories | ||
# | ||
MESSAGE( STATUS "Libraries directory: ${LIBRARY_DIR}") | ||
link_directories( | ||
${LIBRARY_DIR} | ||
${LIBRARY_DEP_DIR} | ||
) | ||
|
||
# User dependency directory | ||
# | ||
set (USER_DEPENDENCY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..) | ||
|
||
SET ( PRIVATE_INCLUDE_DIRS | ||
${CMAKE_CURRENT_LIST_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
${CMAKE_CURRENT_LIST_DIR}/include | ||
${USER_DEPENDENCY_DIR}/include | ||
${USER_DEPENDENCY_DIR}/include/comm.datalayer | ||
) | ||
|
||
# Set target link libraries | ||
|
||
|
||
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() | ||
|
||
add_executable(listener src/subscriber_member_function.cpp) | ||
ament_target_dependencies(listener rclcpp std_msgs) | ||
|
||
|
||
# | ||
# Set target include directories | ||
# | ||
target_include_directories ( ${TARGET_PROJECT_NAME} | ||
PUBLIC ${PUBLIC_INCLUDE_DIRS} | ||
PUBLIC ${LIBRARY_INCLUDES} | ||
PRIVATE ${PRIVATE_INCLUDE_DIRS} | ||
) | ||
# | ||
target_link_libraries(${TARGET_PROJECT_NAME} -Wl,--no-undefined) | ||
target_link_libraries(${TARGET_PROJECT_NAME} | ||
libcomm_datalayer.so | ||
pthread | ||
systemd | ||
zmq | ||
ssl | ||
crypto | ||
) | ||
|
||
install(TARGETS | ||
listener | ||
DESTINATION lib/${PROJECT_NAME}) | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>app</name> | ||
<version>2.2.0</version> | ||
<description>Simple ROS 2 subscriber (listener) in cpp</description> | ||
<maintainer email="[email protected]">boschrexroth</maintainer> | ||
<license>MIT License</license> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
|
||
<depend>rclcpp</depend> | ||
<depend>std_msgs</depend> | ||
<depend>sensor_msgs</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>ament_lint_common</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
Oops, something went wrong.