Skip to content

Commit

Permalink
Support services
Browse files Browse the repository at this point in the history
  • Loading branch information
mullr committed Apr 4, 2024
1 parent 8d4b8a2 commit 9692030
Show file tree
Hide file tree
Showing 33 changed files with 2,061 additions and 627 deletions.
10 changes: 10 additions & 0 deletions .clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CompileFlags:
Add:
- -Iros-deps-for-development/rmw/rmw/include
- -Iros-deps-for-development/rosidl/rosidl_runtime_c/include
- -Iros-deps-for-development/rosidl/rosidl_typesupport_introspection_c/include
- -Iros-deps-for-development/rosidl/rosidl_typesupport_interface/include
- -Iros-deps-for-development/rosidl/rosidl_typesupport_interface/include
- -Iros-deps-for-development/rmw_fastrtps/rmw_fastrtps_dynamic_cpp/include
- -Iros-deps-for-development/rmw_fastrtps/rmw_fastrtps_shared_cpp/include
- -Iros-deps-for-development/rmw_fastrtps/rmw_fastrtps_cpp/include
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/target
ros-deps-for-development
38 changes: 2 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,10 @@ name: CI
on: [push]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: moonrepo/setup-rust@v0

- name: Clippy
working-directory: modality-ros-hook
run: cargo clippy --all-features -- -W clippy::all -D warnings

- name: Format
working-directory: modality-ros-hook
run: cargo fmt --all -- --check

- name: Doc Generation
working-directory: modality-ros-hook
run: cargo doc --workspace --bins --examples --all-features --no-deps

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: moonrepo/setup-rust@v0

- name: Debug build
working-directory: modality-ros-hook
run: cargo build

- name: Release build
working-directory: modality-ros-hook
run: cargo build --release

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: moonrepo/setup-rust@v0

- name: Test
working-directory: modality-ros-hook
run: cargo test --all-features -- --test-threads=1
- name: Docker build
run: ./build-in-docker.sh
18 changes: 6 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ jobs:
package:
name: Package
timeout-minutes: 60
runs-on: ubuntu-${{ matrix.ubuntu_version }}
runs-on: ubuntu-latest
needs: [check]
strategy:
matrix:
ubuntu_version: [20.04, 22.04]
steps:
- name: Print version
run: |
Expand All @@ -57,15 +54,11 @@ jobs:
- uses: actions/checkout@v3
- uses: moonrepo/setup-rust@v0

- name: Fetch dependencies
working-directory: modality-ros-hook
run: cargo fetch

- name: Release build
working-directory: modality-ros-hook
run: |
cargo build --release
cp target/release/libmodality_ros_hook.so libmodality_ros_hook_${{matrix.ubuntu_version}}_amd64.so
./build-in-docker.sh
cp target/docker-release/libmodality_ros_hook.so libmodality_ros_hook_22.04_amd64.so
cp target/docker-release/ros_deps ros_deps_22.04_amd64
- name: Create github release
id: create_release
Expand All @@ -77,4 +70,5 @@ jobs:
prerelease: false
name: Release ${{ env.RELEASE_VERSION }}
files: |
modality-ros-hook/libmodality_ros_hook_${{matrix.ubuntu_version}}_amd64.so
libmodality_ros_hook_22.04_amd64.so
ros_deps_22.04_amd64
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target/
/ros-deps-for-development/
9 changes: 0 additions & 9 deletions .gitmodules

This file was deleted.

12 changes: 12 additions & 0 deletions Dockerfile.builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ros:humble

RUN apt-get update
RUN apt-get install libssl-dev libclang-dev curl pkg-config -y

RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

COPY . /src
WORKDIR /src
ENV BINDGEN_EXTRA_CLANG_ARGS="-I/opt/ros/humble/include/rcutils -I/opt/ros/humble/include/rcpputils -I/opt/ros/humble/include/rosidl_runtime_c -I/opt/ros/humble/include/rosidl_typesupport_interface -I/opt/ros/humble/include/rosidl_typesupport_introspection_c -I/opt/ros/humble/include/rmw -I/opt/ros/humble/include/rmw_fastrtps_shared_cpp -I/opt/ros/humble/include/fastrtps -I/opt/ros/humble/include/fastcdr"
RUN ./build-release.sh
56 changes: 47 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# modality-ros2

Observability ([Modality](https://docs.auxon.io/modality/)) and Mutation ([Deviant](https://docs.auxon.io/deviant/)) support for [ROS 2](https://www.ros.org/).

Supports the following ROS versions:
Expand All @@ -18,22 +17,61 @@ publisher and subscriber tracing.
cargo build --release
target/release/libmodality_ros_hook.so
```

* Download the latest artifact from github releases
```bash
wget -O libmodality_ros_hook.so https://github.com/auxoncorp/modality-ros2/releases/latest/download/libmodality_ros_hook_22.04_amd64.so
wget -O ros_deps https://github.com/auxoncorp/modality-ros2/releases/latest/download/ros_deps_22.04
```
2. Install and use the cyclonedds rmw
```bash
sudo apt install ros-humble-rmw-cyclonedds-cpp

export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
```
3. Set `LD_PRELOAD` environment variable prior to running ROS nodes
3. Set `LD_PRELOAD` environment variable prior to running ROS nodes.
```bash
export LD_PRELOAD=/path/to/libmodality_ros_hook.so:/opt/ros/humble/lib/librmw_fastrtps_cpp.so
```

NB: You must be *100% sure* that the .so library you're using was
built against *exactly* the same version of ROS that you're
running. This instrumentation relies on the layout of some internal
structs, which may change between versions. We build against the
`ros:humble` docker image, but even that is a moving target; check
the versions in the `ros_deps` file against your system to make sure
everything lines up.

Note that we've also appended 'librmw_fastrtps_cpp.so' to LD_PRELOAD
as well. This is because, ROS uses a middleware-dispatch library
that `dlopen`s the appropriate middlware library on the fly,
depending on configuration. Unfortunately, this mechanism is not
compatible with `LD_PRELOAD`. By including the specific middleware
implementation in `LD_PRELOAD` here, the dispatch library isn't
loaded at all, which allows our `LD_PRELOAD` hooks to work.

### Configuration

See the [`modality-reflector` Configuration File documentation](https://docs.auxon.io/modality/ingest/modality-reflector-configuration-file.html) for more information
about the reflector or reflector-plugin configuration.
These environment variables configure the behavior of the ROS LD_PRELOAD library:

* `MODALITY_ROS_CONNECT_TIMEOUT`: How long to wait, in seconds, for a
connection to `modalityd`, before giving up. During this time,
messages are queued in memory. Defaults to 20 seconds.

* `MODALITY_ROS_IGNORED_TOPICS`: A comma-separated list of ROS topics
which should be completely ignored when relaying data to
Modality. Be sure to include the '/' at the beginning of the
topic. Defaults to "/parameter_events". If you want to explicitly
include ALL topics (with no default ignores), set this to the empty
string `""`.

* `MODALITY_ROS_MAX_ARRAY_LEN`: When transcribing ROS messages into
Modality format, what is the largest array that should be allowed?
Any array longer than this will be ignored. This is meant to allow
things like vectors and coordinates to be passed into Modality,
while excluding things like camera frames and LIDAR point
clouds. Defaults to 12.

* `MODALITY_AUTH_TOKEN`: The content of the auth token to use when
connecting to Modality. If this is not set, the auth token used by
the Modality CLI is read from `~/.config/modality_cli/.user_auth_token`.

This uses the same connection and configuration infrastructure as
reflector plugins; see the [`modality-reflector` Configuration File
documentation](https://docs.auxon.io/modality/ingest/modality-reflector-configuration-file.html)
for more information.
20 changes: 0 additions & 20 deletions build-debug.sh

This file was deleted.

9 changes: 9 additions & 0 deletions build-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -e

docker build -f Dockerfile.builder -t modality-ros2-build .

mkdir -p target/docker-release/
id=$(docker create modality-ros2-build)
docker cp $id:/src/target/release/libmodality_ros_hook.so target/docker-release/
docker cp $id:/src/target/release/ros_deps target/docker-release/
docker rm -v $id
35 changes: 29 additions & 6 deletions build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ set -e

(
cd modality-ros-hook
cargo clippy --all-features -- -W clippy::all -D warnings
cargo fmt --all -- --check
cargo test --all-features -- --test-threads=1
cargo build --profile=release-with-debug

)

mkdir -p target/release
Expand All @@ -12,10 +14,31 @@ gcc -Wall -fPIC -shared \
-Os \
-o target/release/libmodality_ros_hook.so \
ld_preload_shim.c \
-Irmw/rmw/include \
-Ircutils/include \
-Irosidl/rosidl_runtime_c/include \
-Irosidl/rosidl_typesupport_introspection_c/include \
-Irosidl/rosidl_typesupport_interface/include \
${BINDGEN_EXTRA_CLANG_ARGS} \
-L modality-ros-hook/target/release-with-debug/ \
-ldl -lmodality_ros_hook_rust

record_package_version () {
local package=$1
echo "${package}" >> target/release/ros_deps
dpkg -s "${package}" | grep '^Version:' >> target/release/ros_deps
echo >> target/release/ros_deps
}

lsb_release -a >> target/release/ros_deps
echo >> target/release/ros_deps

uname -a >> target/release/ros_deps
echo >> target/release/ros_deps

record_package_version "libc-bin"
record_package_version "libc6-dev"
record_package_version "ros-humble-rcutils"
record_package_version "ros-humble-rcpputils"
record_package_version "ros-humble-rosidl-runtime-c"
record_package_version "ros-humble-rosidl-typesupport-interface"
record_package_version "ros-humble-rosidl-typesupport-introspection-c"
record_package_version "ros-humble-rmw"
record_package_version "ros-humble-fastrtps"
record_package_version "ros-humble-rmw-fastrtps-shared-cpp"
record_package_version "ros-humble-fastcdr"
20 changes: 20 additions & 0 deletions example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM modality-ros2-build

FROM ros:humble

RUN apt update
RUN apt upgrade -y
RUN apt install less vim ros-humble-demo-nodes-py psmisc -y
COPY --from=0 /src/target/release/libmodality_ros_hook.so /
COPY run.sh /

# RUN apt install xterm -y
# RUN apt install ros-humble-ros-ign-bridge ros-humble-robot-localization "ros-humble-nav2-*" -y
# RUN apt install ignition-fortress -y
# RUN apt install ros-humble-xacro ros-humble-ros-gz-sim ros-humble-rviz2 -y
#
# COPY run.sh /
# COPY nav2_outdoor_example /nav2_outdoor_example
# WORKDIR /nav2_outdoor_example
# RUN bash -c "source /opt/ros/humble/setup.bash && colcon build"
# WORKDIR /
13 changes: 13 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Make podman fast in debian: https://github.com/containers/podman/issues/13226
Running:
- source install/setup.bash
- ros2 launch nav2_outdoor_example bringup.launch.py

/opt/ros/humble/lib/demo_nodes_py/add_two_ints_client
/opt/ros/humble/lib/demo_nodes_py/add_two_ints_client_async
/opt/ros/humble/lib/demo_nodes_py/add_two_ints_server
/opt/ros/humble/lib/demo_nodes_py/listener
/opt/ros/humble/lib/demo_nodes_py/listener_qos
/opt/ros/humble/lib/demo_nodes_py/listener_serialized
/opt/ros/humble/lib/demo_nodes_py/talker
/opt/ros/humble/lib/demo_nodes_py/talker_qos
64 changes: 64 additions & 0 deletions example/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "generic/ubuntu2204"
config.vagrant.plugins = "vagrant-libvirt"

config.vm.provider "libvirt" do |lv|
lv.memory = "8192"
lv.cpus = 16
end

config.vm.provision "shell", inline: <<-SHELL
apt-get install -y software-properties-common curl
curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null
apt-add-repository universe
apt-get update
apt-get upgrade -y
apt-get install -y apache2 locales ros-humble-ros-base ros-dev-tools ros-humble-desktop "ros-humble-ament-*" ros-humble-xacro ros-humble-ros-gz-sim ros-humble-ros-gz-bridge -y
locale-gen en_US en_US.UTF-8
update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
LANG=en_US.UTF-8
SHELL

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"

# Disable the default share of the current code directory. Doing this
# provides improved isolation between the vagrant box and your host
# by making sure your Vagrantfile isn't accessible to the vagrant box.
# If you use this you may want to enable additional shared subfolders as
# shown above.
# config.vm.synced_folder ".", "/vagrant", disabled: true

end
16 changes: 16 additions & 0 deletions example/go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set -e

(
cd ..
./build-in-docker.sh
)

if ! docker image exists ros:humble; then
docker pull docker.io/ros:humble
fi
docker build . -t modality-ros2-example
docker run -it --rm \
--net=host \
-v ~/.config/modality_cli:/root/.config/modality_cli \
modality-ros2-example \
/run.sh
Loading

0 comments on commit 9692030

Please sign in to comment.