Skip to content

Commit

Permalink
Infrastructure for the new PSim (#231)
Browse files Browse the repository at this point in the history
* Restructuring for incoming PSim changes:
 - Removed Docker support.
 - Added a library.json file for better PIO support.
 - Migrate gnc tests and sources to a gnc subdirectory.
 - Refactored test names to be common across all modules.
 - Update the lin submodule and fixed issues with breaking changes.
 - Renamed the //:psim Bazel target to //:gnc
* Added the PSim configuration/parameter system
* Added the PSim state field system
* Added the PSim state registry
* Added the PSim model and simulation base classes
* Added the initial autocoder infrastructure and time model
  • Loading branch information
kylekrol authored Sep 20, 2020
1 parent 045ce39 commit 039b5f2
Show file tree
Hide file tree
Showing 94 changed files with 3,538 additions and 623 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build --cxxopt=-std=c++14
build --python_top=//:venv --incompatible_use_python_toolchains=false
21 changes: 0 additions & 21 deletions .github/workflows/bazel.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/main.yml → .github/workflows/gnc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PSim Regression Tests
name: GNC Regression Tests

on:
pull_request:
Expand All @@ -11,6 +11,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: 'recursive'

- uses: actions/setup-python@v1
with:
python-version: '3.7'
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/psim.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: PSim Regression Tests

on:
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: 'recursive'

- uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: 'x64'

- name: Install dependencies
run: |
sudo apt-get install bazel
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
- name: Build and Test
run: |
bazel build //:gnc
bazel build //:psim
bazel test //test/psim:ci
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,6 @@ bazel-out
bazel-psim
bazel-testlogs
bazel-genfiles

# Compiler commands from Bazel
compile_commands.json
76 changes: 70 additions & 6 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,75 @@
load("@rules_python//python:defs.bzl", "py_runtime", "py_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")

load("//:tools/psim.bzl", "psim_autocode")

# Build flight software's gnc code as a library.
cc_library(
name = "gnc",
srcs = glob([
"src/gnc/**/*.hpp", "src/gnc/*.cpp", "src/gnc/**/*.inl",
"include/gnc/**/*.inl"
]),
hdrs = glob([
"include/gnc/**/*.hpp", "include/orb/*.h", "include/orb/*.hpp"
]),
includes = ['include'],
copts = ['-Isrc'],
linkstatic = True,
visibility = ["//visibility:public"],
deps = ["@lin//:lin"],
)

# Let bazel know about our virtual environment.
#
# Also see additional options passed with .bazelrc to ensure we're using the
# virtual environment.
#
# TODO : This is a little hacky and could be cleaned up with toolchains.
py_runtime(
name = "venv",
files = glob(["venv/**"], exclude=["venv/**/* *"]),
interpreter = "venv/bin/python",
python_version = "PY3",
visibility = ["//visibility:private"],
)

# Register the autocoder as an executable.
#
# This is later consumed by the autocoder command. See psim.bzl for more
# information.
py_binary(
name = "autocoder",
srcs = ["tools/autocoder.py"],
srcs_version = "PY3",
visibility = ["//visibility:private"],
)

# Autocode the model interfaces
psim_autocode(
name = "autocode",
srcs = glob(["include/psim/**/*.yml"]),
includes = ["include"],
tool = "//:autocoder",
visibility = ["//visibility:private"],
)

# Build all PSim models as a library
#
# This will be linked with executables later on.
cc_library(
name = "psim",
srcs = glob(["src/**/*.cpp", "src/**/*.inl", "src/**/*.hpp", "include/**/*.inl"], exclude=["src/targets/*.cpp"]),
hdrs = glob(["include/**/*.hpp", "include/**/*.h"]),
copts = ["-Iinclude -Isrc"],
srcs = glob([
"src/psim/**/*.hpp", "src/psim/**/*.inl", "src/psim/**/*.cpp",
"include/psim/**/*.inl", "include/psim/**/*.yml.hpp",
]),
hdrs = glob(
["include/psim/**/*.hpp"],
exclude = ["include/psim/**/*.yml.hpp"],
),
includes = ["include"],
copts = ["-Isrc"],
linkstatic = True,
visibility = ["//visibility:public"],
deps = [
"@lin//:lin",
]
deps = ["@lin//:lin", "//:gnc", "//:autocode"],
)
24 changes: 0 additions & 24 deletions Dockerfile

This file was deleted.

68 changes: 61 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,74 @@

# PSim

This repository will hold all GNC code for the PAN mission. It will largely be
comprised of the two main executables/modules:
This repository holds all GNC code for the PAN mission. It will be comprised of
two main modules:

1. MATLAB simulation to support GNC algorithm development.
2. C++ versions of all flight GNC algorithms.
1. GNC algorithms and utility functions implemented in C++ that will be
used by flight software and our internal simulation - PSim.
2. PSim models and simulation implementations.

See folder specific READMEs for more information.
MATLAB code listed in `MATLAB/**` is deprecated and will be phased out by the
new C++ implementation of PSim.

## Running CXX Tests Locally
## Getting Setup

Perform the following from the root PSim directory and replace `python` in the following commands with whatver command matches Python 3.7:
For GNC development, it's only necessary to setup the PlatformIO development
environment. This requires setting up a local virtual environment as shown
below:

python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
pio platform install native

Officially, we support Python 3.7 (this is what continuous integration runs) but
you'll most likely have success with Python 3.6+.

You can ensure everything is behaving as expected by building and running tests
for the GNC code with:

source venv/bin/activate
pio test -e native

**_Note: Naming your virtual environment `venv` is required for PSim
development!_**

For PSim development, we need to have the virtual environment setup as shown
above _and_ setup Bazel. You should be able to install Bazel through your
system's package manager.

It's also recommended to install the Bazel build tools along with the VSCode
extensions 'Bazel' by the 'Bazel Build Team'. With this extension plus
configuring C/C++ intellisense according to
`tools/bazel-compilation-database.sh` the Bazel build system should integrate
fairly well with VSCode.

To ensure everything is working as expected, you should be able to run the
following successfully:

bazel test //test/psim:all

## GNC

The GNC library is a set of flight software algorithms (mainly controllers and
estimators) along with a myriad of utility functions.

The source code for the GNC library lives in `include/gnc/**` and `src/gnc/**`.
The associated unit tests are located in `test/gnc/**` and can be built with
PlatformIO using the following command:

source venv/bin/activate
pio test -e native

## PSim

The actual infrastructure for PSim is slightly fluid at the moment; however,
this PR have a good overview of the architecture: [#231](https://github.com/pathfinder-for-autonomous-navigation/psim/pull/231).

The code lives under `include/psim/**` and `src/psim/**` and leverages the GNC
modules as a dependency. Unit test are implemented under `test/psim/**` and can
be run with the following command:

bazel test //test/psim:all --test_output=all
36 changes: 21 additions & 15 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

lin_build = """
cc_library(
name = "lin",
srcs = glob(["src/**/*.cpp", "include/**/*.inl"]),
hdrs = glob(["include/**/*.hpp"]),
includes = ["include"],
linkstatic = True,
visibility = ["//visibility:public"]
git_repository(
name = "rules_python",
remote = "https://github.com/bazelbuild/rules_python.git",
commit = "3baa2660569a76898d0f520c73b299ea39b6374d", # (9-8-2020)
)

http_archive(
name = "gtest",
url = "https://github.com/google/googletest/archive/release-1.10.0.zip",
sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91",
strip_prefix = "googletest-release-1.10.0",
)
"""

new_git_repository(
# http_archive(
# name = "sofa",
# url = "https://github.com/pathfinder-for-autonomous-navigation/sofa/archive/v1.0.zip",
# sha256 = "a5660ff94270934c33b3fdaaf891620c9a454181dad7fb12378e66a5b73c205f",
# strip_prefix = "sofa-1.0",
# )

local_repository(
name = "lin",
init_submodules = True,
remote = "https://github.com/pathfinder-for-autonomous-navigation/lin",
commit = "f8fafaa5a29190663bc313a0b835201749b876b8",
build_file_content = lin_build
path = "lib/lin",
)
7 changes: 4 additions & 3 deletions estimatortest/pythonwrapper/pwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ mypath=Path(filepath)
psimpath= mypath.parent.parent.parent
#flightsoftwarepath= psimpath.parent/'FlightSoftware'
# 'dependencies' controls what get checked for changes before recompile
cfg['dependencies'] = [str(p) for p in (psimpath/'src').rglob('*') if p.is_file()]
cfg['dependencies'] = [str(p) for p in (psimpath/'src/gnc').rglob('*') if p.is_file()]
cfg['dependencies'] += [str(p) for p in (psimpath/'lib').rglob('*') if p.is_file()]
cfg['dependencies'] += [str(p) for p in (psimpath/'include').rglob('*') if p.is_file()]
cfg['dependencies'] += [str(p) for p in (psimpath/'include/gnc').rglob('*') if p.is_file()]
cfg['dependencies'] += [str(p) for p in (psimpath/'include/orb').rglob('*') if p.is_file()]
cfg['dependencies'] += [str(mypath.parent/'lin_ext.cpp')]
cfg['dependencies'] += [str(mypath.parent/'orb_ext.cpp')]
#cfg['dependencies'] += [str(p) for p in (flightsoftwarepath/'src').rglob('*') if p.is_file()]
#cfg['dependencies'] += [str(p) for p in (flightsoftwarepath/'lib').rglob('*') if p.is_file()]
cfg['sources'] = ['lin_ext.cpp', 'orb_ext.cpp']
cfg['sources'] += [str(p) for p in (psimpath/'src').rglob('*.cpp') if (p.is_file() and p.parent.name!='targets')]
cfg['sources'] += [str(p) for p in (psimpath/'src/gnc').rglob('*.cpp') if (p.is_file() and p.parent.name!='targets')]
#cfg['sources'] += [str(p) for p in (flightsoftwarepath/'src/fsw').rglob('*.cpp') if (p.is_file() and p.parent.name!='targets')]
#cfg['sources'] += [str(p) for p in (flightsoftwarepath/'src/common').rglob('*.cpp') if (p.is_file() and p.parent.name!='targets')]
Expand Down
Loading

0 comments on commit 039b5f2

Please sign in to comment.