Skip to content

Commit

Permalink
Single Orbit Simulation in Python (#244)
Browse files Browse the repository at this point in the history
* Updated lin pointer
* Build system and README updates
* Update GNC fixed step size integrators for future use
* Fixed two bugs found in psim infrastructure
* Earth ephemeris model
* Orbit model implemented with GNC functions
* Vector transform models
* Environment models
* Single orbit simulation
* Python wrappers, single orbit simulation, and basic config files
* Update CI build targets
  • Loading branch information
kylekrol authored Sep 27, 2020
1 parent 039b5f2 commit 51bf398
Show file tree
Hide file tree
Showing 57 changed files with 2,497 additions and 487 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
build --cxxopt=-std=c++14
build --cxxopt=-std=c++14 --cxxopt=-O3 --cxxopt=-Werror --cxxopt=-Wall
build --python_top=//:venv --incompatible_use_python_toolchains=false
2 changes: 1 addition & 1 deletion .github/workflows/psim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ jobs:
- name: Build and Test
run: |
bazel build //:gnc
bazel build //:psim
bazel build //python:psim
bazel test //test/psim:ci
81 changes: 36 additions & 45 deletions BUILD → BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
load("@rules_python//python:defs.bzl", "py_runtime", "py_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_python//python:defs.bzl", "py_runtime", "py_binary")

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"],
)
load("//bazel:psim_build.bzl", "psim_autocoded_cc_library", "psim_cc_library", "psim_py_extension")

# Let bazel know about our virtual environment.
#
Expand All @@ -34,42 +17,50 @@ py_runtime(
visibility = ["//visibility:private"],
)

# Register the autocoder as an executable.
#
# This is later consumed by the autocoder command. See psim.bzl for more
# information.
# 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 = ["//: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.
# Builds the GNC flight software implementations to be linked in as a dependancy
# of PSim.
cc_library(
name = "psim",
name = "gnc",
srcs = glob([
"src/psim/**/*.hpp", "src/psim/**/*.inl", "src/psim/**/*.cpp",
"include/psim/**/*.inl", "include/psim/**/*.yml.hpp",
"src/gnc/**/*.hpp", "src/gnc/*.cpp", "src/gnc/**/*.inl",
"include/gnc/**/*.inl"
]),
hdrs = glob([
"include/gnc/**/*.hpp", "include/orb/*.h", "include/orb/*.hpp"
]),
hdrs = glob(
["include/psim/**/*.hpp"],
exclude = ["include/psim/**/*.yml.hpp"],
),
includes = ["include"],
copts = ["-Isrc"],
copts = ["-Isrc", "-fvisibility=hidden"],
linkstatic = True,
visibility = ["//visibility:public"],
deps = ["@lin//:lin", "//:gnc", "//:autocode"],
deps = ["@lin//:lin"],
)

# Builds the core PSim infrastructure.
psim_cc_library(
name = "core",
deps = ["@lin//:lin"],
visibility = ["//visibility:public"],
)

# Builds the PSim truth models
psim_autocoded_cc_library(
name = "truth",
deps = ["@lin//:lin", "//:gnc", "//:psim_core"],
visibility = ["//visibility:public"],
)

# Builds all PSim models deemed "simulation" worthy.
psim_cc_library(
name = "simulations",
deps = ["//:psim_core", "//:psim_truth"],
visibility = ["//visibility:public"],
)
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ two main modules:
MATLAB code listed in `MATLAB/**` is deprecated and will be phased out by the
new C++ implementation of PSim.

## Getting Setup
## Getting Started

For GNC development, it's only necessary to setup the PlatformIO development
environment. This requires setting up a local virtual environment as shown
Expand All @@ -36,8 +36,21 @@ for the GNC code with:
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.
above, a couple extra Python bells and whistles you most likely already have,
and then Bazel.

Besides your system install of Python and the virtual environment that will be
used to work with the PSim repository, you need to install the Python
development headers and `distutils` for the version of Python you'll be using.
The Bazel build system will require both of these to compile PSim into a Python
module.

Generally the Python development headers and `distutils` can be installed via a
package manager. Note that Bazel will explicitly let you know if it can't find
either of these.

As far as Bazel is concerned, you should be able to install it through your
package manager of choice as well.

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
Expand All @@ -46,7 +59,8 @@ configuring C/C++ intellisense according to
fairly well with VSCode.

To ensure everything is working as expected, you should be able to run the
following successfully:
following successfully (make sure you're in your virtual environment when
working with Bazel as well):

bazel test //test/psim:all

Expand Down
56 changes: 47 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
workspace(name = "psim")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

load("//bazel:psim_workspace.bzl", "psim_configure")

# Standard cc rules
git_repository(
name = "rules_cc",
remote = "https://github.com/bazelbuild/rules_cc",
commit = "bea600c25d246a79398a1c1a73e9261aee35a6b1",
)

# Standard Python rules
http_archive(
name = "rules_python",
remote = "https://github.com/bazelbuild/rules_python.git",
commit = "3baa2660569a76898d0f520c73b299ea39b6374d", # (9-8-2020)
url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.2/rules_python-0.0.2.tar.gz",
strip_prefix = "rules_python-0.0.2",
sha256 = "b5668cde8bb6e3515057ef465a35ad712214962f0b3a314e551204266c7be90c",
)

# Pybind11
http_archive(
name = "pybind11",
build_file = "//bazel:pybind11.BUILD",
strip_prefix = "pybind11-2.5.0",
urls = ["https://github.com/pybind/pybind11/archive/v2.5.0.tar.gz"],
)

# Googletest
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",
)

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

# std::variant alternative for use in C++ 14
http_archive(
name = "variant",
build_file = "//bazel:variant.BUILD",
url = "https://github.com/mapbox/variant/archive/v1.2.0.zip",
sha256 = "48df02096b954ea35c447edc3e662e7f163a92e1de2ab5f226445d6001a4537d",
strip_prefix = "variant-1.2.0",
)

# lin
local_repository(
name = "lin",
path = "lib/lin",
)

# Grabs the systems Python headers in preparation for building with Pybind11
psim_configure(
name = "psim_configuration"
)
Empty file added bazel/BUILD.bazel
Empty file.
30 changes: 30 additions & 0 deletions bazel/psim.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# MIT License
#
# Copyright (c) 2020 Pathfinder for Autonomous Navigation (PAN)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

"""Collection of tools shared across PSim's Bazel rules.
"""

def psim_fail(message):
"""Outputs an error message and fails the build. Used throughout PSim's rules.
"""
fail("\033[0;31mPSim Error:\033[0m %s" % message)
Loading

0 comments on commit 51bf398

Please sign in to comment.