-
Couldn't load subscription status.
- Fork 52
Feature/traj generation modular #537
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
Merged
Merged
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 5240203
Moving initializations of x_ref, vehicle, etc. to under-the-hood
kjjarvis 3200686
Further additions for TrajGen in ProgPy
kjjarvis e361741
Adding dx and simulate_to for TrajGen
kjjarvis a154d86
Merge branch 'dev' into feature/traj_generation
kjjarvis 301a0b7
Renamed files, cleaned up some code, started user input
kjjarvis 8e86ecd
Added user defined inputs; commented out unused code
kjjarvis 3af70ad
Adjustments for updated code from Matteo
kjjarvis c71afae
More adjustments to match Matteo updated code
kjjarvis 8870c93
Merge remote-tracking branch 'origin/dev' into feature/traj_generation
kjjarvis d449d0c
Debugging TrajGen, fixed aircraft.state not updating
kjjarvis 41ee4ed
Merge remote-tracking branch 'origin/dev' into feature/traj_generation
kjjarvis 5d5fe17
Merge remote-tracking branch 'origin/dev' into feature/traj_generation
kjjarvis 90933cf
Merge branch 'dev' into feature/traj_generation
kjjarvis f5b700b
Further development of traj_gen
kjjarvis bed50eb
Adding threshold_met and event_state for TrajGen
kjjarvis 6a0133b
TrajGen development - input data units and exceptions
kjjarvis d0fec27
Deleting unused code in trajectory generation
kjjarvis cc5d2f5
Improved traj gen example, added visualization function,
kjjarvis c8c24b0
Traj Gen documentation and code clean up
kjjarvis d120fe3
Merge branch 'dev' into feature/traj_generation
kjjarvis efd3566
Adding documentation and cleaning up Traj Gen code
kjjarvis 9025e96
Adding init to fix initialization
kjjarvis 4d11f2b
Added beginning of TrajGen tests, a few additional exceptions added
kjjarvis 117dd7f
Merge remote-tracking branch 'origin/dev' into feature/traj_generation
kjjarvis fad536f
Adding tests for traj gen
kjjarvis 1f93613
Final edits to trajectory generation
kjjarvis caaacf8
Initial edits from PR
kjjarvis 557553c
Fixing copyright
kjjarvis 7f676be
Edits on uav_model.py: line 237, computing waypoints in xyz from rout…
matteocorbetta 7575876
resolving conflicts
matteocorbetta 89594f5
fixing a couple of errors that made the new code break. now it runs.
matteocorbetta 99d1fd2
adding some comments to functions
matteocorbetta a73dcd8
Second round of PR edits
kjjarvis a830a1b
Merge branch 'dev' into feature/traj_generation
teubert 6d33c32
Traj gen modularity change - new models, moving files, new example
kjjarvis 052414e
Removing aircraft_name and flight_name
kjjarvis 6b8eea1
Change in loading folder name
kjjarvis c54ae24
Cleaning up TrajGen new format for Matteo to work on controller
kjjarvis cac8a48
some progress on modular controller classes
matteocorbetta 6969f91
updating the controller class LQR_I with some general improvements.
matteocorbetta 42abd74
adding controller details
kjjarvis 511d23b
More work on integrating separate controller
kjjarvis 70ca4fe
Deleting extra controller code
kjjarvis 8f88f2b
First changes to LQR
kjjarvis c7ce495
Cleaning up old controller code
kjjarvis a446932
LQR controller changes
kjjarvis 7dc0a92
Merge remote-tracking branch 'origin/dev' into feature/traj_generatio…
kjjarvis 3549253
Further development of UAV model
kjjarvis effa755
Documentation and final edits to ref_gen; added beginning uav_model test
kjjarvis f013176
Cleaning up comments/tests, adding tests
kjjarvis 041f410
Improvements on controller functions: removed a for loop in lqr_fn by…
matteocorbetta 27f09e2
Added a new class that is supposed to replace UAVGen (if accepted) an…
matteocorbetta 01832d1
Auto stash before merge of "feature/traj_generation_modular" and "ori…
kjjarvis a4a18b8
debugging new code
kjjarvis ed06535
Debugging
kjjarvis 0f8d9f7
cleaned up SmallRotorcraft class and removed AircraftModels, which is…
matteocorbetta 9a00e66
Merge remote-tracking branch 'origin/feature/traj_generation_modular'…
kjjarvis e2ef386
Final adjustments for deleting AircraftModels and class
kjjarvis 790bc77
First changes for mission_complete in inputs/ctrl
kjjarvis 5b993c6
Added mission_complete works
kjjarvis c30cfce
Change coarse waypoints format to DataFrames
kjjarvis 1ec678e
Merge remote-tracking branch 'origin/dev' into feature/traj_generatio…
kjjarvis 776c476
Add back in uav_model test to __main__
kjjarvis 42f52e7
Small clean-up changes
kjjarvis 0755987
Small clean-up edits
kjjarvis 30f36de
added documentation for a bunch of functions, although this pass is n…
matteocorbetta 79da7cc
Rename loading_fcns to loading and documentation edits/typos
kjjarvis ffd496b
First pass at PR comments
kjjarvis ff66096
Adding test_uav_model to coverage assessment
kjjarvis e260827
Fixing copyright issue
kjjarvis 4d9d834
Small improvements and more testing
kjjarvis 43a574b
first changes to cleanup route and trajectory
matteocorbetta 6b59be9
commiting local changes before merge
matteocorbetta 7a0c44d
Add test of actual simulation
kjjarvis b94dd5d
major refactoring of trajectory generation files; cleaned up interfac…
matteocorbetta 085b4f3
Merge branch 'feature/traj_generation_modular' of https://github.com/…
matteocorbetta 62afa5f
changes according to Chris' review. Removed traj_gen.py, renamed traj…
matteocorbetta 801f219
Added warnings/exceptions for new structure; fixed tests
kjjarvis f18bb07
Cleaning up code; fixing copyright issue
kjjarvis 32e5806
Small fixes from review
kjjarvis 4dfe9cc
Merge branch 'dev' into feature/traj_generation_modular
kjjarvis 6724ea8
Cleanup spacing and documentation
teubert 0975b1f
Increasing timeout for test
kjjarvis 3595483
Merge remote-tracking branch 'origin/feature/traj_generation_modular'…
kjjarvis 63f4c23
Controller kwargs description
kjjarvis 92a454a
Debugging failed test
kjjarvis 162f823
Debugging PR test by skipping uav_test
kjjarvis 33997d5
Debugging test
kjjarvis 4d9a434
Merge remote-tracking branch 'origin/run_all_tests' into feature/traj…
kjjarvis b12fc7b
Testing without examples
kjjarvis 55c5a26
Adding some tests
kjjarvis 0e77e76
Only include uav test
kjjarvis a8b8efe
Just testing test_uav, no example
kjjarvis eb8b409
Testing commented out code in uav example
kjjarvis 211c30a
Testing example again
kjjarvis f14b7a3
Testing example again
kjjarvis 38cc4a4
Testing example again
kjjarvis a64d4ed
Test example again, with ex #2
kjjarvis eb077c1
Test example again, add ex #3 no plot
kjjarvis 83589e2
Testing complete example
kjjarvis 3a5e870
Rename and clean
teubert 81351e0
Testing example start
kjjarvis f3fd7a0
Adding more example
kjjarvis d35f0d1
Adding more of test
kjjarvis 72a32b5
Adding less to test
kjjarvis ea73617
add warning message
teubert 8a6688f
fix typo
teubert 4d4aa74
print all state
teubert 43ddd58
Print controller config
teubert d5c4663
Add controller printing
teubert d8f4779
logging in example
teubert a98d666
additional warnings
teubert 4216396
additional logs
teubert 1e797ff
Using absolute datetimes
teubert 45675fc
before/after eta call
teubert d4f2286
before/after other fcn
teubert e7b1116
small fixes
teubert 78ee671
before/after other fcn
teubert c31180c
clean warnings
teubert 53e1c2a
trying float time
teubert 33e0fc5
propogate change
teubert 15c5cbe
Merge branch 'feature/traj_generation_modular' into float_time
teubert fe29189
Uncomment example
teubert 6e7ba07
Remove exception
teubert e0ab157
Merge branch 'feature/traj_generation_modular' into float_time
teubert 91f7724
Remove waypoints in eg
teubert 53a7511
Fix lat/lon typo
teubert 3b50f84
Remove comments and merge functions
teubert a9e9688
Remove logging messages
teubert 99b50a7
Fix typo
teubert 4ff5c0b
More cleanup
teubert 07855ea
Merge branch 'feature/traj_generation_modular' into float_time
teubert cb59116
Merge pull request #553 from nasa/float_time
teubert ec7d17d
Fix tests for new time configuration
kjjarvis 728c8d0
Add uav model to cov
teubert 60c1456
Adding more tests for coverage
kjjarvis e5fda4f
Merge remote-tracking branch 'origin/feature/traj_generation_modular'…
kjjarvis 9f5064a
Fix typo
kjjarvis f80a8df
Merge branch 'dev' into feature/traj_generation_modular
teubert 19fd78e
Merge branch 'dev' into feature/traj_generation_modular
teubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') | ||
matteocorbetta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Great example, very clean and easy to understand now.