Skip to content

Commit

Permalink
Support services
Browse files Browse the repository at this point in the history
  • Loading branch information
mullr committed Apr 3, 2024
1 parent 8d4b8a2 commit d1ef2fd
Show file tree
Hide file tree
Showing 42 changed files with 2,099 additions and 566 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
25 changes: 18 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: moonrepo/setup-rust@v0

- name: Install stable rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
toolchain: stable

- name: Clippy
working-directory: modality-ros-hook
Expand All @@ -25,21 +30,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: moonrepo/setup-rust@v0

- name: Install stable rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Debug build
working-directory: modality-ros-hook
run: cargo build
run: ./build-debug.sh

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

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

- name: Install stable rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Test
working-directory: modality-ros-hook
Expand Down
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.
13 changes: 13 additions & 0 deletions build-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set -e

if ! docker image exists ros:humble; then
docker pull docker.io/ros:humble
fi

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
32 changes: 26 additions & 6 deletions build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set -e
(
cd modality-ros-hook
cargo build --profile=release-with-debug

)

mkdir -p target/release
Expand All @@ -12,10 +11,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"
1 change: 1 addition & 0 deletions example/.vagrant/bundler/global.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"dependencies":[["racc",["~> 1.4"]],["nokogiri",["~> 1.6"]],["diffy",[">= 0"]],["rexml",[">= 0"]],["xml-simple",[">= 0"]],["mime-types-data",["~> 3.2015"]],["mime-types",[">= 0"]],["formatador",[">= 0.2","< 2.0"]],["excon",["~> 0.71"]],["builder",[">= 2.1.2"]],["fog-core",["~> 2"]],["json",[">= 0"]],["ruby-libvirt",[">= 0.7.0"]],["fog-xml",["~> 0.1.1"]],["multi_json",["~> 1.14"]],["fog-json",[">= 0"]],["fog-libvirt",[">= 0.6.0"]],["vagrant-libvirt",["= 0.12.2"]],["rubyntlm",["~> 0.6.0",">= 0.6.3"]],["nori",["~> 2.0"]],["little-plugger",["~> 1.1"]],["logging",[">= 1.6.1","< 3.0"]],["httpclient",["~> 2.2",">= 2.2.0.2"]],["gyoku",["~> 1.0"]],["ffi",[">= 1.0.1"]],["gssapi",["~> 1.2"]],["erubi",["~> 1.8"]],["winrm",["= 2.3.6"]],["rubyzip",["~> 2.0"]],["winrm-fs",["= 1.3.5"]],["winrm-elevated",["= 1.2.3"]]],"checksum":"4cadc14fadbdf591c69ed73b0f547abcd37c91c0223f8122682438aac7c3e94b","vagrant_version":"2.4.1"}
1 change: 1 addition & 0 deletions example/.vagrant/machines/default/libvirt/action_provision
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.5:f6788d93-bb81-4e14-a06f-08cdb92983ca
1 change: 1 addition & 0 deletions example/.vagrant/machines/default/libvirt/box_meta
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"generic/ubuntu2204","version":"4.3.12","provider":"libvirt","directory":"boxes/generic-VAGRANTSLASH-ubuntu2204/4.3.12/amd64/libvirt"}
1 change: 1 addition & 0 deletions example/.vagrant/machines/default/libvirt/created_networks
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
73ca022a-b7e4-4386-9b0b-f45ba1862a03
1 change: 1 addition & 0 deletions example/.vagrant/machines/default/libvirt/creator_uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1000
1 change: 1 addition & 0 deletions example/.vagrant/machines/default/libvirt/id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f6788d93-bb81-4e14-a06f-08cdb92983ca
1 change: 1 addition & 0 deletions example/.vagrant/machines/default/libvirt/index_uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8926bfed4fd544c0acd5f238e2f81718
8 changes: 8 additions & 0 deletions example/.vagrant/machines/default/libvirt/private_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAA
AAtzc2gtZWQyNTUxOQAAACA9fOlEFeuZAJxESa87IeALdO5wyy9xwaV8tpr+
AG5sAAAAAJC3AyCytwMgsgAAAAtzc2gtZWQyNTUxOQAAACA9fOlEFeuZAJxE
Sa87IeALdO5wyy9xwaV8tpr+AG5sAAAAAECmzz3lbDPaJSwYjRuUEQU5X1eq
0aoshxoJYJ8EaHqZ+D186UQV65kAnERJrzsh4At07nDLL3HBpXy2mv4AbmwA
AAAAB3ZhZ3JhbnQBAgMEBQY=
-----END OPENSSH PRIVATE KEY-----
1 change: 1 addition & 0 deletions example/.vagrant/machines/default/libvirt/synced_folders
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions example/.vagrant/machines/default/libvirt/vagrant_cwd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/home/mullr/devel/modality-ros2/example
12 changes: 12 additions & 0 deletions example/.vagrant/rgloader/loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

# This file loads the proper rgloader/loader.rb file that comes packaged
# with Vagrant so that encoded files can properly run with Vagrant.

if ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]
require File.expand_path(
"rgloader/loader", ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"])
else
raise "Encoded files can't be read outside of the Vagrant installer."
end
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
1 change: 1 addition & 0 deletions example/nav2_outdoor_example
Submodule nav2_outdoor_example added at 0b7eee
Loading

0 comments on commit d1ef2fd

Please sign in to comment.