-
Notifications
You must be signed in to change notification settings - Fork 6
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
Single Orbit Simulation in Python #244
Conversation
Commit by commit this should be pretty easy to do! Up until 8415076 are "original" commits on this PR. |
auto const &t = prefix_t_s->get(); | ||
|
||
Vector3 s_eci; | ||
gnc::env::sun_vector(t, s_eci); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the sake of reducing how distributed implementations are, are these functions (defined in gnc/environment.hpp) eventually going to move their implemenations into this class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely no because these are also shared by the flight computer. If we implement more complex models to be run only by the truth model, they may be moved in here.
PSim can consume the GNC flight software implementation as a library but not the other way around.
}); | ||
|
||
// Write back to our state fields | ||
r = lin::ref<3, 1>(xf, 0, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are r and v lazily evaluated here, is that why they get xf?
Why are they lazily evaluated? Shouldn't they be computed on each timestep for the integrator to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Position and velocity are not being lazily evaluated in the orbit model because they are integral to the state of the simulation. This is also why they're required to be initialized from config.
}; | ||
gnc::Ode4<double, 2> ode; | ||
lin::Vector2d x = {1.0, 0.0}; | ||
x = ode(0.0, 0.1, x, nullptr, dx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lazy evaluation concern I brought up seems related to the changes made in this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integrators don't employ any lazy evaluation? They just take the function to calculate dx/dt
.
Overview
There is a lot of stuff going down in this PR so i am going to take it commit by commit.
Updated
lin
PointerThis is pretty self explanatory. The reason for the update was to avoid naming collisions on MacOS with the Bazel
BUILD
file and some file Python's setup tools likes to create.Build System Updates
There we a lot of build system updates this time around but here are the highlights:
*.bzl
files were centralized in thebazel/
directory (this was done because of the large number of build files added on this PR).std::variant
implementation was added to help handle passing dynamic types between Python and C++ at runtime. This gets plugged into the Python binding code later on..bazelrc
to enable optimizations! It makes a huge difference and I opened a ticket to add explicit support for debug and release builds.GNC Updates to the Fixed Step Size Integrators
Per the section header. The integrators were updated to also take a void pointer to allow the end user to pass arbitrary data to the integration step. This will be useful for more complex PSim implementations.
PSim Bugs
We were missing a return statement in a few assignment operators and was why build issues were seen on MacOS.
Earth Ephemeris Model
This is the first model that will pretty much run in every simulation and is just downstream of the time model. It's responsible for outputing information about Earth's attitude and angular rate (i.e. all the information that's needed to transform between ECI and ECEF).
The interface was initially implemented here using existing GNC functions but should be revisited later per #236.
Point Mass Orbit Model
This is a generic interface for a point mass orbit propagator. The orbit propagator can work in whatever frame it wants to and a vector transformer should be added later to abstract away this fact - these will be touched on later.
The orbit propagator implemented here just relies on GNC functions.
Vector Transform Functions
The general idea here is to add a layer of abstraction that abstracts away the particular frame and orbit model, environment model, et cetera is operating in. These models take in a vector
vector.lookup.name
and output the vector in different frames:vector.lookup.eci
, ...Environment Models
This model generates magnetic field and sun vector truth values for a satellite and should be supplemented with vector transformers.
Single Orbit Simulation
Simply created a model list here with the proper arguments to create a simple simulation of a single point mass orbiting Earth.
Python!!!
If you aren't familiar, I would highly recommend taking a look through the pybind11 docs here. It's a super slick way to interface C++ with Python and it's what's being used here for PSim.
In short, the PSim configuration and single orbit simulations were wrapped and made available to Python. A simple model was thrown together and you can run the simulation currently with the following:
You should get these plots! This was tested on Arch Linux and MacOS.
There is plenty more work to be done to clean up the Python side of things a little bit.