Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
f67c888
Adding Trajectory Generation code
kjjarvis Sep 26, 2022
5240203
Moving initializations of x_ref, vehicle, etc. to under-the-hood
kjjarvis Sep 27, 2022
3200686
Further additions for TrajGen in ProgPy
kjjarvis Sep 28, 2022
e361741
Adding dx and simulate_to for TrajGen
kjjarvis Oct 3, 2022
a154d86
Merge branch 'dev' into feature/traj_generation
kjjarvis Nov 22, 2022
301a0b7
Renamed files, cleaned up some code, started user input
kjjarvis Nov 23, 2022
8e86ecd
Added user defined inputs; commented out unused code
kjjarvis Nov 29, 2022
3af70ad
Adjustments for updated code from Matteo
kjjarvis Dec 1, 2022
c71afae
More adjustments to match Matteo updated code
kjjarvis Dec 2, 2022
8870c93
Merge remote-tracking branch 'origin/dev' into feature/traj_generation
kjjarvis Dec 9, 2022
d449d0c
Debugging TrajGen, fixed aircraft.state not updating
kjjarvis Dec 12, 2022
41ee4ed
Merge remote-tracking branch 'origin/dev' into feature/traj_generation
kjjarvis Dec 13, 2022
5d5fe17
Merge remote-tracking branch 'origin/dev' into feature/traj_generation
kjjarvis Dec 20, 2022
90933cf
Merge branch 'dev' into feature/traj_generation
kjjarvis Dec 22, 2022
f5b700b
Further development of traj_gen
kjjarvis Dec 22, 2022
bed50eb
Adding threshold_met and event_state for TrajGen
kjjarvis Dec 24, 2022
6a0133b
TrajGen development - input data units and exceptions
kjjarvis Dec 30, 2022
d0fec27
Deleting unused code in trajectory generation
kjjarvis Dec 30, 2022
cc5d2f5
Improved traj gen example, added visualization function,
kjjarvis Jan 4, 2023
c8c24b0
Traj Gen documentation and code clean up
kjjarvis Jan 7, 2023
d120fe3
Merge branch 'dev' into feature/traj_generation
kjjarvis Jan 9, 2023
efd3566
Adding documentation and cleaning up Traj Gen code
kjjarvis Jan 10, 2023
9025e96
Adding init to fix initialization
kjjarvis Jan 10, 2023
4d11f2b
Added beginning of TrajGen tests, a few additional exceptions added
kjjarvis Jan 11, 2023
117dd7f
Merge remote-tracking branch 'origin/dev' into feature/traj_generation
kjjarvis Jan 11, 2023
fad536f
Adding tests for traj gen
kjjarvis Jan 11, 2023
1f93613
Final edits to trajectory generation
kjjarvis Jan 13, 2023
caaacf8
Initial edits from PR
kjjarvis Jan 18, 2023
557553c
Fixing copyright
kjjarvis Jan 18, 2023
7f676be
Edits on uav_model.py: line 237, computing waypoints in xyz from rout…
matteocorbetta Jan 18, 2023
7575876
resolving conflicts
matteocorbetta Jan 18, 2023
89594f5
fixing a couple of errors that made the new code break. now it runs.
matteocorbetta Jan 18, 2023
99d1fd2
adding some comments to functions
matteocorbetta Jan 18, 2023
a73dcd8
Second round of PR edits
kjjarvis Jan 19, 2023
a830a1b
Merge branch 'dev' into feature/traj_generation
teubert Jan 27, 2023
6d33c32
Traj gen modularity change - new models, moving files, new example
kjjarvis Feb 10, 2023
052414e
Removing aircraft_name and flight_name
kjjarvis Feb 15, 2023
6b8eea1
Change in loading folder name
kjjarvis Feb 23, 2023
c54ae24
Cleaning up TrajGen new format for Matteo to work on controller
kjjarvis Feb 24, 2023
cac8a48
some progress on modular controller classes
matteocorbetta Mar 21, 2023
6969f91
updating the controller class LQR_I with some general improvements.
matteocorbetta Apr 5, 2023
42abd74
adding controller details
kjjarvis Apr 12, 2023
511d23b
More work on integrating separate controller
kjjarvis Apr 13, 2023
70ca4fe
Deleting extra controller code
kjjarvis Apr 17, 2023
8f88f2b
First changes to LQR
kjjarvis Apr 18, 2023
c7ce495
Cleaning up old controller code
kjjarvis Apr 19, 2023
a446932
LQR controller changes
kjjarvis Apr 21, 2023
7dc0a92
Merge remote-tracking branch 'origin/dev' into feature/traj_generatio…
kjjarvis May 3, 2023
3549253
Further development of UAV model
kjjarvis May 6, 2023
effa755
Documentation and final edits to ref_gen; added beginning uav_model test
kjjarvis May 9, 2023
f013176
Cleaning up comments/tests, adding tests
kjjarvis May 11, 2023
041f410
Improvements on controller functions: removed a for loop in lqr_fn by…
matteocorbetta May 22, 2023
27f09e2
Added a new class that is supposed to replace UAVGen (if accepted) an…
matteocorbetta May 22, 2023
01832d1
Auto stash before merge of "feature/traj_generation_modular" and "ori…
kjjarvis May 22, 2023
a4a18b8
debugging new code
kjjarvis May 24, 2023
ed06535
Debugging
kjjarvis May 24, 2023
0f8d9f7
cleaned up SmallRotorcraft class and removed AircraftModels, which is…
matteocorbetta May 24, 2023
9a00e66
Merge remote-tracking branch 'origin/feature/traj_generation_modular'…
kjjarvis May 24, 2023
e2ef386
Final adjustments for deleting AircraftModels and class
kjjarvis May 24, 2023
790bc77
First changes for mission_complete in inputs/ctrl
kjjarvis May 24, 2023
5b993c6
Added mission_complete works
kjjarvis May 24, 2023
c30cfce
Change coarse waypoints format to DataFrames
kjjarvis May 27, 2023
1ec678e
Merge remote-tracking branch 'origin/dev' into feature/traj_generatio…
kjjarvis May 27, 2023
776c476
Add back in uav_model test to __main__
kjjarvis May 27, 2023
42f52e7
Small clean-up changes
kjjarvis May 29, 2023
0755987
Small clean-up edits
kjjarvis May 30, 2023
30f36de
added documentation for a bunch of functions, although this pass is n…
matteocorbetta May 30, 2023
79da7cc
Rename loading_fcns to loading and documentation edits/typos
kjjarvis May 31, 2023
ffd496b
First pass at PR comments
kjjarvis May 31, 2023
ff66096
Adding test_uav_model to coverage assessment
kjjarvis May 31, 2023
e260827
Fixing copyright issue
kjjarvis May 31, 2023
4d9d834
Small improvements and more testing
kjjarvis Jun 2, 2023
43a574b
first changes to cleanup route and trajectory
matteocorbetta Jun 2, 2023
6b59be9
commiting local changes before merge
matteocorbetta Jun 2, 2023
7a0c44d
Add test of actual simulation
kjjarvis Jun 2, 2023
b94dd5d
major refactoring of trajectory generation files; cleaned up interfac…
matteocorbetta Jun 6, 2023
085b4f3
Merge branch 'feature/traj_generation_modular' of https://github.com/…
matteocorbetta Jun 6, 2023
62afa5f
changes according to Chris' review. Removed traj_gen.py, renamed traj…
matteocorbetta Jun 7, 2023
801f219
Added warnings/exceptions for new structure; fixed tests
kjjarvis Jun 10, 2023
f18bb07
Cleaning up code; fixing copyright issue
kjjarvis Jun 12, 2023
32e5806
Small fixes from review
kjjarvis Jun 12, 2023
4dfe9cc
Merge branch 'dev' into feature/traj_generation_modular
kjjarvis Jun 12, 2023
6724ea8
Cleanup spacing and documentation
teubert Jun 12, 2023
0975b1f
Increasing timeout for test
kjjarvis Jun 12, 2023
3595483
Merge remote-tracking branch 'origin/feature/traj_generation_modular'…
kjjarvis Jun 12, 2023
63f4c23
Controller kwargs description
kjjarvis Jun 12, 2023
92a454a
Debugging failed test
kjjarvis Jun 12, 2023
162f823
Debugging PR test by skipping uav_test
kjjarvis Jun 12, 2023
33997d5
Debugging test
kjjarvis Jun 13, 2023
4d9a434
Merge remote-tracking branch 'origin/run_all_tests' into feature/traj…
kjjarvis Jun 13, 2023
b12fc7b
Testing without examples
kjjarvis Jun 13, 2023
55c5a26
Adding some tests
kjjarvis Jun 13, 2023
0e77e76
Only include uav test
kjjarvis Jun 13, 2023
a8b8efe
Just testing test_uav, no example
kjjarvis Jun 13, 2023
eb8b409
Testing commented out code in uav example
kjjarvis Jun 13, 2023
211c30a
Testing example again
kjjarvis Jun 13, 2023
f14b7a3
Testing example again
kjjarvis Jun 13, 2023
38cc4a4
Testing example again
kjjarvis Jun 13, 2023
a64d4ed
Test example again, with ex #2
kjjarvis Jun 13, 2023
eb077c1
Test example again, add ex #3 no plot
kjjarvis Jun 13, 2023
83589e2
Testing complete example
kjjarvis Jun 13, 2023
3a5e870
Rename and clean
teubert Jun 13, 2023
81351e0
Testing example start
kjjarvis Jun 13, 2023
f3fd7a0
Adding more example
kjjarvis Jun 13, 2023
d35f0d1
Adding more of test
kjjarvis Jun 13, 2023
72a32b5
Adding less to test
kjjarvis Jun 13, 2023
ea73617
add warning message
teubert Jun 13, 2023
8a6688f
fix typo
teubert Jun 13, 2023
4d4aa74
print all state
teubert Jun 13, 2023
43ddd58
Print controller config
teubert Jun 13, 2023
d5c4663
Add controller printing
teubert Jun 13, 2023
d8f4779
logging in example
teubert Jun 13, 2023
a98d666
additional warnings
teubert Jun 13, 2023
4216396
additional logs
teubert Jun 13, 2023
1e797ff
Using absolute datetimes
teubert Jun 13, 2023
45675fc
before/after eta call
teubert Jun 13, 2023
d4f2286
before/after other fcn
teubert Jun 13, 2023
e7b1116
small fixes
teubert Jun 13, 2023
78ee671
before/after other fcn
teubert Jun 13, 2023
c31180c
clean warnings
teubert Jun 13, 2023
53e1c2a
trying float time
teubert Jun 13, 2023
33e0fc5
propogate change
teubert Jun 13, 2023
15c5cbe
Merge branch 'feature/traj_generation_modular' into float_time
teubert Jun 14, 2023
fe29189
Uncomment example
teubert Jun 14, 2023
6e7ba07
Remove exception
teubert Jun 14, 2023
e0ab157
Merge branch 'feature/traj_generation_modular' into float_time
teubert Jun 14, 2023
91f7724
Remove waypoints in eg
teubert Jun 14, 2023
53a7511
Fix lat/lon typo
teubert Jun 14, 2023
3b50f84
Remove comments and merge functions
teubert Jun 14, 2023
a9e9688
Remove logging messages
teubert Jun 14, 2023
99b50a7
Fix typo
teubert Jun 14, 2023
4ff5c0b
More cleanup
teubert Jun 14, 2023
07855ea
Merge branch 'feature/traj_generation_modular' into float_time
teubert Jun 14, 2023
cb59116
Merge pull request #553 from nasa/float_time
teubert Jun 15, 2023
ec7d17d
Fix tests for new time configuration
kjjarvis Jun 16, 2023
728c8d0
Add uav model to cov
teubert Jun 16, 2023
60c1456
Adding more tests for coverage
kjjarvis Jun 16, 2023
e5fda4f
Merge remote-tracking branch 'origin/feature/traj_generation_modular'…
kjjarvis Jun 16, 2023
9f5064a
Fix typo
kjjarvis Jun 16, 2023
f80a8df
Merge branch 'dev' into feature/traj_generation_modular
teubert Jun 16, 2023
19fd78e
Merge branch 'dev' into feature/traj_generation_modular
teubert Jun 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ jobs:
coverage run -a -m tests.test_powertrain
coverage run -a -m tests.test_serialization
coverage run -a -m tests.test_sim_result
coverage run -a -m tests.test_uav_model
coverage xml -i
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v3
18 changes: 18 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,24 @@ jobs:
pip install testbook
- name: Run tests
run: python -m tests.test_tutorials
test_uav_model:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.7'
- name: Install dependencies cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip-cache
- name: Update
run: pip install --upgrade --upgrade-strategy eager -e .
- name: Run tests
run: python -m tests.test_uav_model
# test_prog_algs_released:
# timeout-minutes: 30
# runs-on: ubuntu-latest
Expand Down
155 changes: 155 additions & 0 deletions examples/uav_dynamics_model.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great example, very clean and easy to understand now.

Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Copyright © 2021 United States Government as represented by the Administrator of the
# National Aeronautics and Space Administration. All Rights Reserved.

"""
Example of generating a trajectory for a small rotorcraft through a set of coarse waypoints, and simulate the rotorcraft flight using a 6-dof model.
"""

import matplotlib.pyplot as plt
import numpy as np

from prog_models.utils.traj_gen import Trajectory
from prog_models.models.aircraft_model import SmallRotorcraft
from prog_models.loading.controllers import LQR_I, LQR


def run_example():
# Initialize vehicle
vehicle = SmallRotorcraft(
dt=0.05,
vehicle_model='tarot18',
process_noise=0,
measurement_noise=0
)

# EXAMPLE 1:
# Define coarse waypoints: latitudes, longitudes, and altitudes are
# required, ETAs are optional
# Latitudes and longitudes must be defined as numpy arrays of size n x 1
# and with unit radians
# Altitudes must be defined as numpy arrays of size n x 1 with unit meters
# ETAs (if included) must be defined as a list of datetime objects
# If ETAs are not included, speeds must be defined (see Example 2)

# Here, we specify waypoints in a dictionary and then pass
# lat/lon/alt/ETAs into the trajectory class
lat_deg = np.array([37.09776, 37.09776, 37.09776, 37.09798, 37.09748, 37.09665, 37.09703, 37.09719, 37.09719, 37.09719, 37.09719, 37.09748, 37.09798, 37.09776, 37.09776])
lon_deg = np.array([-76.38631, -76.38629, -76.38629, -76.38589, -76.3848, -76.38569, -76.38658, -76.38628, -76.38628, -76.38628, -76.38628, -76.3848, -76.38589, -76.38629, -76.38629])
alt_ft = np.array([-1.9682394, 164.01995, 164.01995, 164.01995, 164.01995, 164.01995, 164.01995, 164.01995, 0.0, 0.0, 164.01995, 164.01995, 164.01995, 164.01995, 0.0])
time_unix = [1544188336, 1544188358, 1544188360, 1544188377, 1544188394, 1544188411, 1544188428, 1544188496, 1544188539, 1544188584, 1544188601, 1544188635, 1544188652, 1544188672, 1544188692]

# Generate trajectory
# =====================
# Generate trajectory object and pass the route (waypoints, ETA) to it
traj = Trajectory(lat=lat_deg * np.pi/180.0,
lon=lon_deg * np.pi/180.0,
alt=alt_ft * 0.3048,
etas=time_unix)

ref_traj = traj.generate(dt=vehicle.parameters['dt'])

# Define controller and build scheduled control. The controller acts as a
# future_loading function when simulating
# We use a linear quadratic regulator (LQR), which tries to minimize the
# cost function defined by:
# J = \int{ x^T Q x + u^T R u \mathrm{d}t }
# Where x is the state vector, u is the input vector, t is time, Q is the
# state error penalty matrix, and R is the input generation penalty matrix.
# The LQR uses a linearized version of the dynamic system
# (i.e., dxdt = A x + Bu) to find the gain matrix K that minimizes the cost J.
ctrl = LQR(ref_traj, vehicle)

# Simulate vehicle to fly trajectory
traj_results = vehicle.simulate_to_threshold(
ctrl,
dt=vehicle.parameters['dt'],
save_freq=vehicle.parameters['dt'])

# Visualize Results
vehicle.visualize_traj(pred=traj_results, ref=ref_traj)

# EXAMPLE 2:
# In this example, we define another trajectory through the same
# waypoints but with speeds defined instead of ETAs

# Generate trajectory object and pass the route (lat/lon/alt, no ETAs)
# and speed information to it
traj_speed = Trajectory(lat=lat_deg * np.pi/180.0,
lon=lon_deg * np.pi/180.0,
alt=alt_ft * 0.3048,
cruise_speed=8.0,
ascent_speed=2.0,
descent_speed=3.0,
landing_speed=2.0)
ref_traj_speeds = traj_speed.generate(dt=vehicle.parameters['dt'])

# Define controller and build scheduled control. This time we'll use LQR_I,
# which is a linear quadratic regulator with integral action.
# The integral action has the same purpose of "I" in PI or PID controllers,
# which is to minimize offset errors in the variable of interest.
# This version of LQR_I compensates for integral errors in the position of
# the vehicle, i.e., x, y, z variables of the state vector.
ctrl_speeds = LQR_I(ref_traj_speeds, vehicle)

# Set simulation options
options = {
'dt': vehicle.parameters['dt'],
'save_freq': vehicle.parameters['dt']
}

# Simulate vehicle to fly trajectory
traj_results_speeds = vehicle.simulate_to_threshold(ctrl_speeds, **options)

# Visualize results - notice these results are slightly different, since
# the speeds through the waypoints (and therefore the resulting trajectory)
# are different than Example 1
vehicle.visualize_traj(pred=traj_results_speeds, ref=ref_traj_speeds)

# EXAMPLE 3:
# In this example, we just want to simulate a specific portion of the
# reference trajectory
# We will simulate the second cruise interval in Example 1,
# i.e. waypoints 10 - 13 (where the first waypoint is index 0).
# We will use the reference trajectory (ref_traj) and controller (ctrl)
# already generated in Example 1

# First, we'll re-define the ETAs in the waypoints dictionary
# (since we deleted them from the waypoints in Example 2)
time_unix = np.array([1544188336, 1544188358, 1544188360, 1544188377, 1544188394, 1544188411, 1544188428, 1544188496, 1544188539, 1544188584, 1544188601, 1544188635, 1544188652, 1544188672, 1544188692])

# Extract time information for desired interval, starting at waypoint 10
# and ending at waypoint 13
start_time = time_unix[10] - time_unix[0]
end_time = time_unix[13] - time_unix[0]
sim_time = end_time - start_time

# Define initial state, x0, based on reference trajectory at start_time
ind = np.where(ref_traj['t'] == start_time)
x0 = {key: ref_traj[key][ind][0] for key in ref_traj.keys()}
vehicle.parameters['x0'] = x0

# Define simulation parameters - note that we must define t0 as start_time
# since we are not starting at the default of t0 = 0
options = {
'dt': vehicle.parameters['dt'],
'save_freq': vehicle.parameters['dt'],
't0': start_time
}

# Simulate starting from this initial state from start_time to end_time
traj_results_interval = vehicle.simulate_to(sim_time, ctrl, **options)

# Plot results with Example 1 results to show equivalence on this interval
z_1 = [output['z'] for output in traj_results.outputs]
z_4 = [output['z'] for output in traj_results_interval.outputs]

fig, ax = plt.subplots()
ax.plot(traj_results.times, z_1, '-b', label='Example 1')
ax.plot(traj_results_interval.times, z_4, '--r', label='Example 3')
ax.set_xlabel('time, s', fontsize=14)
ax.set_ylabel('altitude, m', fontsize=14)
ax.legend()

# This allows the module to be executed directly
if __name__ == '__main__':
run_example()
Loading