Skip to content

Working with ROS initial example #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Working with ROS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Working with ROS

This application demonstrates how to set up ROS working environment.

## Setup

Application should use Docker image that has ROS preinstalled (or installs it as specified in custom Dockerfile). This can be for example one of the official ROS images.
To enable visibility of ROS system libraries while running the App, you can update `pre_launch` configuration in `robotapp.toml` in following way:
`pre_launch = "export ROS_DOMAIN_ID=30\n. /opt/ros/$ROS_DISTRO/setup.sh\n. /ws/install/setup.sh"`
- `export ROS_DOMAIN_ID=30` - setting up correct ROS domaind ID when running
- `. /opt/ros/$ROS_DISTRO/setup.sh` - sourcing main ROS install
- `. /ws/install/setup.sh` - sourcing custom ROS package

In the App itself you can either create your own Python nodes via rclpy, or launch other nodes, for example via using separate bash script.
19 changes: 19 additions & 0 deletions Working with ROS/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import signal
import subprocess
from robothub import BaseApplication

class Application(BaseApplication):
def __init__(self):
super().__init__()
self.ros_proc = None
def on_start(self):
env = dict(os.environ)
self.ros_proc = subprocess.Popen(
"bash -c 'chmod +x /app/start_ros.sh ; /app/start_ros.sh'", shell=True, env=env, preexec_fn=os.setsid
)
def on_stop(self):
if self.ros_proc is not None:
pgid = os.getpgid(self.ros_proc.pid)
os.killpg(pgid, signal.SIGTERM)

19 changes: 19 additions & 0 deletions Working with ROS/robotapp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
config_version = "2.0"
configuration = []

[info]
name = "ROS App"
description = "ROS App environment"

[runtime]
application = "app.py#Application"
workdir = "/app"
pre_launch = "export ROS_DOMAIN_ID=30\n. /opt/ros/$ROS_DISTRO/setup.sh\n. /ws/install/setup.sh"


[runtime.frontend]
redirectToIndex = true

[runtime.runs_on]
type = "image"
name = "ros:humble-ros-base"
10 changes: 10 additions & 0 deletions Working with ROS/start_ros.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

# setup ros environment
source "/opt/ros/$ROS_DISTRO/setup.bash"
source "/ws/install/setup.bash"

export ROS_DOMAIN_ID=30 # setup domain id
# Add your custom launch file here
# ros2 launch demo_nodes_cpp talker_listener.launch.py