Creation of the magnetometer sensor - #1190
Open
aitorperezgrau-sys wants to merge 90 commits into
Open
Conversation
…ire to have effect on different magnetometers, while ensuring efficiency and coherence with library
…s and magnetometer
…ignition wire type
…netometer creation of soft iron
…nction of the nose cone, intoduction of plate in inits modules,
…he radius of the nose_cone
…nd making it more modular.
… methods, and improvement of wire checking
…ape, better testing, and improvement of plotting
…to represent also method's incorrect parameters, and some docstring improvements
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull request type
Checklist
black rocketpy/ tests/) has passed locallypytest tests -m slow --runslow) have passed locallyNew behavior
The backbone of this PR is the creation of the magnetometer sensor.
Unlike other sensors, the measured value (magnetic field) is not a result of the flight simulation, as a result I used the WMM (World Magnetic Model) to obtain the magnetic field, and use frame changes to adjust the magnetic field reading to the sensor position.
When it comes to the noise and distortions included we can divide them into:
Magnetic distortion:
To represent the magnetic distortions (hard iron distortion, soft iron distortion and power interference) I created auxiliary classes
PlateandWire. Their distortions are applied in the Body Axis Coordinate System frame. Moreover, print and plot methods to validate their geometric position and its characteristics have been included together with new methods to satisfy their physical requirements.Sensor Noise
The noise related to the apparatus limitations has been covered using the existing
InertialSensorandSensornoise model and included in the measured value when the magnetic field is in the sensor frame.Furthermore, the documentation has been improved to include the new features and testing of every new element has been performed successfully.
Breaking change
Additional information
This PR requires pywmm Python library to evaluate the World Magnetic Model (WMM). It has been added to requirements.txt.
A change in the accelerometer sensor has been made, due to existing coordinate transformation error.
I opted for a software architecture that raises error when input parameters are incorrect because this approach allows users to know the cause of the error rather than seeing the error in an inner layer of the code. The obvious disadvantage is that for personal/private usage of the library there is no room for other parameters if desired; nonetheless, I have accounted for these having more flexible arguments. This is illustrated with the
ignition_wire_type, which allows any type of strings, so that It can be used for HIL testing.One of the functions implemented that were required to ensure a physically accurate model was the
general_radiusmethod. This method belongs to the rocket and returns the radius of the rocket, without the fins, for any value along the longitudinal axis. Also methods for adding plates and wires to the rocket have been implementedadd_wireandadd_plate.The distortion created by wires is calculated using the Biot-Savart expression for finite wire, while the soft iron distortion modeled by the Plates is the sum of the distortions of the points that form the plate.
The current model supports plates that turns around the rocket, are bigger than the size of the rocket, have radius changes. All of these plate geometry characteristics are illustrated in the following image:
Other images that illustrate the creation of the plate are the following


Focusing on code efficiency, the calculation of the magnetic distortion (by the wire, and the plate) is calculated once, when it is needed, and then stored in a dictionary with keys the position for which it has been calculated and value the magnetic field or soft iron distortion matrix computed.
Aiming to have a coherent naming style and better readability, almost all the variables/attributes that start with _ are Vector instances.
Plots of all plates and wires attached to the rocket have also been implemented in
_RocketPlot(draw_wires,draw_plates). Due to code repetition in this class, a function_rocket_shape_plotthat creates the outline of the rocket has been added.Example of
draw_wiresSupporting features were included in
sensor.py,nose_cone.py,tail.py,components.py....The user defined coordinate system orientation and the center of dry mass are required for the changes in coordinate systems in
WireandPlateand the rocket instance to which they are attached is necessary for the corresponding plotting associated classes. As a result, the_rocket_belongingmethod is implemented inWireandPlateand called when added to the rocket withadd_wireadd_plate. I am aware that cross referencing is not the best software practice, and it reduces the conceptual understanding of the inner library; however, I find it the best solution for this necessity.All plotting methods have been implemented using Matplotlib
The test "tests/unit/environment/test_environment_analysis.py::test_values" failed during local test, yet it is an atmospheric test unrelated to the new features. Outputs of Monte Carlo testing
.../monte_carlo_analysis/monte_carlo_analysis_outputs/mrs.inputs.txtand.../monte_carlo_analysis/monte_carlo_analysis_outputs/mrs.outputs.txthave been automatically included in the current version.