Skip to content

Commit

Permalink
Merge pull request #344 from RocketPy-Team/enh/rail-buttons-class
Browse files Browse the repository at this point in the history
ENH: RailButtons Class
  • Loading branch information
MateusStano authored Jun 10, 2023
2 parents 586f309 + 6304ab5 commit 8ddf577
Show file tree
Hide file tree
Showing 23 changed files with 411 additions and 250 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Calisto = Rocket(
centerOfDryMassPosition=0,
coordinateSystemOrientation="tailToNose"
)
Calisto.setRailButtons([0.2, -0.5])
Calisto.setRailButtons(0.2, -0.5)
Calisto.addMotor(Pro75M1670, position=-1.255)
Calisto.addNose(length=0.55829, kind="vonKarman", position=1.278)
Calisto.addTrapezoidalFins(
Expand Down
2 changes: 1 addition & 1 deletion docs/development/rocketpy_as_developer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Then the rail buttons must be set:

.. code-block:: python
Calisto.setRailButtons([0.2, -0.5])
Calisto.setRailButtons(0.2, -0.5)
In sequence, the aerodynamic surfaces must be set.
If a lift curve for the fin set is not specified, it is assumed that they behave according to a linearized model with a coefficient calculated with Barrowman's theory.
Expand Down
2 changes: 1 addition & 1 deletion docs/matlab/Getting_Started.m
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
'coordinateSystemOrientation', "nozzleToCombustionChamber", ...
));

Calisto.setRailButtons([0.2, -0.5])
Calisto.setRailButtons(0.2, -0.5)

Calisto.addMotor(Pro75M1670, position=-1.255)
% Adding Aerodynamic Surfaces
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/compare_flights_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
" coordinateSystemOrientation=\"tailToNose\",\n",
")\n",
"\n",
"Calisto.setRailButtons([0.2, -0.5])\n",
"Calisto.setRailButtons(0.2, -0.5)\n",
"\n",
"Calisto.addMotor(Pro75M1670, position=-1.255)\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/notebooks/deployable_payload_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4634,7 +4634,7 @@
" powerOnDrag=\"../../data/calisto/powerOnDragCurve.csv\",\n",
")\n",
"\n",
"Rocket1.setRailButtons([0.2, -0.5])\n",
"Rocket1.setRailButtons(0.2, -0.5)\n",
"\n",
"NoseCone_Rocket1 = Rocket1.addNose(\n",
" length=0.55829, kind=\"vonKarman\", distanceToCM=0.71971\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@
" centerOfDryMassPosition=0,\n",
" coordinateSystemOrientation=\"tailToNose\",\n",
" )\n",
" Valetudo.setRailButtons([0.224, -0.93], 30)\n",
" Valetudo.setRailButtons(0.224, -0.93, 30)\n",
"\n",
" Valetudo.addMotor(Keron, position=setting[\"distanceRocketNozzle\"])\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
" centerOfDryMassPosition=0,\n",
" coordinateSystemOrientation=\"tailToNose\",\n",
" )\n",
" Valetudo.setRailButtons([0.224, -0.93], 30)\n",
" Valetudo.setRailButtons(0.224, -0.93, 30)\n",
"\n",
" Valetudo.addMotor(Keron, position=setting[\"distanceRocketNozzle\"])\n",
"\n",
Expand Down
298 changes: 150 additions & 148 deletions docs/notebooks/getting_started.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/notebooks/getting_started_colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@
" coordinateSystemOrientation=\"tailToNose\",\n",
")\n",
"\n",
"Calisto.setRailButtons([0.2, -0.5])"
"Calisto.setRailButtons(0.2, -0.5)"
]
},
{
Expand Down Expand Up @@ -1364,7 +1364,7 @@
" coordinateSystemOrientation=\"tailToNose\",\n",
")\n",
"\n",
"Calisto.setRailButtons([0.2, -0.5])\n",
"Calisto.setRailButtons(0.2, -0.5)\n",
"\n",
"Calisto.addMotor(Pro75M1670, position=-1.255)\n",
"\n",
Expand Down Expand Up @@ -1526,7 +1526,7 @@
" coordinateSystemOrientation=\"tailToNose\",\n",
")\n",
"\n",
"Calisto.setRailButtons([0.2, -0.5])\n",
"Calisto.setRailButtons(0.2, -0.5)\n",
"\n",
"Calisto.addMotor(Pro75M1670, position=-1.255)\n",
"\n",
Expand Down Expand Up @@ -1678,7 +1678,7 @@
" coordinateSystemOrientation=\"tailToNose\",\n",
" )\n",
"\n",
" Calisto.setRailButtons([0.2, -0.5])\n",
" Calisto.setRailButtons(0.2, -0.5)\n",
"\n",
" Calisto.addMotor(Pro75M1670, position=-1.255)\n",
"\n",
Expand Down Expand Up @@ -1805,7 +1805,7 @@
" coordinateSystemOrientation=\"tailToNose\",\n",
" )\n",
"\n",
" Calisto.setRailButtons([0.2, -0.5])\n",
" Calisto.setRailButtons(0.2, -0.5)\n",
"\n",
" Calisto.addMotor(Pro75M1670, position=-1.255)\n",
"\n",
Expand Down
126 changes: 115 additions & 11 deletions rocketpy/AeroSurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(self, name):
self.cpx = 0
self.cpy = 0
self.cpz = 0
self.position = None # relative to rocket
self.name = name
return None

Expand Down Expand Up @@ -305,8 +304,6 @@ def geometricalInfo(self):
"""
print(f"\nGeometric Information of {self.name}")
print("-------------------------------")
if self.position:
print(f"Position: {self.position:.3f} m")
print(f"Length: {self.length:.3f} m")
print(f"Kind: {self.kind}")
print(f"Base Radius: {self.baseRadius:.3f} m")
Expand Down Expand Up @@ -767,8 +764,6 @@ def geometricalInfo(self):
print("Fin Type: Elliptical")
print("Root Chord: {:.3f} m".format(self.rootChord))
print("Span: {:.3f} m".format(self.span))
if self.position:
print("Position: {:.3f} m".format(self.position))
print("Cant Angle: {:.3f} °".format(self.cantAngle))
print("Longitudinal Section Area: {:.3f} m²".format(self.Af))
print("Aspect Ratio: {:.3f} ".format(self.AR))
Expand Down Expand Up @@ -1656,7 +1651,7 @@ class Tail(AeroSurface):
downwards (top -> bottom). Origin located at top of the tail (generally the portion
closest to the rocket's nose).
Parameters
Attributes
----------
Tail.topRadius : int, float
Radius of the top of the tail. The top radius is defined as the radius
Expand All @@ -1671,9 +1666,6 @@ class Tail(AeroSurface):
The reference rocket radius used for lift coefficient normalization in meters.
Tail.name : str
Name of the tail. Default is 'Tail'.
Attributes
----------
Tail.cpx : int, float
x local coordinate of the center of pressure of the tail.
Tail.cpy : int, float
Expand Down Expand Up @@ -1831,6 +1823,7 @@ def evaluateLiftCoefficient(self):
def evaluateCenterOfPressure(self):
"""Calculates and returns the center of pressure of the tail in local
coordinates. The center of pressure position is saved and stored as a tuple.
Parameters
----------
None
Expand Down Expand Up @@ -1860,8 +1853,6 @@ def geometricalInfo(self):

print(f"\nGeometric Information of {self.name}")
print("-------------------------------")
if self.position:
print(f"Tail Position: {self.position:.3f} m")
print(f"Tail Top Radius: {self.topRadius:.3f} m")
print(f"Tail Bottom Radius: {self.bottomRadius:.3f} m")
print(f"Tail Length: {self.length:.3f} m")
Expand Down Expand Up @@ -1892,3 +1883,116 @@ def allInfo(self):
self.aerodynamicInfo()

return None


class RailButtons(AeroSurface):
"""Class that defines a rail button pair or group.
Attributes
----------
RailButtons.buttons_distance : int, float
Distance between the two rail buttons closest to the nozzle.
RailButtons.angular_position : int, float
Angular position of the rail buttons in degrees measured
as the rotation around the symmetry axis of the rocket
relative to one of the other principal axis.
"""

def __init__(self, buttons_distance, angular_position=45, name="Rail Buttons"):
"""Initializes RailButtons Class.
Parameters
----------
buttons_distance : int, float
Distance between the first and the last rail button in meters.
angular_position : int, float, optional
Angular position of the rail buttons in degrees measured
as the rotation around the symmetry axis of the rocket
relative to one of the other principal axis.
name : string, optional
Name of the rail buttons. Default is "Rail Buttons".
Returns
-------
None
"""
self.buttons_distance = buttons_distance
self.angular_position = angular_position
self.name = name

self.evaluateLiftCoefficient()
self.evaluateCenterOfPressure()
return None

def evaluateCenterOfPressure(self):
"""Evaluates the center of pressure of the rail buttons. Rail buttons
do not contribute to the center of pressure of the rocket.
Returns
-------
None
"""
self.cpx = 0
self.cpy = 0
self.cpz = 0
self.cp = (self.cpx, self.cpy, self.cpz)
return None

def evaluateLiftCoefficient(self):
"""Evaluates the lift coefficient curve of the rail buttons. Rail
buttons do not contribute to the lift coefficient of the rocket.
Returns
-------
None
"""
self.clalpha = Function(
lambda mach: 0,
"Mach",
f"Lift coefficient derivative for {self.name}",
)
self.cl = Function(
lambda alpha, mach: 0,
["Alpha (rad)", "Mach"],
"Cl",
)
return None

def evaluateGeometricalParameters(self):
"""Evaluates the geometrical parameters of the rail buttons. Rail
buttons do not contribute to the geometrical parameters of the rocket.
Returns
-------
None
"""
return None

def geometricalInfo(self):
"""Returns the geometrical info of the rail buttons. Rail buttons
do not have geometrical parameters.
Returns
-------
None
"""
return None

def aerodynamicInfo(self):
"""Returns the aerodynamic info of the aerodynamic surface.
Returns
-------
None
"""
return None

def allInfo(self):
"""Returns all info of the aerodynamic surface.
Returns
-------
None
"""
return None
31 changes: 31 additions & 0 deletions rocketpy/Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,37 @@ def get_by_type(self, component_type):
]
return component_type_list

def get_tuple_by_type(self, component_type):
"""Search the list of components and return a list with all the components
of the given type.
Parameters
----------
component_type: type
The type of component to be returned.
Returns:
--------
list
A list of components matching the specified type.
"""
component_type_list = [
c for c in self._components if isinstance(c.component, component_type)
]
return component_type_list

def get_positions(self):
"""Return a list of all the positions of the components in the list of
components.
Returns
-------
list
A list of all the positions of the components in the list of
components.
"""
return [c.position for c in self._components]

def remove(self, component):
"""Remove a component from the list of components. If more than one
instance of the same component is present in the list, only the first
Expand Down
Loading

0 comments on commit 8ddf577

Please sign in to comment.