Skip to content
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

ENH: CP and Thrust Eccentricity Effects Generate Roll Moment #617

Merged
merged 7 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions rocketpy/simulation/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,9 @@
M3 += M3f - M3d
except AttributeError:
pass
# Off center moment
M3 += self.rocket.cp_eccentricity_x * R2 - self.rocket.cp_eccentricity_y * R1

Check warning on line 1498 in rocketpy/simulation/flight.py

View check run for this annotation

Codecov / codecov/patch

rocketpy/simulation/flight.py#L1498

Added line #L1498 was not covered by tests

# Calculate derivatives
# Angular acceleration
alpha1 = (
Expand Down Expand Up @@ -1651,10 +1654,6 @@
R3 = air_brakes_force # Substitutes rocket drag coefficient
else:
R3 += air_brakes_force
## Off center moment
M1 += self.rocket.cp_eccentricity_y * R3
M2 -= self.rocket.cp_eccentricity_x * R3

# Get rocket velocity in body frame
vB = Kt @ v
# Calculate lift and moment for each component of the rocket
Expand Down Expand Up @@ -1724,11 +1723,24 @@
M3 += M3f - M3d
except AttributeError:
pass

# Off center moment
thrust = self.rocket.motor.thrust.get_value_opt(t)
M1 += (
self.rocket.cp_eccentricity_y * R3
+ self.rocket.thrust_eccentricity_x * thrust
)
M2 -= (
self.rocket.cp_eccentricity_x * R3
- self.rocket.thrust_eccentricity_y * thrust
)
M3 += self.rocket.cp_eccentricity_x * R2 - self.rocket.cp_eccentricity_y * R1

weightB = Kt @ Vector([0, 0, -total_mass * self.env.gravity.get_value_opt(z)])
T00 = total_mass * r_CM
T03 = 2 * total_mass_dot * (r_NOZ - r_CM) - 2 * total_mass * r_CM_dot
T04 = (
Vector([0, 0, self.rocket.motor.thrust.get_value_opt(t)])
Vector([0, 0, thrust])
- total_mass * r_CM_ddot
- 2 * total_mass_dot * r_CM_dot
+ total_mass_ddot * (r_NOZ - r_CM)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,37 @@ def test_rolling_flight(
assert test_flight.all_info() == None


@patch("matplotlib.pyplot.show")
def test_eccentricity_on_flight(
mock_show,
example_plain_env,
cesaroni_m1670,
calisto,
calisto_nose_cone,
calisto_trapezoidal_fins,
calisto_tail,
):
test_rocket = calisto

test_rocket.set_rail_buttons(0.082, -0.618)
test_rocket.add_motor(cesaroni_m1670, position=-1.373)
calisto.aerodynamic_surfaces.add(calisto_trapezoidal_fins, position=-1.04956)
calisto.aerodynamic_surfaces.add(calisto_nose_cone, 1.160)
calisto.aerodynamic_surfaces.add(calisto_tail, -1.313)
calisto.add_cm_eccentricity(x=-0.01, y=-0.01)

test_flight = Flight(
rocket=test_rocket,
environment=example_plain_env,
rail_length=5.2,
inclination=85,
heading=0,
terminate_on_apogee=True,
)

assert test_flight.all_info() == None


@patch("matplotlib.pyplot.show")
def test_air_brakes_flight(mock_show, flight_calisto_air_brakes):
"""Test the flight of a rocket with air brakes. This test only validates
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/test_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,26 @@ def test_get_inertia_tensor_derivative_at_time(calisto):
assert pytest.approx(0, atol) == inertia_tensor.y[2]
assert pytest.approx(0, atol) == inertia_tensor.z[0]
assert pytest.approx(0, atol) == inertia_tensor.z[1]


def test_add_cp_eccentricity(calisto):
"""Test add_cp_eccentricity method of the Rocket class."""
calisto.add_cp_eccentricity(0.1, 0.1)
assert calisto.cp_eccentricity_x == 0.1
assert calisto.cp_eccentricity_y == 0.1
Gui-FernandesBR marked this conversation as resolved.
Show resolved Hide resolved


def test_add_thrust_eccentricity(calisto):
"""Test add_thrust_eccentricity method of the Rocket class."""
calisto.add_thrust_eccentricity(0.1, 0.1)
assert calisto.thrust_eccentricity_x == 0.1
assert calisto.thrust_eccentricity_y == 0.1


def test_add_cm_eccentricity(calisto):
"""Test add_cm_eccentricity method of the Rocket class."""
calisto.add_cm_eccentricity(-0.1, -0.1)
assert calisto.cp_eccentricity_x == 0.1
assert calisto.cp_eccentricity_y == 0.1
assert calisto.thrust_eccentricity_x == 0.1
assert calisto.thrust_eccentricity_y == 0.1
Loading