Skip to content

Commit

Permalink
Merge branch 'develop-ros-dockerfile' into develop. Close #136.
Browse files Browse the repository at this point in the history
**Description**

Ogma doesn't currently generate a Dockerfile with the ROS packages. That
makes it harder for users to know how to use the produce of Copilot.

**Type**

- Feature: Complementing new feature.

**Additional context**

None.

**Requester**

- Ivan Perez

**Method to check presence of bug**

Not applicable (not a bug).

**Expected result**

Running the ROS command should produce a Dockerfile with the ROS package
that can be used to compile the package.

**Proposed solution**

Add a dockerfile to the list of files produced.

Modify the README to document how to use the generated file.

Introduce a new CI job that builds a demo using the ros backend and
compiles the result using the generated Dockerfile.

**Further notes**

None.
  • Loading branch information
ivanperez-keera committed May 21, 2024
2 parents 7fb0e25 + 5d226c9 commit 9709229
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 11 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/repo-ghc-8.6-cabal-2.4-ros.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: ros-ghc-8.6-cabal-2.4

# Trigger the workflow on push or pull request
on:
- pull_request
- push

jobs:
cabal:
name: ${{ matrix.os }} / ghc ${{ matrix.ghc }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
cabal: ["2.4"]
ghc:
- "8.6"

steps:

- uses: haskell-actions/setup@main
id: setup-haskell-cabal
name: Setup Haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}

- name: Prepare environment
run: |
echo "$HOME/.ghcup/bin" >> $GITHUB_PATH
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
- uses: actions/checkout@v4

- name: Create sandbox
run: |
echo "$PWD/.cabal-sandbox/bin" >> $GITHUB_PATH
cabal v1-sandbox init
- name: Install dependencies
run: |
cabal v1-install alex happy
- name: Install ogma
run: |
cabal v1-install copilot ogma-**/ --constraint="copilot >= 3.19.1"
- name: Generate ROS app
run: |
ogma ros --app-target-dir demo --variable-db ogma-cli/examples/ros-copilot/vars-db --variable-file ogma-cli/examples/ros-copilot/variables --handlers-file ogma-cli/examples/ros-copilot/handlers
cabal v1-exec -- runhaskell ogma-cli/examples/ros-copilot/ROS.hs
find demo/
cd demo/
docker build .
4 changes: 3 additions & 1 deletion ogma-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Revision history for ogma-cli

## [1.X.X] - 2024-05-19
## [1.X.X] - 2024-05-20

* Introduce CI test job (#139).
* Introduce test job for ROS package generation (#136).

## [1.3.0] - 2024-03-21

Expand Down
20 changes: 15 additions & 5 deletions ogma-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,21 @@ $ ogma ros --handlers filename --variable-file variables --variable-db ros-varia

The application generated by Ogma contains the following files:
```
ros_demo/CMakeLists.txt
ros_demo/src/copilot_monitor.cpp
ros_demo/src/copilot_logger.cpp
ros_demo/src/.keep
ros_demo/package.xml
ros_demo/copilot/CMakeLists.txt
ros_demo/copilot/src/copilot_monitor.cpp
ros_demo/copilot/src/copilot_logger.cpp
ros_demo/copilot/src/.keep
ros_demo/copilot/package.xml
ros_demo/Dockerfile
```

The Dockerfile can be used to compile the application inside the base image for
the Space ROS distribution. To build the image, first place the core
implementation of the monitors in C inside the directory
`ros_demo/copilot/src/` (see 'Current limitations' for details). After, you can
compile the image with:
```
docker build .
```

### Current limitations
Expand Down
20 changes: 20 additions & 0 deletions ogma-cli/examples/ros-copilot/ROS.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Copilot.Compile.C99
import Copilot.Language
import Language.Copilot (reify)
import Prelude hiding (not, (>=))

inputSignal :: Stream Int64
inputSignal = extern "input_signal" Nothing

propTestCopilot :: Stream Bool
propTestCopilot = inputSignal >= 5

spec :: Spec
spec = do
trigger "handlerTestCopilot" (not propTestCopilot) []

main :: IO ()
main = reify spec >>= compileWith settings "monitor"
where
settings = mkDefaultCSettings
{ cSettingsOutputDirectory = "demo/copilot/src/" }
1 change: 1 addition & 0 deletions ogma-cli/examples/ros-copilot/handlers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
handlerTestCopilot
1 change: 1 addition & 0 deletions ogma-cli/examples/ros-copilot/variables
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
input_signal
1 change: 1 addition & 0 deletions ogma-cli/examples/ros-copilot/vars-db
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
("input_signal","int64_t","/demo/topic","int64_t")
4 changes: 4 additions & 0 deletions ogma-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Revision history for ogma-core

## [1.X.X] - 2024-05-20

* Make ros command generate dockerfile (#136).

## [1.3.0] - 2024-03-21

* Version bump 1.3.0 (#133).
Expand Down
7 changes: 4 additions & 3 deletions ogma-core/ogma-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ data-files: templates/copilot-cfs/CMakeLists.txt
templates/copilot-cfs/fsw/src/copilot_cfs_version.h
templates/copilot-cfs/fsw/src/copilot_cfs.h
templates/copilot-cfs/fsw/src/copilot_cfs_events.h
templates/ros/CMakeLists.txt
templates/ros/src/.keep
templates/ros/package.xml
templates/ros/Dockerfile
templates/ros/copilot/CMakeLists.txt
templates/ros/copilot/src/.keep
templates/ros/copilot/package.xml
templates/fprime/CMakeLists.txt
templates/fprime/Dockerfile
templates/fprime/instance-copilot
Expand Down
4 changes: 2 additions & 2 deletions ogma-core/src/Command/ROSApp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ rosApp' targetDir varNames varDB monitors =
foldr f ([], [], [], []) varNames

let rosFileName =
targetDir </> "src" </> "copilot_monitor.cpp"
targetDir </> "copilot" </> "src" </> "copilot_monitor.cpp"
rosFileContents =
unlines $
rosMonitorContents varNames vars ids infos datas monitors

writeFile rosFileName rosFileContents

let rosFileName =
targetDir </> "src" </> "copilot_logger.cpp"
targetDir </> "copilot" </> "src" </> "copilot_logger.cpp"
rosFileContents =
unlines $
rosLoggerContents varNames vars ids infos datas monitors
Expand Down
16 changes: 16 additions & 0 deletions ogma-core/templates/ros/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM osrf/space-ros:latest

ARG USER=spaceros-user
ARG PACKAGE_PATH=/home/${USER}/monitors
ARG ROS_PATH=/home/${USER}/spaceros/

RUN mkdir -p ${PACKAGE_PATH}/src/
ADD copilot ${PACKAGE_PATH}/src/copilot
USER root
RUN chown -R ${USER} ${PACKAGE_PATH}
USER ${USER}

SHELL ["/bin/bash", "-c"]
WORKDIR ${PACKAGE_PATH}
RUN source ${ROS_PATH}/install/setup.bash && \
colcon build
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9709229

Please sign in to comment.