-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Autopilot. Update SimConsole. Add new examples.
- Loading branch information
1 parent
04fa9ae
commit 7d7fe86
Showing
25 changed files
with
1,533 additions
and
200 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
__pycache__/ | ||
*.py[cod] | ||
.pytest_cache/ | ||
|
||
htmlcov/ | ||
|
||
logs/ | ||
*.log |
This file contains 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 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 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,78 @@ | ||
""" | ||
Copyright (c) 2024 Pablo Ramirez Escudero | ||
This software is released under the MIT License. | ||
https://opensource.org/licenses/MIT | ||
""" | ||
|
||
import time | ||
|
||
import numpy as np | ||
from scipy import signal | ||
|
||
from simulator.aircraft import ( | ||
AircraftDynamics, | ||
ControlDeltas, | ||
load_airframe_parameters_from_yaml, | ||
) | ||
from simulator.autopilot import Autopilot | ||
from simulator.cli import SimConsole | ||
from simulator.gui import AttitudePositionPanel, FlightControlPanel | ||
from simulator.utils import wait_animation | ||
|
||
params_file = r"config/aerosonde_parameters.yaml" | ||
aerosonde_params = load_airframe_parameters_from_yaml(params_file) | ||
|
||
dt = 0.01 | ||
x0 = np.array( | ||
[ | ||
0.0, # pd | ||
0.0, # pe | ||
0.0, # pn | ||
25.0, # u | ||
0.0, # v | ||
0.0, # w | ||
1.0, # q0 | ||
0.0, # q1 | ||
0.0, # q2 | ||
0.0, # q3 | ||
0.0, # p | ||
0.0, # q | ||
0.0, # r | ||
] | ||
) | ||
uav = AircraftDynamics(dt, aerosonde_params, use_quat=True, x0=x0) | ||
x_trim, delta_trim = uav.trim(Va=25.0) | ||
|
||
autopilot = Autopilot(dt, aerosonde_params, uav.state) | ||
|
||
cli = SimConsole() | ||
gui = AttitudePositionPanel(use_blit=True, pos_3d=True) | ||
# gui = FlightControlPanel(use_blit=True) | ||
|
||
t_sim = 0.0 # simulation time | ||
k_sim = 0 # simulation steps | ||
t0 = time.time() | ||
while True: | ||
t_sim += dt | ||
k_sim += 1 | ||
|
||
roll_cmd = np.deg2rad(0.0) * signal.square(2*np.pi*0.5*t_sim) | ||
pitch_cmd = np.deg2rad(0.0) * signal.sawtooth(2*np.pi*0.1*t_sim, width=0.5) | ||
Va_cmd = 25.0 + 10.0 * signal.sawtooth(2*np.pi*0.05*t_sim, width=0.5) | ||
h_cmd = 0.0 * signal.sawtooth(2*np.pi*0.01*t_sim, width=0.5) | ||
X_cmd = np.deg2rad(90.0) * signal.square(2*np.pi*0.01*t_sim) | ||
# autopilot.control_pitch_roll(roll_target=roll_cmd, pitch_target=pitch_cmd, airspeed_target=Va_cmd) | ||
autopilot.control_course_altitude(altitude_target=h_cmd, course_target=X_cmd, airspeed_target=25.0) | ||
|
||
uav.update(autopilot.control_deltas) # update simulation states | ||
|
||
gui.add_data(time=t_sim, state=uav.state, autopilot_status=autopilot.status) | ||
|
||
if k_sim % 10 == 0: # update interface each 10 steps | ||
t_real = time.time() - t0 | ||
cli.print_time(t_sim, t_real, dt, k_sim, style='simple') | ||
cli.print_aircraft_state(uav.state, style='simple') | ||
cli.print_control_deltas(uav.control_deltas, style='simple') | ||
cli.print_autopilot_status(autopilot.status, style='simple') | ||
gui.update(state=uav.state, pause=0.01) |
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -2,6 +2,6 @@ matplotlib==3.8.4 | |
numpy==2.1.0 | ||
pytest==8.2.2 | ||
PyYAML==6.0.2 | ||
rich==13.7.1 | ||
rich==13.8.0 | ||
scipy==1.14.1 | ||
toml==0.10.2 |
This file contains 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 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
Oops, something went wrong.