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

NASA Challenge_[@minahilrz]_[JAXA RACS2 Bridge Demo] (Closes space-ros#26) #45

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
71 changes: 71 additions & 0 deletions jaxa_integration/Dockerfile.jaxa_spaceros_cfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -----------------------------------------------------------------------------
# Dockerfile for setting up an environment with Space ROS and cFS
# Author: Minahil Raza
# Date: [email protected]
# -----------------------------------------------------------------------------

FROM osrf/space-ros:latest

# Set environment variables
ENV JAXA_BRIDGE_DIR=/tmp/racs2_bridge
ENV CFS_DIR=${HOME_DIR}/cfs

# Install dependencies for the ROS - cFS bridge
RUN sudo apt-get install -y libwebsockets-dev protobuf-c-compiler libprotobuf-c-dev python3-pip git \
&& pip3 install protobuf websockets

# Set working directory and clone the JAXA bridge repository
WORKDIR ${HOME_DIR}
RUN git clone https://github.com/jaxa/racs2_bridge ${JAXA_BRIDGE_DIR}

# Prepare cFS

## Clone cFS repository
RUN git clone --recursive -b v6.7.0a https://github.com/nasa/cFS/ ${CFS_DIR}
WORKDIR ${CFS_DIR}
RUN git submodule init \
&& git submodule update

## Customize cFS to run the bridge
RUN cp cfe/cmake/Makefile.sample Makefile \
&& cp -r cfe/cmake/sample_defs sample_defs \
&& cp -pr ${JAXA_BRIDGE_DIR}/cFS/Bridge/Client_C/apps/racs2_bridge_client ${CFS_DIR}/apps/

# Uncomment the following line if you only want the bridge and not the sample app.
# RUN cp -p ${JAXA_BRIDGE_DIR}/cFS/Bridge/Client_C/sample_defs/* ${CFS_DIR}/sample_defs/

## Deploy the sample talker application and adjust the startup scripts
RUN cp -pr ${JAXA_BRIDGE_DIR}/Example/Case.1/cFS/sample_defs/* ${CFS_DIR}/sample_defs/
COPY ./cFS_app_examples/space_robots/cfs_app/sample_talker ${CFS_DIR}/apps/sample_talker

## Adjust settings for running 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 \
&& sed -i -e 's/^#undef OSAL_DEBUG_DISABLE_TASK_PRIORITIES/#define OSAL_DEBUG_DISABLE_TASK_PRIORITIES 1/g' sample_defs/default_osconfig.h \
&& 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 \
&& make \
&& make install

# Prepare ROS packages

## Create ROS workspace
WORKDIR ${HOME_DIR}
RUN mkdir -p ros2-project/src

## Copy bridge and example packages into the workspace
RUN cp -pr ${JAXA_BRIDGE_DIR}/ROS2/Bridge/Server_Python/bridge_py_s ${HOME_DIR}/ros2-project/src/
COPY ./racs2_msg ${HOME_DIR}/ros2-project/src/racs2_msg

## Compile and install ROS 2 packages
WORKDIR ${HOME_DIR}/ros2-project
SHELL ["/bin/bash", "-c"]
RUN source ${HOME_DIR}/spaceros/install/setup.bash && colcon build --symlink-install

## Adjust configuration for the JAXA bridge (IPv4 settings)
RUN sed -i -e 's/wss_uri:.*/wss_uri: "127.0.0.1"/g' ./src/bridge_py_s/config/params.yaml

# Set the default shell in screen to bash
RUN echo "defshell -bash" > ${HOME_DIR}/.screenrc

23 changes: 23 additions & 0 deletions jaxa_integration/Dockerfile.jaxa_spaceros_listener
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM osrf/space-ros:latest

# Define key locations
ENV JAXA_ROS_DIR=${HOME_DIR}/jaxa_comm_ws
ENV JAXA_COMM_DIR=${JAXA_ROS_DIR}/src/jaxa_comm_spaceros
ENV JAXA_MSG_DIR=${JAXA_ROS_DIR}/src/racs2_msg

# Copy package files for jaxa bridge
RUN mkdir -p $JAXA_COMM_DIR
COPY --chown=${USERNAME}:${USERNAME} ./jaxa_comm_spaceros $JAXA_COMM_DIR
RUN mkdir -p $JAXA_MSG_DIR
COPY --chown=${USERNAME}:${USERNAME} ./racs2_msg $JAXA_MSG_DIR

# install protobuf
RUN pip install protobuf==3.20.1

# Build packages
WORKDIR ${JAXA_ROS_DIR}

RUN /bin/bash -c 'source ${SPACEROS_DIR}/install/setup.bash \
&& colcon build'

CMD ["bash"]
135 changes: 135 additions & 0 deletions jaxa_integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# JAXA RACS2 Bridge Demo

This demo demonstrates the use of the [RACS2](https://github.com/jaxa/racs2_bridge) (ROS and cFS System 2) Bridge to facilitate communication between {Space ROS](https://github.com/space-ros) and [Core Flight Executives (cFE)](https://github.com/nasa/cFE). The cFE is a core component of NASA-supplied spacecraft software, the [Core Flight System (CFS)](https://github.com/nasa/cFS).

This code is a part of the following challenge:
- Challenge Name: NASA Space ROS Sim Summer Sprint Challenge
- Team Lead Freelancer Username: minahilrz
- Submission Title: JAXA RACS2 Bridge Demo

## Directory Overview

- **jaxa_comm_spaceros**: A ROS2 package for communication over the bridge. This ROS2 package allows spawning listener nodes to receive messages over the RACS2 Bridge.
- **racs2_msg**: A ROS2 package containing message definitions for communication between ROS2 and cFS.
- **cFS_app_examples**: Example apps for cFS.
- **Dockerfile.jaxa_spaceros_cfs**: Dockerfile for building the `jaxa_spaceros_cfs` container. It uses the spaceros image as its base.
- **Dockerfile.jaxa_spaceros_listener**: Dockerfile for building the `jaxa_spaceros_listener` container. It uses the spaceros image as its base.
- **run_jaxa_spaceros_cfs.sh**: Script to run the `jaxa_spaceros_cfs` container.
- **run_jaxa_spaceros_listener.sh**: Script to run the `jaxa_spaceros_listener` container.
- **build.sh**: Script to build two Docker images: `jaxa_spaceros_listener` and `jaxa_spaceros_cfs`.


## Dependencies

To get started, ensure you have Docker Desktop installed on your system. This tutorial uses the Space ROS image, which can either be pulled from a registry or built locally.

## Build Instructions

To build the two necessary Docker containers, simply run the provided `build.sh` script:

```bash
./build.sh
```

Once completed, you will have two Docker images: **jaxa_spaceros_listener** and **jaxa_spaceros_cfs**.

## Usage Instructions
### Terminal 1: Start the cFS Container

To start the `jaxa_spaceros_cfs` container, run:
```bash
./run_jaxa_spaceros_cfs.sh
```

When the bash terminal for the container opens, execute the following commands to start the bridge nodes:
```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
```

### Terminal 2: Start the cFE Publisher
Connect to the same `jaxa_spaceros_cfs` container using
```bash
docker exec -it jaxa_spaceros_cfs bash
```

Now, run the following commands inside the container to send messages over the bridge:
```bash
cd ../cfs/build/exe/cpu1/
./core-cpu1
```

### Terminal 3: Start the Listener Node
The `jaxa_comm_spaceros` package provides different examples of listener nodes, including demos of interacting with the Curiosity Rover and Canadarm.

#### Example 1: Simple Listener Demo
In this example, a simple listener node is spawned which would receive the message and print it.

First, run the `jaxa_spaceros_listener` container using the following script:
```bash
./run_jaxa_spaceros_listener.sh
```

Then, run the following commands inside the container to start the listener node:
```bash
source install/setup.bash
ros2 run jaxa_comm_spaceros jaxa_simple_listener

```

#### Example 2: JAXA Bridge and Curiosity Rover Demo
In this example, the listener node receives numbers as messages from the cFS (commands) over the bridge and performs an action accordingly including moving and stopping the rover, turning the rover, opening and closing the tool arm or the mast.

You need to build the space_robots image or run the curiosity rover on your own machine prior to running this example by following the instructions in the [demos](https://github.com/space-ros/demos) and [docker](https://github.com/space-ros/docker/tree/main) repos.

Once you run the demo docker container, launch the demo using:
```bash
ros2 launch mars_rover mars_rover.launch.py
```

Then, run the `jaxa_spaceros_listener` container using the following script:
```bash
./run_jaxa_spaceros_listener.sh
```

Then, run the following commands inside the container to start the rover listener node:
```bash
source install/setup.bash
ros2 run jaxa_comm_spaceros jaxa_rover_listener

```

#### Example 3: JAXA Bridge and Canadarm Demo
In this example, the listener node receives numbers as messages from the cFS (commands) over the bridge and performs an action accordingly by calling services for the Canadarm.

Similar to example 2, you need to build the space_robots image or run the Canadarm demo on your own machine prior to running this example.

Once you run the demo docker container, launch the demo using:
```bash
ros2 launch canadarm canadarm.launch.py
```

Then, run the `jaxa_spaceros_listener` container using the following script:
```bash
./run_jaxa_spaceros_listener.sh
```

Then, run the following commands inside the container to start the canadarm listener node:
```bash
source install/setup.bash
ros2 run jaxa_comm_spaceros jaxa_canadarm_listener

```

## Architecture
The main design goal was to simulate a real life situation where the listener would be running pn a different machine as compared to the system running the cFS. Therefore, this demo builds and runs two separate containers. The system architecture is provided below.

![archiecture](images/architecture.png)

## Using the jaxa_comm_package in other projects
The communication package can be used in any system which has ROS2 or SpaceROS installed. Copy the package files into your own workspace and use colcon to build it.

## Notes
- When running ROS nodes inside docker containers, all the containers must be over the same network.
- The listener node can be run in the same spaceros container as the bridge and cFS. Two separate containers demonstrate a scenario where different systems are communicating over the RACS2 Bridge.

26 changes: 26 additions & 0 deletions jaxa_integration/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Define variables
APP1="jaxa_spaceros_cfs"
APP2="jaxa_spaceros_listener"

# Define Docker image names
IMAGE1="jaxa_spaceros_cfs"
IMAGE2="jaxa_spaceros_listener"

# Define Dockerfile names
DOCKERFILE1="Dockerfile.${APP1}"
DOCKERFILE2="Dockerfile.${APP2}"

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

# Build Docker images
echo "Building Docker image for ${APP1}..."
docker build -t $IMAGE1 -f $DOCKERFILE1 .

echo "Building Docker image for ${APP2}..."
docker build -t $IMAGE2 -f $DOCKERFILE2 .

echo "Docker images built successfully."

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 2.6.4)
project(CFE_SAMPLE_TALKER 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(sample_talker ${APP_SRC_FILES})

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


#define SAMPLE_APP_PERF_ID 91

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

#define SAMPLE_TALKER_CMD_MID 0x1892
#define SAMPLE_TALKER_SEND_HK_MID 0x1893
#define SAMPLE_TALKER_HK_TLM_MID 0x0893
#define RACS2_BRIDGE_MID 0x1EFE

#endif /* _sample_talker_msgids_h_ */
Loading
Loading