Skip to content
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

Adding racs2 /cfs-ros2 bridge demo by JAXA on spaceros #81

Open
wants to merge 1 commit 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
53 changes: 53 additions & 0 deletions racs2_demos_on_spaceros/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.8)
project(mars_rover)

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(ament_cmake_python REQUIRED)
find_package(control_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(rclpy REQUIRED)
find_package(simulation REQUIRED)
find_package(std_msgs REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

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()

install(DIRECTORY
config
launch
worlds
DESTINATION share/${PROJECT_NAME}
)

ament_python_install_package(${PROJECT_NAME})

install(PROGRAMS
nodes/move_arm
nodes/move_mast
nodes/move_wheel
nodes/run_demo
nodes/odom_tf_publisher
nodes/RACS2Bridge_geometry_msgs_pb2.py
DESTINATION lib/${PROJECT_NAME}
)

ament_package()
142 changes: 142 additions & 0 deletions racs2_demos_on_spaceros/Dockerfile
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few suggestions for this Dockerfile, but generally I'm conflicted about how this is organized.

I appreciate that this goes step by step and documents how to use the RACS2 bridge, but there is a lot more file manipulation here than I would typically expect from a Dockerfile.
Since this is a demo I suppose this doesn't need to be productionized and is better off as it is now as documentation?

I think I'd feel better about having all of the code existing in the repository with this file manipulation done before-hand if this process was also documented elsewhere and referenced in this codebase (e.g. in the README or as a comment here). However, I understand that could be a lot more additional work, so I'm happy either way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have modified the pull request as suggested to reduce the number of clone operations in the Dockerfile, making it simpler. This should align better with typical Dockerfile practices while still providing step-by-step documentation for the RACS2 bridge.

Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# A Docker configuration script to build the Space ROS image.
#
# The script provides the following build arguments:
#
# VCS_REF - The git revision of the Space ROS source code (no default value).
# VERSION - The version of Space ROS (default: "preview")

FROM openrobotics/space_robots_demo:latest

# Define arguments used in the metadata definition
ARG VCS_REF
ARG VERSION="preview"

# Specify the docker image metadata
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.name="RACS2 demo on Curiosity Rover"
LABEL org.label-schema.description="RACS2 demo on the Space ROS platform"
LABEL org.label-schema.vendor="JAXA"
LABEL org.label-schema.version=${VERSION}
LABEL org.label-schema.url="https://github.com/space-ros"
LABEL org.label-schema.vcs-url="https://github.com/space-ros/docker"
LABEL org.label-schema.vcs-ref=${VCS_REF}

# Define a few key variables
ENV RACS2_DEMO_DIR=${HOME_DIR}/racs2_ws

# Disable prompting during package installation
ARG DEBIAN_FRONTEND=noninteractive

# Get rosinstall_generator
# Using Docker BuildKit cache mounts for /var/cache/apt and /var/lib/apt ensures that
# the cache won't make it into the built image but will be maintained between steps.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update -y && sudo apt-get install -y python3-rosinstall-generator

RUN mkdir -p ${RACS2_DEMO_DIR}
WORKDIR ${RACS2_DEMO_DIR}

# Install dependencies
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get install libwebsockets-dev libwebsockets-dev protobuf-c-compiler libprotobuf-c-dev python3-pip tmux gdb -y
RUN python3 -m pip install protobuf==3.20.0 websockets==12.0

# Get the cFS source code
RUN git clone --recursive -b v6.7.0a https://github.com/nasa/cFS/ cfs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of all of this git cloneing in the Dockerfile, I've learned that this can cause issues since Docker doesn't know when to invalidate the layer cache when the upstream changes.

It would be nice if these repositories were a git submodule, downloaded via vcs before the Dockerfile is run, or at the very least, uses the ADD Dockerfile instruction .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this kind of clone is fine in this case because we are cloning a specific tag. The code won't change unless the tag changes, and that shouldn't happen because it's a release tag.

If it was a rolling HEAD, then I agree that we might want to do it differently.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Ivan suggested I did not change on this.

WORKDIR ${RACS2_DEMO_DIR}/cfs
RUN git submodule init
RUN git submodule update

# Get the RACS2 source code
WORKDIR ${RACS2_DEMO_DIR}
RUN git clone https://github.com/jaxa/racs2_bridge -b v1.1

# Get the demo source code
# rename old demo directory and exclude from build
WORKDIR ${DEMO_DIR}/src
# RUN mv demos demos_old
RUN cp -r demos demos_old
RUN touch demos_old/COLCON_IGNORE
# git clone new demo
# RUN git clone https://github.com/tt-saito/demos.git -b racs2_demo2
# RUN git clone https://github.com/space-ros/demos

# Customize cFS to run the bridge
WORKDIR ${RACS2_DEMO_DIR}/cfs
RUN cp cfe/cmake/Makefile.sample Makefile
RUN cp -r cfe/cmake/sample_defs sample_defs
RUN cp -pr ${RACS2_DEMO_DIR}/racs2_bridge/cFS/Bridge/Client_C/apps/racs2_bridge_client apps/

# Deploy the run_app application and adjust the startup scripts
# RUN cp -pr ${DEMO_DIR}/src/demos/racs2_demos_on_spaceros/cFS/sample_defs/* ${RACS2_DEMO_DIR}/cfs/sample_defs/
# RUN cp -pr ${DEMO_DIR}/src/demos/racs2_demos_on_spaceros/cFS/apps/run_app ${RACS2_DEMO_DIR}/cfs/apps/
COPY cFS/sample_defs/cpu1_cfe_es_startup.scr ${RACS2_DEMO_DIR}/cfs/sample_defs/cpu1_cfe_es_startup.scr
COPY cFS/sample_defs/racs2_bridge_config.txt ${RACS2_DEMO_DIR}/cfs/sample_defs/racs2_bridge_config.txt
COPY cFS/sample_defs/targets.cmake ${RACS2_DEMO_DIR}/cfs/sample_defs/targets.cmake
COPY cFS/apps/run_app ${RACS2_DEMO_DIR}/cfs/apps/run_app

# This is necessary to run cFS inside docker
RUN sed -i -e 's/^#undef OSAL_DEBUG_PERMISSIVE_MODE/#define OSAL_DEBUG_PERMISSIVE_MODE 1/g' sample_defs/default_osconfig.h
RUN sed -i -e 's/^#undef OSAL_DEBUG_DISABLE_TASK_PRIORITIES/#define OSAL_DEBUG_DISABLE_TASK_PRIORITIES 1/g' sample_defs/default_osconfig.h

# This is only needed because docker by default starts in IPv4. This setting
# is specific to the JAXA bridge.
RUN sed -i -e 's/^wss_uri=.*/wss_uri=127.0.0.1/g' sample_defs/racs2_bridge_config.txt

# Compile cFS
RUN make SIMULATION=native prep
RUN make
RUN make install

# Prepare ROS packages
WORKDIR ${DEMO_DIR}
# Copy bridge & racs2_msg node
RUN cp -pr ${RACS2_DEMO_DIR}/racs2_bridge/ROS2/Bridge/Server_Python/bridge_py_s src/
RUN cp -pr ${RACS2_DEMO_DIR}/racs2_bridge/Example/Case.1/ROS2/racs2_msg src/


COPY CMakeLists.txt ${DEMO_DIR}/src/demos/mars_rover/CMakeLists.txt
COPY package.xml ${DEMO_DIR}/src/demos/mars_rover/package.xml
# COPY racs2_demos_on_spaceros ${DEMO_DIR}/src/demos/mars_rover/racs2_demos_on_spaceros
COPY launch/mars_rover.launch.py ${DEMO_DIR}/src/demos/mars_rover/launch/mars_rover.launch.py
COPY nodes/RACS2Bridge_geometry_msgs_pb2.py ${DEMO_DIR}/src/demos/mars_rover/nodes/RACS2Bridge_geometry_msgs_pb2.py
COPY nodes/move_wheel ${DEMO_DIR}/src/demos/mars_rover/nodes/move_wheel




# Install dependencies
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
sudo apt-get update -y \
&& /bin/bash -c 'source "${SPACEROS_DIR}/install/setup.bash"' \
&& /bin/bash -c 'source "${MOVEIT2_DIR}/install/setup.bash"' \
&& rosdep install --from-paths src --ignore-src -r -y --rosdistro ${ROS_DISTRO}

# Build the demo
RUN /bin/bash -c 'source ${SPACEROS_DIR}/install/setup.bash && source ${MOVEIT2_DIR}/install/setup.bash \
&& colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release'

# Add the user to the render group so that the user can access /dev/dri/renderD128
RUN sudo usermod -aG render $USERNAME

# Setup the entrypoint
COPY ./entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
93 changes: 93 additions & 0 deletions racs2_demos_on_spaceros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# RACS2 on Space ROS and Space Robots Demo Docker Image

The RACS2 on Space ROS and Space Robots Demo docker image uses the space_robots demo docker image (*openrobotics/space_robots_demo:latest*) as its base image.
Build instructions for that image can be found in [this README](../space_robots/README.md).
The Dockerfile installs all of the prerequisite system dependencies along with the demos source code, then builds the Space ROS Space Robots and RACS2 demo.

This is RACS2 Bridge demo for Curiosity Mars rover.

## Building the Demo Docker

The demo image builds on top of the `spaceros`, `moveit2`, `space_robots` images.
To build the docker image, first ensure the `spaceros` base image is available either by [building it locally](https://github.com/space-ros/space-ros) or pulling it.

Then build the `moveit2`, `space_robots` and `racs2_demos_on_spaceros` demo images:

```bash
git clone https://github.com/space-ros/docker.git
cd docker/moveit2
./build.sh
cd ../space_robots
./build.sh
cd ../../
./build.sh
```

## Running the Demo Docker

(at /path/to/demos/racs2_demos_on_spaceros/docker/racs2_demos_on_spaceros)
run the following to allow GUI passthrough:
```bash
xhost +local:docker
```

Then run:
```bash
./run.sh
```

Depending on the host computer, you might need to remove the ```--gpus all``` flag in ```run.sh```, which uses your GPUs.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see the --gpus flag in the run file. Should this be "you might want to add --gpus all..."


## Running the Demos

### Curiosity Mars rover demo
Launch the rover demo (calling Terminal 1):
```bash
source install/setup.bash
ros2 launch mars_rover mars_rover.launch.py
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI I'm on apple silicone using a VM and I had to set an environment variable to enable software rendering in order to get his working.

export LIBGL_ALWAYS_SOFTWARE=1

@ivanperez-keera Do we have a good place to document this. As far as I'm aware, this affects any gazebo simulation for setups like mine.
gazebosim/gz-sim#1841 (comment)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the most appropriate place for platform support notes like this is probably https://github.com/space-ros/docs

```

#### RACS2 Bridge demo

##### Running racs2 bridge node
Open a new terminal (calling Terminal 2) and attach to the currently running container:

```bash
docker exec -it <container-name> bash
source install/setup.bash
ros2 run bridge_py_s bridge_py_s_node --ros-args --params-file ./src/bridge_py_s/config/params.yaml
```

##### Running cFS bridge app & run_app app
Open a new terminal (calling Terminal 3) and attach to the currently running container:

```bash
docker exec -it <container-name> bash
cd ~/racs2_ws
cd cfs/build/exe/cpu1/
./core-cpu1
```

**Executing commands to the rover must be done with this terminal active.**


##### Available Commands

Drive commands to the rover are input via keyboard in Terimnal 3. The keymap is as follows.

* "w": Drive the rover forward
* "s": Drive the rover backward
* "a": Turn left
* "d": Turn right
* "x": Stop the rover

##### Nodes
![RACS2 demo on Space ROS Mars rover demo](racs2_demo_on_spaceros_nodes.png)

## Reference

* [RACS2 bridge project by Japan Aerospace Exploration Agency (JAXA)](https://github.com/jaxa/racs2_bridge)

* [Hiroki Kato and Tatsuhiko Saito, "RACS2: the ROS2 and cFS System - launched" Flight Software Workshop 2023.](https://drive.google.com/drive/folders/1C9fokWGDl2e4NfgX_ZU3f98FfPe9udwQ)

* [Hiroki Kato and Tatsuhiko Saito, "ROS and cFS System (RACS): Easing Space Robotic Development post-opensource activities and ROS2 integration" Flight Software Workshop 2021.](https://drive.google.com/file/d/11L48doT_pRNs7R0hdChPALqJO849TvV2/view?usp=drive_web)
23 changes: 23 additions & 0 deletions racs2_demos_on_spaceros/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

ORG=jaxa
IMAGE=racs2_demos_on_spaceros
TAG=latest

VCS_REF=""
VERSION=preview

# Exit script with failure if build fails
set -eo pipefail

echo ""
echo "##### Building RACS2 Demo on Space ROS Docker Image #####"
echo ""

docker build -t $ORG/$IMAGE:$TAG \
--build-arg VCS_REF="$VCS_REF" \
--build-arg VERSION="$VERSION" .

echo ""
echo "##### Done! #####"

15 changes: 15 additions & 0 deletions racs2_demos_on_spaceros/cFS/apps/run_app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.6.4)
project(CFE_RUN_APP C)

include_directories(fsw/mission_inc)
include_directories(fsw/platform_inc)

aux_source_directory(fsw/src APP_SRC_FILES)

# Create the app module
add_cfe_app(run_app ${APP_SRC_FILES})

target_link_libraries(run_app
${PROTOBUF_LIBRARY}
protobuf-c
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef _run_app_perfids_h_
#define _run_app_perfids_h_


#define SAMPLE_APP_PERF_ID 91

#endif /* _run_app_perfids_h_ */
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _run_app_msgids_h_
#define _run_app_msgids_h_

#define RUN_APP_CMD_MID 0x1892
#define RUN_APP_SEND_HK_MID 0x1893
#define RUN_APP_HK_TLM_MID 0x0893
#define RACS2_BRIDGE_MID 0x1EFE

#endif /* _run_app_msgids_h_ */
Loading