Skip to content

Commit 8daa37c

Browse files
committed
add integrated test for spinningBodyTwoDOF branching
1 parent dfa97f0 commit 8daa37c

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# ISC License
2+
#
3+
# Copyright (c) 2024, Autonomous Vehicle Systems Lab, University of Colorado at Boulder
4+
#
5+
# Permission to use, copy, modify, and/or distribute this software for any
6+
# purpose with or without fee is hereby granted, provided that the above
7+
# copyright notice and this permission notice appear in all copies.
8+
#
9+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
17+
18+
#
19+
# Unit Test Script
20+
# Module Name: spinningBody2TwoDOF
21+
# Author: Andrew Morell
22+
# Creation Date: December 18, 2024
23+
#
24+
25+
import inspect
26+
import os
27+
import pytest
28+
import numpy
29+
import matplotlib.pyplot as plt
30+
31+
filename = inspect.getframeinfo(inspect.currentframe()).filename
32+
path = os.path.dirname(os.path.abspath(filename))
33+
splitPath = path.split('simulation')
34+
35+
from Basilisk.utilities import SimulationBaseClass, unitTestSupport, macros
36+
from Basilisk.simulation import spacecraft, spinningBodyTwoDOFStateEffector, gravityEffector
37+
from Basilisk.architecture import messaging
38+
39+
40+
# uncomment this line is this test is to be skipped in the global unit test run, adjust message as needed
41+
# @pytest.mark.skipif(conditionstring)
42+
# uncomment this line if this test has an expected failure, adjust message as needed
43+
# @pytest.mark.xfail() # need to update how the RW states are defined
44+
# provide a unique test method name, starting with test_
45+
46+
@pytest.mark.parametrize("cmdTorque1, lock1, theta1Ref, cmdTorque2, lock2, theta2Ref", [
47+
(0.0, False, 0.0, 0.0, False, 0.0)
48+
, (0.0, True, 0.0, 0.0, False, 0.0)
49+
, (0.0, False, 0.0, 0.0, True, 0.0)
50+
, (0.0, True, 0.0, 0.0, True, 0.0)
51+
, (1.0, False, 0.0, -2.0, False, 0.0)
52+
, (0.0, False, 10.0 * macros.D2R, 0.0, False, -5.0 * macros.D2R)
53+
, (0.0, False, -5.0 * macros.D2R, 0.0, False, 10.0 * macros.D2R)
54+
])
55+
def test_spinningBody(show_plots, cmdTorque1, lock1, theta1Ref, cmdTorque2, lock2, theta2Ref):
56+
r"""
57+
**Validation Test Description**
58+
This integrated test checks the functionality of attaching a dynamic effector onto a spinningBodyTwoDOF such that
59+
spinningBodyTwoDOF is the dynamical parent rather than the hub. Note that this can also be done in some cases using
60+
the messaging system (see test_thruster_dynamics_attached_body.py) but is done here using the dynParamManager to
61+
achieve time varying motion with respect to the hub, two-way dynamical coupling, and sub-integration timestep
62+
resolution.
63+
64+
The integrated test sets up an extForceTorque dynamic effector as normal, but then converts the direction and
65+
location to take into account being in the spinningBodyTwoDOF local body. The extForceTorque effector is set to
66+
apply a force and torque for the first half of the simulation, and then turn off.
67+
68+
69+
70+
71+
As with the other tests, the expected forces and torques are compared with the values from the module to check that
72+
everything matches accordingly.
73+
74+
This unit test sets up a spacecraft with a single-axis rotating rigid body attached to a rigid hub. The spinning
75+
body's center of mass is off-center from the spinning axis and the position of the axis is arbitrary. The scenario
76+
includes gravity acting on both the spacecraft and the effector.
77+
78+
**Description of Variables Being Tested**
79+
80+
In this file we are checking the principles of conservation of energy and angular momentum. Both the orbital and
81+
rotational energy and angular momentum must be maintained when conservative forces like gravity are present.
82+
Therefore, the values of the variables
83+
84+
- ``finalOrbAngMom``
85+
- ``finalOrbEnergy``
86+
- ``finalRotAngMom``
87+
- ``finalRotEnergy``
88+
89+
against their initial values.
90+
"""
91+
[testResults, testMessage] = spinningBody(show_plots, cmdTorque1, lock1, theta1Ref, cmdTorque2, lock2, theta2Ref)
92+
assert testResults < 1, testMessage

0 commit comments

Comments
 (0)