-
Notifications
You must be signed in to change notification settings - Fork 2
Add test and Docs for simple motor #282
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Simple Motor | ||
|
|
||
| Simple Motor class is based on the class called "attatched component", and written over the Motor class. For the fact that it is an attatched component, it is needed to set a parent for it, and just like on attached component, all information from the parent will be taken in count on the children methods. | ||
|
|
||
| Besides that the class needs some inputs values from the user, such as: | ||
| * static_thrust | ||
| * linear_coefficient | ||
| * distance_origin_to_propeller | ||
|
|
||
| ## *Thrust Center* _method_: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to use the same name as the method (thrust_center). |
||
|
|
||
| It's a property that returns a Vector2 with the values of the points where the thrust is applied. | ||
|
|
||
| As it is a Simple Motor, by default the force is applied on x in the distance from the origin to the propeller and in y, in 0 as it's seen in the example below: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it is a simplified model of a motor, by default the force is applied on the motor axis (y = 0), on a given distance (distance_origin_to_propeller) over the horizontal X-axis, as it's seen in the example below: |
||
|
|
||
| ```python | ||
| motor = SimpleMotor( | ||
| name='attached_component', | ||
| mass=1.4, | ||
| relative_position=Vector2(-0.4, 0.1), | ||
| relative_angle=math.radians(0), | ||
| static_thrust = 78, | ||
| linear_coefficient = -1, | ||
| distance_origin_to_propeller = 0.3 | ||
| ) | ||
|
|
||
| env = Ambient() | ||
| plane = FreeBody( | ||
| name='freebody', | ||
| type='generic_freebody', | ||
| mass=23.4, | ||
| position_cg=Vector2(-0.2, 0.02), | ||
| pitch_rot_inertia=5.2, | ||
| ambient=env, | ||
| ) | ||
|
|
||
| motor.set_parent(plane) | ||
|
|
||
| print(motor.thrust_center) | ||
| >>> Vector2(0.3, 0) | ||
| ``` | ||
| ##*Get Thrust* method: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. get_thrust |
||
|
|
||
| This methods is responsible for returning the magnitude value of the given thrust. To make the calculation, the method calls the function get_axial_thrust_from_linear_model, that takes into consideration the motor inputs, the environment variables, and the given velocity of the aircraft rotated to the axial velocity, considering the angle of attack. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It returns the magnitude of the thrust and the point where it is applied.
|
||
|
|
||
| The method returns to vectors, one with the thrust magnitude and the other one with the thrust_center, that was calculated on the method before. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be merged with the first phrase. |
||
|
|
||
| ```python | ||
|
|
||
| thrust_magnitude, thrust_center = motor.get_thrust() | ||
|
|
||
| print(thrust_magnitude) | ||
| >>> Vector2(82.269378, 0) | ||
| print(thrust_center) | ||
| >>> Vector2(0.3, 0) | ||
| ``` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import attr | ||
| from vec import Vector2 | ||
| from adr.World import Ambient | ||
| from adr.Components import FreeBody | ||
| from adr.Components.Powertrain import SimpleMotor | ||
| from adr.Methods.Powertrain.thrust_equations import get_axial_thrust_from_linear_model | ||
| import numpy.testing as npt | ||
| import math | ||
| import pytest | ||
|
|
||
| @pytest.fixture | ||
| def motor(): | ||
| motor = SimpleMotor( | ||
| name='attached_component', | ||
| mass=1.4, | ||
| relative_position=Vector2(-0.4, 0.1), | ||
| relative_angle=math.radians(0), | ||
| static_thrust = 78, | ||
| linear_coefficient = -1, | ||
| distance_origin_to_propeller = 0.3 | ||
| ) | ||
| return motor | ||
|
|
||
| @pytest.fixture | ||
| def plane(): | ||
| env = Ambient() | ||
| plane = FreeBody( | ||
| name='freebody', | ||
| type='generic_freebody', | ||
| mass=23.4, | ||
| position_cg=Vector2(-0.2, 0.02), | ||
| pitch_rot_inertia=5.2, | ||
| ambient=env, | ||
| ) | ||
| return plane | ||
|
|
||
| def test_thrust_center(motor, plane): | ||
|
|
||
| motor.set_parent(plane) | ||
|
|
||
| check_thrust_center = Vector2(0.3, 0) | ||
|
Comment on lines
+37
to
+41
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excess of blank lines |
||
|
|
||
| assert(motor.thrust_center == check_thrust_center) | ||
|
|
||
| def test_get_thrust(motor, plane): | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this blank line |
||
| motor.set_parent(plane) | ||
| x,y = motor.get_thrust() | ||
|
|
||
| check_thrust_center = Vector2(0.3, 0) | ||
| check_thrust = Vector2(82.269378, 0) | ||
|
|
||
| npt.assert_array_almost_equal(x, check_thrust) | ||
| npt.assert_array_almost_equal(y, check_thrust_center) | ||
|
Comment on lines
+48
to
+54
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. x and y are bad names, not recognizable. You could use thrust_center and thrust, as you use right after. |
||
|
|
||
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.
...based on the Motor class, which inherits from the AttachedComponent class, ...