Skip to content

Commit

Permalink
added racs2_demos_on_spaceros jaxa's demo (Issue #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyuqq committed Feb 4, 2025
1 parent 981bd60 commit 3458c2a
Show file tree
Hide file tree
Showing 36 changed files with 3,638 additions and 0 deletions.
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
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
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.

## 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
```

#### 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

0 comments on commit 3458c2a

Please sign in to comment.