Skip to content

Commit

Permalink
Added the initial autocoder infrastructure and time model
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekrol committed Sep 12, 2020
1 parent da94781 commit d7e1af3
Show file tree
Hide file tree
Showing 16 changed files with 718 additions and 99 deletions.
3 changes: 2 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build --cxxopt=-std=c++14
build --cxxopt=-std=c++17
build --python_top=//:venv --incompatible_use_python_toolchains=false
23 changes: 0 additions & 23 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
50 changes: 25 additions & 25 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# load("@rules_python//python:defs.bzl", "py_runtime", "py_binary")
load("@rules_python//python:defs.bzl", "py_runtime", "py_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")

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

# Build flight software's gnc code as a library.
cc_library(
Expand All @@ -26,33 +26,33 @@ cc_library(
# 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"],
# )
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"],
# )
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"],
# )
psim_autocode(
name = "autocode",
srcs = glob(["include/psim/**/*.yml"]),
includes = ["include"],
tool = "//:autocoder",
visibility = ["//visibility:private"],
)

# Build all PSim models as a library
#
Expand All @@ -61,15 +61,15 @@ cc_library(
name = "psim",
srcs = glob([
"src/psim/**/*.hpp", "src/psim/**/*.inl", "src/psim/**/*.cpp",
"include/psim/**/*.inl", # "include/psim/**/*.yml.hpp",
"include/psim/**/*.inl", "include/psim/**/*.yml.hpp",
]),
hdrs = glob(
["include/psim/**/*.hpp"],
#exclude = ["include/psim/**/*.yml.hpp"],
exclude = ["include/psim/**/*.yml.hpp"],
),
includes = ["include"],
copts = ["-Isrc"],
linkstatic = True,
visibility = ["//visibility:public"],
deps = ["@lin//:lin", "//:gnc"],# "//:autocode"],
deps = ["@lin//:lin", "//:gnc", "//:autocode"],
)
12 changes: 6 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# git_repository(
# name = "rules_python",
# remote = "https://github.com/bazelbuild/rules_python.git",
# commit = "3baa2660569a76898d0f520c73b299ea39b6374d", # (9-8-2020)
# )
git_repository(
name = "rules_python",
remote = "https://github.com/bazelbuild/rules_python.git",
commit = "3baa2660569a76898d0f520c73b299ea39b6374d", # (9-8-2020)
)

http_archive(
name = "gtest",
Expand Down
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
53 changes: 53 additions & 0 deletions include/psim/truth/time.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// 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.
//

/** @file psim/truth/time.hpp
* @author Kyle Krol
*/

#ifndef PSIM_TRUTH_TIME_HPP_
#define PSIM_TRUTH_TIME_HPP_

#include <psim/truth/time.yml.hpp>

namespace psim {

class Time : public TimeInterface<Time> {
private:
typedef TimeInterface<Time> Super;

public:
Time() = delete;
virtual ~Time() = default;

Time(Configuration const &config, std::string const &prefix);

virtual void step() override;

Real prefix_t_s() const;
Real prefix_dt_s() const;
};
} // namespace psim

#endif
27 changes: 27 additions & 0 deletions include/psim/truth/time.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

name: TimeInterface
type: Model
comment: >
Simple model responsible for stepping the simulation forward in time. Time
is counted since the PAN epoch.
args:
- prefix

adds:
- name: "{prefix}.t.ns"
type: Initialized Integer
comment: >
Current simulation time in nanoseconds since the PAN epoch.
- name: "{prefix}.t.s"
type: Lazy Real
comment: >
Current simulation time in seconds since the PAN epoch.
- name: "{prefix}.dt.ns"
type: Initialized Writable Integer
comment: >
Current simulation timestep in nanoseconds.
- name: "{prefix}.dt.s"
type: Lazy Real
comment: >
Current simulation timestep in seconds.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ cppimport
h5py
dulwich
ipykernel
notebook
notebook
pyyaml
45 changes: 45 additions & 0 deletions src/psim/truth/time.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// 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.
//

#include <psim/truth/time.hpp>

namespace psim {

Time::Time(Configuration const &config, std::string const &prefix)
: Super(config, prefix) { }

void Time::step() {
this->Super::step();

this->prefix_t_ns.get() += this->prefix_dt_ns.get();
}

Real Time::prefix_t_s() const {
return ((Real) prefix_t_ns.get()) / 1.0e9;
}

Real Time::prefix_dt_s() const {
return ((Real) prefix_dt_ns.get()) / 1.0e9;
}
} // namespace psim
1 change: 1 addition & 0 deletions test/psim/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ load("//:tools/psim.bzl", "psim_cc_test")
test_suite(name = "ci", tags = ["ci"])

psim_cc_test(name = "core", tags = ["ci"])
psim_cc_test(name = "truth", tags = ["ci"])
32 changes: 32 additions & 0 deletions test/psim/truth/time_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @file test/psim/truth/time_test.cpp
* @author Kyle Krol
*/

#include <gtest/gtest.h>

#include <psim/core/configuration.hpp>
#include <psim/core/simulation.hpp>
#include <psim/truth/time.hpp>

TEST(Time, TestStep) {
auto const config = psim::Configuration::make("test/psim/truth/time_test_config.txt");
auto sim = psim::Simulation::make<psim::Time>(config, "time");

// Assert intial conditions
ASSERT_EQ(sim["time.dt.ns"].get<psim::Integer>(), 5);
ASSERT_EQ(sim["time.t.ns"].get<psim::Integer>(), 0);

// Check the time.t.ns field is updated
sim.step();
sim.step();
ASSERT_EQ(sim["time.t.ns"].get<psim::Integer>(), 10);

// Check the lazy evaluated fiels
ASSERT_DOUBLE_EQ(sim["time.dt.s"].get<psim::Real>(), 5e-9);
ASSERT_DOUBLE_EQ(sim["time.t.s"].get<psim::Real>(), 1e-8);

// Update time.dt.ns and try stepping again
sim.get_writable("time.dt.ns")->get<psim::Integer>() = 4;
sim.step();
ASSERT_EQ(sim["time.t.ns"].get<psim::Integer>(), 14);
}
2 changes: 2 additions & 0 deletions test/psim/truth/time_test_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
time.t.ns 0
time.dt.ns 5
Loading

0 comments on commit d7e1af3

Please sign in to comment.