Skip to content

Commit

Permalink
new: add data layer samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Krauskopf Sebastian (DC-AE/EAR2) committed Oct 20, 2024
1 parent c31bebd commit 62d07ba
Show file tree
Hide file tree
Showing 27 changed files with 1,066 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ Temporary Items
/parts/
/stage/
/prime/
/*.snap
*.snap

# Snapcraft global state tracking data(automatically generated)
# https://forum.snapcraft.io/t/location-to-save-global-state/768
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Bosch Rexroth AG
Copyright (c) 2024 Bosch Rexroth AG

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# ctrlX AUTOMATION Software Development Kit for ROS 2

This is the Software Development Kit (SDK) to build ROS 2 Applications, that can run on industrial devices that are based on the ctrlX OS platform.
This is the Software Development Kit (SDK) to build ROS 2 Applications, that can run on industrial devices that are based on the ctrlX OS platform.

The **Robot Operating System (ROS)** is an open source robotics software framework that help you build robot applications.
The **Robot Operating System (ROS)** is an open source robotics software framework that help you build robot applications.
**ctrlX OS** is an industrial grade realtime platform based on Linux which is available for several industrial hardware devices and features an app-based modular architecture that allows you to install additional functionality. This includes apps for industrial fieldbus communication, machine automation, programmable logic control (PLC) and other automation software which can also be found ready-to-run in the [ctrlX Store](https://developer.community.boschrexroth.com/).

Please note, that this is the first version of the ROS 2 SDK. You may expect more samples and extensions over the course of the next months.

## Getting Started

As a prerequisite you should get yourself familiar with:

* ROS 2 and its underlying architecture using the official ROS 2 documentation at: <https://www.ros.org/blog/getting-started/>
* The [ctrlX AUTOMATION Ecosystem](https://ctrlx-automation.com/) and the architecture of ctrlX OS as well as devices which are capable to run ctrlX OS. E.g. ctrlX CORE devices from [Bosch Rexroth](https://www.boschrexroth.com/).
* The [ctrlX AUTOMATION SDK](https://github.com/boschrexroth/ctrlx-automation-sdk) which is the underlying SDK that allows you to create any kind of App for ctrlX OS and is the foundation for the ctrlX AUTOMATION Software Development Kit for ROS 2.
* The [ctrlX AUTOMATION SDK](https://github.com/boschrexroth/ctrlx-automation-sdk) which is the underlying SDK that allows you to create any kind of App for ctrlX OS and is the foundation for the ctrlX AUTOMATION Software Development Kit for ROS 2. [Link to SDK Documentation](https://boschrexroth.github.io/ctrlx-automation-sdk/)

## Usage

Expand All @@ -38,13 +40,20 @@ This SDK contains also multiple project examples to show the usage of ROS 2. All

### ROS 2 Humble Applications in C++

#### Writing a Simple Publisher and Subscriber (C++)
#### Learn how to package your application as snap

This example is based on the official ROS 2 Tutorial and adjusted to run on ctrlX OS together with the *base snap*. You can find the original source code at [ROS 2 Humble Tutorials - 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)

* [`simple-talker-cpp/`](simple-talker-cpp/README.md) contains the snap version of the described publisher (talker)
* [`simple-listener-cpp/`](simple-listener-cpp/README.md) contains the snap version of the described subscriber (listener)

#### Learn how to access the ctrlX Data Layer from your application

the ctrlX Data Layer is the realtime message broker that runs on ctrlX OS. It is used by all ctrlX Apps to publish and exchange variables, types, methods and programs. In the ctrlX Data Layer you can find all device, process, fieldbus and periphery data. You can connect to the ctrlX Data Layer via TCP/IP or IPC.

* [`simple-talker-dl-cpp/`](simple-talker-dl-cpp/README.md) read from ctrlX Data Layer and publish as ROS message (talker)
* [`simple-listener-dl-cpp/`](simple-listener-dl-cpp/README.md) subscribe to ROS message and publish in ctrlX Data Layer (listener)

### ROS 2 Humble Applications in Python

#### Writing a Simple Publisher and Subscriber (Python)
Expand Down Expand Up @@ -87,7 +96,7 @@ Any use of the source code and related documents of this repository in applicati

## About

SPDX-FileCopyrightText: Copyright (c) 2023 Bosch Rexroth AG
SPDX-FileCopyrightText: Copyright (c) 2024 Bosch Rexroth AG

<https://www.boschrexroth.com/en/dc/imprint/>

Expand Down
8 changes: 8 additions & 0 deletions simple-listener-dl-cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build/
install/
log/
__pycache__/
prime/
parts/
stage/
squashfs-root/
7 changes: 7 additions & 0 deletions simple-listener-dl-cpp/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ros.distro": "humble",
"files.associations": {
"functional": "cpp",
"new": "cpp"
}
}
28 changes: 28 additions & 0 deletions simple-listener-dl-cpp/.vscode/tasks.json
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"
}
59 changes: 59 additions & 0 deletions simple-listener-dl-cpp/README.md
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
12 changes: 12 additions & 0 deletions simple-listener-dl-cpp/build-snap-amd64.sh
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
17 changes: 17 additions & 0 deletions simple-listener-dl-cpp/colcon-build.sh
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
48 changes: 48 additions & 0 deletions simple-listener-dl-cpp/snap/snapcraft.yaml
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
78 changes: 78 additions & 0 deletions simple-listener-dl-cpp/src/app/CMakeLists.txt
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()
22 changes: 22 additions & 0 deletions simple-listener-dl-cpp/src/app/package.xml
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>
Loading

0 comments on commit 62d07ba

Please sign in to comment.