diff --git a/Working with ROS/README.md b/Working with ROS/README.md new file mode 100644 index 0000000..ecd4933 --- /dev/null +++ b/Working with ROS/README.md @@ -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. \ No newline at end of file diff --git a/Working with ROS/app.py b/Working with ROS/app.py new file mode 100644 index 0000000..916b116 --- /dev/null +++ b/Working with ROS/app.py @@ -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) + \ No newline at end of file diff --git a/Working with ROS/robotapp.toml b/Working with ROS/robotapp.toml new file mode 100644 index 0000000..33530e5 --- /dev/null +++ b/Working with ROS/robotapp.toml @@ -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" diff --git a/Working with ROS/start_ros.sh b/Working with ROS/start_ros.sh new file mode 100644 index 0000000..4f05856 --- /dev/null +++ b/Working with ROS/start_ros.sh @@ -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 \ No newline at end of file