-
-
Notifications
You must be signed in to change notification settings - Fork 237
ENH: Adds GNSS Receiver sensor #636
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
27 commits
Select commit
Hold shift + click to select a range
88cd9a2
ENH: class GNSS
MateusStano 686e665
ENH: gnss prints
MateusStano a5c8513
ENH: add params to measure call
MateusStano 7c0e507
ENH: export data
MateusStano ae682cb
ENH: pass env in .measure
MateusStano 575148a
DOC: gnss attribute docs
MateusStano da74430
MNT: units in prints
MateusStano c62f475
Merge branch 'enh/sensors-impl' into enh/gps
MateusStano 0f25181
MNT: fix merge errors
MateusStano 0bc461d
TST: add gnss tests
MateusStano 3b46ae2
TST: fix time nodes tests
MateusStano dd4d63c
DEV: add gnss to sensors testing notebook
MateusStano 137c6ec
Merge branch 'enh/sensors-impl' into enh/gps
MateusStano f926472
DEV: fix merge errors
MateusStano d9458a1
MNT: lint and isort
MateusStano 0e1c58e
MNT: black notebooks
MateusStano 0744b79
TST: fix test by inversion of rotation
MateusStano e6fdaeb
TST: lower rel tolerances and delete duplicated tests
MateusStano 6f741df
MNT: minor fixes
MateusStano 9ce718e
ENH: export sensor data by sensor name
MateusStano a28e7bd
MNT: use inverted_haversine in GNSS
MateusStano 887e0a9
BUG: bearing unit in inverted_haversine
MateusStano dc43f27
MNT: pylint
MateusStano 2295609
TST: add test for export with sensor name
MateusStano 015f5ea
MNT: rename `GNSS` class to `GnssReceiver`
Gui-FernandesBR 26859e6
MNT: fix lint
Gui-FernandesBR 6265f05
MNT: rename gnss file
Gui-FernandesBR 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from .accelerometer import Accelerometer | ||
| from .barometer import Barometer | ||
| from .gnss_receiver import GnssReceiver | ||
| from .gyroscope import Gyroscope | ||
| from .sensor import InertialSensor, ScalarSensor, Sensor |
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,125 @@ | ||
| import math | ||
|
|
||
| import numpy as np | ||
|
|
||
| from rocketpy.tools import inverted_haversine | ||
|
|
||
| from ..mathutils.vector_matrix import Matrix, Vector | ||
| from ..prints.sensors_prints import _GnssReceiverPrints | ||
| from .sensor import ScalarSensor | ||
|
|
||
|
|
||
| class GnssReceiver(ScalarSensor): | ||
| """Class for the GNSS Receiver sensor. | ||
|
|
||
| Attributes | ||
| ---------- | ||
| prints : _GnssReceiverPrints | ||
| Object that contains the print functions for the sensor. | ||
| sampling_rate : float | ||
| Sample rate of the sensor in Hz. | ||
| position_accuracy : float | ||
| Accuracy of the sensor interpreted as the standard deviation of the | ||
| position in meters. | ||
| altitude_accuracy : float | ||
| Accuracy of the sensor interpreted as the standard deviation of the | ||
| position in meters. | ||
| name : str | ||
| The name of the sensor. | ||
| measurement : tuple | ||
| The measurement of the sensor. | ||
| measured_data : list | ||
| The stored measured data of the sensor. | ||
| """ | ||
|
|
||
| units = "°, m" | ||
|
|
||
| def __init__( | ||
| self, | ||
| sampling_rate, | ||
| position_accuracy=0, | ||
| altitude_accuracy=0, | ||
| name="GnssReceiver", | ||
| ): | ||
| """Initialize the Gnss Receiver sensor. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| sampling_rate : float | ||
| Sample rate of the sensor in Hz. | ||
| position_accuracy : float | ||
| Accuracy of the sensor interpreted as the standard deviation of the | ||
| position in meters. Default is 0. | ||
| altitude_accuracy : float | ||
| Accuracy of the sensor interpreted as the standard deviation of the | ||
| position in meters. Default is 0. | ||
| name : str | ||
| The name of the sensor. Default is "GnssReceiver". | ||
| """ | ||
| super().__init__(sampling_rate=sampling_rate, name=name) | ||
| self.position_accuracy = position_accuracy | ||
| self.altitude_accuracy = altitude_accuracy | ||
|
|
||
| self.prints = _GnssReceiverPrints(self) | ||
|
|
||
| def measure(self, time, **kwargs): | ||
| """Measure the position of the rocket in latitude, longitude and | ||
| altitude. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| time : float | ||
| Current time in seconds. | ||
| kwargs : dict | ||
| Keyword arguments dictionary containing the following keys: | ||
| - u : np.array | ||
| State vector of the rocket. | ||
| - u_dot : np.array | ||
| Derivative of the state vector of the rocket. | ||
| - relative_position : np.array | ||
| Position of the sensor relative to the rocket center of mass. | ||
| - environment : Environment | ||
| Environment object containing the atmospheric conditions. | ||
| """ | ||
| u = kwargs["u"] | ||
| relative_position = kwargs["relative_position"] | ||
| lat, lon = kwargs["environment"].latitude, kwargs["environment"].longitude | ||
| earth_radius = kwargs["environment"].earth_radius | ||
|
|
||
| # Get from state u and add relative position | ||
| x, y, z = (Matrix.transformation(u[6:10]) @ relative_position) + Vector(u[0:3]) | ||
| # Apply accuracy to the position | ||
| x = np.random.normal(x, self.position_accuracy) | ||
| y = np.random.normal(y, self.position_accuracy) | ||
| altitude = np.random.normal(z, self.altitude_accuracy) | ||
|
|
||
| # Convert x and y to latitude and longitude | ||
| drift = (x**2 + y**2) ** 0.5 | ||
| bearing = (2 * math.pi - math.atan2(-x, y)) * (180 / math.pi) | ||
|
|
||
| # Applies the haversine equation to find final lat/lon coordinates | ||
| latitude, longitude = inverted_haversine(lat, lon, drift, bearing, earth_radius) | ||
|
|
||
| self.measurement = (latitude, longitude, altitude) | ||
| self._save_data((time, *self.measurement)) | ||
|
|
||
| def export_measured_data(self, filename, file_format="csv"): | ||
| """Export the measured values to a file | ||
|
|
||
| Parameters | ||
| ---------- | ||
| filename : str | ||
| Name of the file to export the values to | ||
| file_format : str | ||
| Format of the file to export the values to. Options are "csv" and | ||
| "json". Default is "csv". | ||
|
|
||
| Returns | ||
| ------- | ||
| None | ||
| """ | ||
| self._generic_export_measured_data( | ||
| filename=filename, | ||
| file_format=file_format, | ||
| data_labels=("t", "latitude", "longitude", "altitude"), | ||
| ) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.