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

Feature/330 gravity effector refactor #331

Merged
merged 13 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion docs/source/Support/bskReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ Version |release|
- Updated :ref:`thrusterPlatformReference` to add an input and output thruster config msg, and integral feedback term
which dumps steady-state momentum in case of uncertainties on the CM location.
- Created :ref:`thrustCMEstimation` to perform online estimation of the CM using gimbaled thruster torque measurements.

- Refactored ``GravityEffector``. Adding custom gravity models can now be done by subclassing ``GravityModel``. The
utility method ``useSphericalHarmonicsGravityModel`` has been added to planetary body objects, which makes the body
use spherical harmonics and loads them from a file with a single command. Similarly, the methods ``usePolyhedralGravityModel``
and ``usePointMassGravityModel`` have been added.

Version 2.2.0 (June 28, 2023)
-----------------------------
Expand Down
6 changes: 2 additions & 4 deletions examples/OpNavScenarios/modelsOpNav/BSK_OpNavDynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ def SetGravityEffector(self):
self.mars = 2
self.jupiter = 3

simIncludeGravBody.loadGravFromFile(bskPath + '/supportData/LocalGravData/GGM2BData.txt'
, gravBodies['mars barycenter'].spherHarm
, 2
)
gravBodies['mars barycenter'].useSphericalHarmonicsGravityModel(
bskPath + '/supportData/LocalGravData/GGM2BData.txt', 2)

self.scObject.gravField.gravBodies = spacecraft.GravBodyVector(list(self.gravFactory.gravBodies.values()))
self.gravFactory.createSpiceInterface(bskPath + '/supportData/EphemerisData/',
Expand Down
10 changes: 4 additions & 6 deletions examples/scenarioBasicOrbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,17 @@ def run(show_plots, orbitCase, useSphericalHarmonics, planetCase):
planet = gravFactory.createMarsBarycenter()
planet.isCentralBody = True # ensure this is the central gravitational body
if useSphericalHarmonics:
planet.useSphericalHarmParams = True
simIncludeGravBody.loadGravFromFile(bskPath + '/supportData/LocalGravData/GGM2BData.txt',
planet.spherHarm, 100)
planet.useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/GGM2BData.txt', 100)

else: # Earth
planet = gravFactory.createEarth()
planet.isCentralBody = True # ensure this is the central gravitational body
if useSphericalHarmonics:
# If extra customization is required, see the createEarth() macro to change additional values.
# For example, the spherical harmonics are turned off by default. To engage them, the following code
# is used
planet.useSphericalHarmParams = True
simIncludeGravBody.loadGravFromFile(bskPath + '/supportData/LocalGravData/GGM03S-J2-only.txt',
planet.spherHarm, 2)
planet.useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/GGM03S-J2-only.txt', 2)

# The value 2 indicates that the first two harmonics, excluding the 0th order harmonic,
# are included. This harmonics data file only includes a zeroth order and J2 term.
mu = planet.mu
Expand Down
9 changes: 3 additions & 6 deletions examples/scenarioBasicOrbitStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,13 @@ def run(show_plots, liveStream, timeStep, orbitCase, useSphericalHarmonics, plan
planet = gravFactory.createMarsBarycenter()
planet.isCentralBody = True # ensure this is the central gravitational body
if useSphericalHarmonics:
planet.useSphericalHarmParams = True
simIncludeGravBody.loadGravFromFile(bskPath + '/supportData/LocalGravData/GGM2BData.txt',
planet.spherHarm, 100)
planet.useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/GGM2BData.txt', 100)

else: # Earth
planet = gravFactory.createEarth()
planet.isCentralBody = True # ensure this is the central gravitational body
if useSphericalHarmonics:
planet.useSphericalHarmParams = True
simIncludeGravBody.loadGravFromFile(bskPath + '/supportData/LocalGravData/GGM03S-J2-only.txt',
planet.spherHarm, 2)
planet.useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/GGM03S-J2-only.txt', 2)
mu = planet.mu

# attach gravity model to spacecraft
Expand Down
5 changes: 2 additions & 3 deletions examples/scenarioDragRendezvous.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ def drag_simulator(altOffset, trueAnomOffset, densMultiplier, ctrlType='lqr', us
gravFactory = simIncludeGravBody.gravBodyFactory()
gravBodies = gravFactory.createBodies(['earth'])
gravBodies['earth'].isCentralBody = True
simIncludeGravBody.loadGravFromFile(bskPath + '/supportData/LocalGravData/GGM03S.txt', gravBodies['earth'].spherHarm, 2)

gravBodies['earth'].useSphericalHarmParams = useJ2
if useJ2:
gravBodies['earth'].useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/GGM03S.txt', 2)
# timeInitString = '2021 MAY 04 07:47:48.965 (UTC)'
# gravFactory.createSpiceInterface(bskPath + '/supportData/EphemerisData/'
# , timeInitString
Expand Down
4 changes: 1 addition & 3 deletions examples/scenarioFormationMeanOEFeedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ def run(show_plots, useClassicElem, numOrbits):
gravFactory = simIncludeGravBody.gravBodyFactory()
gravBodies = gravFactory.createBodies(['earth'])
gravBodies['earth'].isCentralBody = True
gravBodies['earth'].useSphericalHarmParams = True
simIncludeGravBody.loadGravFromFile(
bskPath + '/supportData/LocalGravData/GGM03S.txt', gravBodies['earth'].spherHarm, 2)
gravBodies['earth'].useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/GGM03S.txt', 2)
scObject.gravField.gravBodies = spacecraft.GravBodyVector(
list(gravFactory.gravBodies.values()))
scObject2.gravField.gravBodies = spacecraft.GravBodyVector(
Expand Down
5 changes: 1 addition & 4 deletions examples/scenarioGroundDownlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ def run(show_plots):
gravFactory = simIncludeGravBody.gravBodyFactory()
planet = gravFactory.createEarth()
planet.isCentralBody = True # ensure this is the central gravitational body

planet.useSphericalHarmParams = True
simIncludeGravBody.loadGravFromFile(bskPath + '/supportData/LocalGravData/GGM03S-J2-only.txt',
planet.spherHarm, 2)
planet.useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/GGM03S-J2-only.txt', 2)
mu = planet.mu
# setup Spice interface for some solar system bodies
timeInitString = '2020 MAY 21 18:28:03 (UTC)'
Expand Down
1 change: 0 additions & 1 deletion examples/scenarioLagrangePointOrbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def run(lagrangePoint, nOrbits, timestep, showPlots=True):
gravFactory = simIncludeGravBody.gravBodyFactory()
gravBodies = gravFactory.createBodies(['moon', 'earth'])
gravBodies['earth'].isCentralBody = True
# Necessary to specify useSphericalHarmParams for Earth or Moon, and then load parameters from file?

# Add gravity bodies to the spacecraft dynamics
scObject.gravField.gravBodies = spacecraft.GravBodyVector(list(gravFactory.gravBodies.values()))
Expand Down
6 changes: 1 addition & 5 deletions examples/scenarioOrbitMultiBody.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ def run(show_plots, scCase):
# Other possible ways to access specific gravity bodies include the below
# earth = gravBodies['earth']
# earth = gravFactory.createEarth()
gravBodies['earth'].useSphericalHarmParams = True
simIncludeGravBody.loadGravFromFile(bskPath +'/supportData/LocalGravData/GGM03S.txt'
, gravBodies['earth'].spherHarm
, 100
)
gravBodies['earth'].useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/GGM03S.txt', 100)
# The configured gravitational bodies are added to the spacecraft dynamics with the usual command:
scObject.gravField.gravBodies = spacecraft.GravBodyVector(list(gravFactory.gravBodies.values()))

Expand Down
4 changes: 1 addition & 3 deletions examples/scenarioSmallBodyNavUKF.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,8 @@ def run(show_plots):
mu = 17.2882449693*1e9 # m^3/s^2
asteroid = gravFactory.createCustomGravObject("vesta", mu, radEquator=265*1000)
asteroid.isCentralBody = True
asteroid.useSphericalHarmParams = True
nSpherHarm = 14
simIncludeGravBody.loadGravFromFile(bskPath + '/supportData/LocalGravData/VESTA20H.txt',
asteroid.spherHarm, nSpherHarm)
asteroid.useSphericalHarmonicsGravityModel(bskPath + '/supportData/LocalGravData/VESTA20H.txt', nSpherHarm)
asteroid.planetBodyInMsg.subscribeTo(gravBodyEphem.planetOutMsgs[0])

# create an ephemeris converter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def massDepletionTest(show_plots, thrusterType):
unitTestSim.earthGravBody.planetName = "earth_planet_data"
unitTestSim.earthGravBody.mu = 0.3986004415E+15 # meters!
unitTestSim.earthGravBody.isCentralBody = True
unitTestSim.earthGravBody.useSphericalHarmParams = False

scObject.gravField.gravBodies = spacecraft.GravBodyVector([unitTestSim.earthGravBody])

Expand Down Expand Up @@ -291,7 +290,6 @@ def axisChangeHelper(r_BcB_B):
unitTestSim.earthGravBody.planetName = "earth_planet_data"
unitTestSim.earthGravBody.mu = 0.3986004415E+15 # meters!
unitTestSim.earthGravBody.isCentralBody = True
unitTestSim.earthGravBody.useSphericalHarmParams = False

scObject.gravField.gravBodies = spacecraft.GravBodyVector([unitTestSim.earthGravBody])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def hingedRigidBodyGravity(show_plots):
unitTestSim.earthGravBody.planetName = "earth_planet_data"
unitTestSim.earthGravBody.mu = 0.3986004415E+15 # meters!
unitTestSim.earthGravBody.isCentralBody = True
unitTestSim.earthGravBody.useSphericalHarmParams = False
scObject.primaryCentralSpacecraft.gravField.gravBodies = spacecraft.GravBodyVector([unitTestSim.earthGravBody])

# Log the spacecraft state message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def fuelSloshTest(show_plots,useFlag,testCase):
unitTestSim.earthGravBody.planetName = "earth_planet_data"
unitTestSim.earthGravBody.mu = 0.3986004415E+15 # meters!
unitTestSim.earthGravBody.isCentralBody = True
unitTestSim.earthGravBody.useSphericalHarmParams = False
scObject.gravField.gravBodies = spacecraft.GravBodyVector([unitTestSim.earthGravBody])
scObject.hub.r_CN_NInit = [[-4020338.690396649], [7490566.741852513], [5248299.211589362]]
scObject.hub.v_CN_NInit = [[-5199.77710904224], [-3436.681645356935], [1041.576797498721]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def nHingedRigidBody(show_plots, testCase):
unitTestSim.earthGravBody.planetName = "earth_planet_data"
unitTestSim.earthGravBody.mu = 0.3986004415E+15 # meters!
unitTestSim.earthGravBody.isCentralBody = True
unitTestSim.earthGravBody.useSphericalHarmParams = False
scObject.gravField.gravBodies = spacecraft.GravBodyVector([unitTestSim.earthGravBody])
scObject.hub.r_CN_NInit = [[-4020338.690396649], [7490566.741852513], [5248299.211589362]]
scObject.hub.v_CN_NInit = [[-5199.77710904224], [-3436.681645356935], [1041.576797498721]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,15 @@ def radiationPressureIntegratedTest(show_plots):

# true position for un perturbed 2 body GEO orbit with cannonball SRP
true_pos = np.array([[-2.18197848e+07, 3.58872415e+07, 0.00000000e+00]
,[-3.97753183e+07, 1.34888783e+07, -7.34006882e+01]
,[-3.91389821e+07, -1.52401394e+07, -3.06392342e+02]
,[-2.01837904e+07, -3.68366949e+07, -6.37825333e+02]
,[ 8.21685433e+06, -4.11950336e+07, -9.13451012e+02]
,[ 3.27532829e+07, -2.63023741e+07, -9.57894936e+02]
,[ 4.19944582e+07, 9.02560169e+05, -6.78189034e+02]
,[ 3.15827901e+07, 2.76842665e+07, -1.40584587e+02]
,[ 6.38612441e+06, 4.15047641e+07, 4.29547195e+02]
,[-2.18007315e+07, 3.58874482e+07, 7.40749634e+02]])

,[-3.97753187e+07, 1.34888792e+07, -7.33231880e+01]
,[-3.91389859e+07, -1.52401375e+07, -3.06322198e+02]
,[-2.01838008e+07, -3.68366952e+07, -6.37764168e+02]
,[ 8.21683806e+06, -4.11950440e+07, -9.13393204e+02]
,[ 3.27532709e+07, -2.63024006e+07, -9.57828703e+02]
,[ 4.19944648e+07, 9.02522873e+05, -6.78102461e+02]
,[ 3.15828214e+07, 2.76842358e+07, -1.40473487e+02]
,[ 6.38617052e+06, 4.15047581e+07, 4.29674085e+02]
,[-2.18006914e+07, 3.58874726e+07, 7.40872311e+02]])
# compare the results to the truth values
accuracy = 1.0 # meters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def thrusterIntegratedTest(show_plots):
unitTestSim.earthGravBody.planetName = "earth_planet_data"
unitTestSim.earthGravBody.mu = 0.3986004415E+15 # meters!
unitTestSim.earthGravBody.isCentralBody = True
unitTestSim.earthGravBody.useSphericalHarmParams = False

scObject.gravField.gravBodies = spacecraft.GravBodyVector([unitTestSim.earthGravBody])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def VSCMGIntegratedTest(show_plots,useFlag,testCase):
unitTestSim.earthGravBody.planetName = "earth_planet_data"
unitTestSim.earthGravBody.mu = 0.3986004415E+15 # meters!
unitTestSim.earthGravBody.isCentralBody = True
unitTestSim.earthGravBody.useSphericalHarmParams = False

scObject.gravField.gravBodies = spacecraft.GravBodyVector([unitTestSim.earthGravBody])

Expand Down
Loading
Loading