Skip to content

Commit

Permalink
Merge branch 'enh/generic-surfaces' into doc/generic-surface
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusStano authored Sep 14, 2024
2 parents 2e4d34b + 4815fc1 commit 78fb46c
Show file tree
Hide file tree
Showing 47 changed files with 4,464 additions and 198 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test_pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Cache Python dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-tests.txt') }}
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
run: pytest tests/acceptance --cov=rocketpy --cov-append --cov-report=xml

- name: Upload coverage to artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage.xml
Expand All @@ -75,9 +75,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Download all coverage reports
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
- name: Upload to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: |
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@
"github",
"Glauert",
"gmaps",
"Gnss",
"Gomes",
"Gonçalvez",
"grav",
"Guilherme",
"Haim",
"headlength",
"headwidth",
"hemis",
"hgtprs",
"hgtsfc",
Expand Down Expand Up @@ -245,6 +248,7 @@
"reversesort",
"reynolds",
"rightarrow",
"rmul",
"ROABs",
"rocketpy",
"rocketusage",
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ Attention: The newest changes should be on top -->

### Added

- DOC : Cavour Flight Example [#682](https://github.com/RocketPy-Team/RocketPy/pull/682)
- ENH: Fix Orientation Param of Inertial Sensors [#688](https://github.com/RocketPy-Team/RocketPy/pull/688)
- ENH: Adds Sensors classes [#683](https://github.com/RocketPy-Team/RocketPy/pull/683)
- DOC: Cavour Flight Example [#682](https://github.com/RocketPy-Team/RocketPy/pull/682)
- DOC: Halcyon Flight Example [#681](https://github.com/RocketPy-Team/RocketPy/pull/681)
- ENH: Adds GenericMotor.load_from_eng_file() method [#676](https://github.com/RocketPy-Team/RocketPy/pull/676)
- ENH: Introducing local sensitivity analysis [#575](https://github.com/RocketPy-Team/RocketPy/pull/575)
Expand Down
894 changes: 894 additions & 0 deletions docs/notebooks/sensors.ipynb

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions docs/reference/classes/sensors/abstract/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Sensors Abstract Classes
========================

.. toctree::
:maxdepth: 1
:caption: Contents:

Sensor Class <sensor>
Inertial Sensor Class <inertial_sensor>
Scalar Sensor Class <scalar_sensor>

5 changes: 5 additions & 0 deletions docs/reference/classes/sensors/abstract/inertial_sensor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Inertial Class
--------------

.. autoclass:: rocketpy.sensors.InertialSensor
:members:
5 changes: 5 additions & 0 deletions docs/reference/classes/sensors/abstract/scalar_sensor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Scalar Sensor Class
-------------------

.. autoclass:: rocketpy.sensors.ScalarSensor
:members:
5 changes: 5 additions & 0 deletions docs/reference/classes/sensors/abstract/sensor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Sensor Class
------------

.. autoclass:: rocketpy.sensors.Barometer
:members:
5 changes: 5 additions & 0 deletions docs/reference/classes/sensors/accelerometer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Accelerometer Class
---------------

.. autoclass:: rocketpy.sensors.Accelerometer
:members:
5 changes: 5 additions & 0 deletions docs/reference/classes/sensors/barometer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Barometer Class
---------------

.. autoclass:: rocketpy.sensors.Barometer
:members:
5 changes: 5 additions & 0 deletions docs/reference/classes/sensors/gnss_receiver.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GNSS Receiver Class
-------------------

.. autoclass:: rocketpy.sensors.GnssReceiver
:members:
5 changes: 5 additions & 0 deletions docs/reference/classes/sensors/gyroscope.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Gyroscope Class
---------------

.. autoclass:: rocketpy.sensors.Gyroscope
:members:
12 changes: 12 additions & 0 deletions docs/reference/classes/sensors/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Sensor Classes
==============

.. toctree::
:maxdepth: 1
:caption: Contents:

Sensors Abstract Classes <abstract/index>
Accelerometer Class <accelerometer>
Barometer Class <barometer>
Gyroscope Class <gyroscope>
GNSS Receiver Class <gnss>
1 change: 1 addition & 0 deletions docs/user/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ RocketPy's User Guide
Compare Flights Class<compare_flights.rst>
Deployable Payload <deployable.rst>
Air Brakes Example <airbrakes.rst>
../notebooks/sensors.ipynb
../matlab/matlab.rst

.. toctree::
Expand Down
2 changes: 1 addition & 1 deletion docs/user/rocket/rocket_axes.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _rocketaxes:
.. _rocket_axes:

Rocket Class Axes Definitions
=============================
Expand Down
1 change: 1 addition & 0 deletions rocketpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
TrapezoidalFins,
)
from .sensitivity import SensitivityModel
from .sensors import Accelerometer, Barometer, GnssReceiver, Gyroscope
from .simulation import Flight, MonteCarlo
from .stochastic import (
StochasticEllipticalFins,
Expand Down
54 changes: 52 additions & 2 deletions rocketpy/control/controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from inspect import signature

from ..prints.controller_prints import _ControllerPrints


Expand Down Expand Up @@ -52,6 +54,10 @@ def __init__(
the controller function can interact with. The objects are
listed in the same order as they are provided in the
`interactive_objects`.
7. `sensors` (list): A list of sensors that are attached to the
rocket. The most recent measurements of the sensors are provided
with the ``sensor.measurement`` attribute. The sensors are
listed in the same order as they are added to the rocket
This function will be called during the simulation at the specified
sampling rate. The function should evaluate and change the interactive
Expand All @@ -78,7 +84,7 @@ def __init__(
None
"""
self.interactive_objects = interactive_objects
self.controller_function = controller_function
self.controller_function = self.__init_controller_function(controller_function)
self.sampling_rate = sampling_rate
self.name = name
self.prints = _ControllerPrints(self)
Expand All @@ -88,7 +94,45 @@ def __init__(
else:
self.observed_variables = []

def __call__(self, time, state_vector, state_history):
def __init_controller_function(self, controller_function):
"""Checks number of arguments of the controller function and initializes
it with the correct number of arguments. This is a workaround to allow
the controller function to receive sensors without breaking changes"""
sig = signature(controller_function)
if len(sig.parameters) == 6:

# pylint: disable=unused-argument
def new_controller_function(
time,
sampling_rate,
state_vector,
state_history,
observed_variables,
interactive_objects,
sensors,
):
return controller_function(
time,
sampling_rate,
state_vector,
state_history,
observed_variables,
interactive_objects,
)

elif len(sig.parameters) == 7:
new_controller_function = controller_function
else:
raise ValueError(
"The controller function must have 6 or 7 arguments. "
"The arguments must be in the following order: "
"(time, sampling_rate, state_vector, state_history, "
"observed_variables, interactive_objects, sensors)."
"Sensors argument is optional."
)
return new_controller_function

def __call__(self, time, state_vector, state_history, sensors):
"""Call the controller function. This is used by the simulation class.
Parameters
Expand All @@ -104,6 +148,11 @@ def __call__(self, time, state_vector, state_history):
history is a list of every state vector of every step of the
simulation. The state history is a list of lists, where each
sublist is a state vector and is ordered from oldest to newest.
sensors : list
A list of sensors that are attached to the rocket. The most recent
measurements of the sensors are provided with the
``sensor.measurement`` attribute. The sensors are listed in the same
order as they are added to the rocket.
Returns
-------
Expand All @@ -116,6 +165,7 @@ def __call__(self, time, state_vector, state_history):
state_history,
self.observed_variables,
self.interactive_objects,
sensors,
)
if observed_variables is not None:
self.observed_variables.append(observed_variables)
Expand Down
2 changes: 1 addition & 1 deletion rocketpy/environment/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def utm_to_geodesic( # pylint: disable=too-many-locals,too-many-statements
x, y, utm_zone, hemis, semi_major_axis=6378137.0, flattening=1 / 298.257223563
):
# NOTE: already documented in the Environment class.
# TODO: deprecated the static method from the environment class, use only this one.
# TODO: deprecate the static method from the environment class, use only this one.

if hemis == "N":
y = y + 10000000
Expand Down
Loading

0 comments on commit 78fb46c

Please sign in to comment.