Skip to content

Commit

Permalink
Merge pull request #576 from AVSLab/refactor-prescribed-messages
Browse files Browse the repository at this point in the history
Refactor prescribed messages
  • Loading branch information
leahkiner authored Feb 14, 2024
2 parents dc74723 + 4b186f1 commit 0026775
Show file tree
Hide file tree
Showing 23 changed files with 384 additions and 342 deletions.
2 changes: 2 additions & 0 deletions docs/source/Support/bskReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Version |release|
- Refactored the :ref:`PrescribedTransMsgPayload` message by renaming the message to
:ref:`LinearTranslationRigidBodyMsgPayload` and renaming the message variables from ``scalarPos`` and ``scalarVel`` to
``rho`` and ``rhoDot``
- Deprecated the :ref:`prescribedMotionMsgPayload` message and replaced with two separate
:ref:`prescribedTranslationMsgPayload` and :ref:`prescribedRotationMsgPayload` messages.

Version 2.2.1 (Dec. 22, 2023)
-----------------------------
Expand Down
32 changes: 32 additions & 0 deletions src/architecture/msgPayloadDefC/PrescribedRotationMsgPayload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
ISC License
Copyright (c) 2024, Autonomous Vehicle Systems Lab, University of Colorado at Boulder
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef prescribedRotationSimMsg_h
#define prescribedRotationSimMsg_h


/*! @brief Structure used to define the prescribed motion state effector rotational state data message */
typedef struct {
double omega_FM_F[3]; //!< [rad/s] Angular velocity of the F frame wrt the M frame in F frame components
double omegaPrime_FM_F[3]; //!< [rad/s^2] B/M frame time derivative of omega_FM_F
double sigma_FM[3]; //!< MRP attitude parameters for the F frame relative to the M frame
}PrescribedRotationMsgPayload;


#endif /* prescribedRotationSimMsg_h */
32 changes: 32 additions & 0 deletions src/architecture/msgPayloadDefC/PrescribedTranslationMsgPayload.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
ISC License
Copyright (c) 2024, Autonomous Vehicle Systems Lab, University of Colorado at Boulder
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef prescribedTranslationSimMsg_h
#define prescribedTranslationSimMsg_h


/*! @brief Structure used to define the prescribed motion state effector translational state data message */
typedef struct {
double r_FM_M[3]; //!< [m] Position vector from the M frame origin to the F frame origin expressed in M frame components
double rPrime_FM_M[3]; //!< [m/s] B/M frame time derivative of r_FM_M
double rPrimePrime_FM_M[3]; //!< [m/s^2] B/M frame time derivative of rPrime_FM_M
}PrescribedTranslationMsgPayload;


#endif /* prescribedTranslationSimMsg_h */
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_prescribedRot1DOFTestFunction(show_plots, thetaInit, thetaRef, thetaDDo
r"""
**Validation Test Description**
This unit test ensures that the profiled 1 DOF attitude maneuver for a secondary rigid body connected
This unit test ensures that the profiled 1 DOF rotation for a secondary rigid body connected
to the spacecraft hub is properly computed for a series of initial and reference PRV angles and maximum
angular accelerations. The final prescribed attitude and angular velocity magnitude are compared with
the reference values.
Expand All @@ -67,8 +67,8 @@ def test_prescribedRot1DOFTestFunction(show_plots, thetaInit, thetaRef, thetaDDo
**Description of Variables Being Tested**
This unit test ensures that the profiled 1 DOF rotational attitude maneuver is properly computed for a series of
initial and reference PRV angles and maximum angular accelerations. The final prescribed angle ``theta_FM_Final``
This unit test ensures that the profiled 1 DOF rotation is properly computed for a series of initial and
reference PRV angles and maximum angular accelerations. The final prescribed angle ``theta_FM_Final``
and angular velocity magnitude ``thetaDot_Final`` are compared with the reference values ``theta_Ref`` and
``thetaDot_Ref``, respectively.
"""
Expand All @@ -79,8 +79,8 @@ def test_prescribedRot1DOFTestFunction(show_plots, thetaInit, thetaRef, thetaDDo

def prescribedRot1DOFTestFunction(show_plots, thetaInit, thetaRef, thetaDDotMax, accuracy):
"""Call this routine directly to run the unit test."""
testFailCount = 0 # Zero the unit test result counter
testMessages = [] # Create an empty array to store the test log messages
testFailCount = 0
testMessages = []
unitTaskName = "unitTask"
unitProcessName = "TestProcess"
bskLogging.setDefaultLogLevel(bskLogging.BSK_WARNING)
Expand All @@ -89,7 +89,7 @@ def prescribedRot1DOFTestFunction(show_plots, thetaInit, thetaRef, thetaDDotMax,
unitTestSim = SimulationBaseClass.SimBaseClass()

# Create the test thread
testProcessRate = macros.sec2nano(0.1) # update process rate update time
testProcessRate = macros.sec2nano(0.1)
testProc = unitTestSim.CreateNewProcess(unitProcessName)
testProc.addTask(unitTestSim.CreateNewTask(unitTaskName, testProcessRate))

Expand All @@ -103,9 +103,6 @@ def prescribedRot1DOFTestFunction(show_plots, thetaInit, thetaRef, thetaDDotMax,
# Initialize the prescribedRot1DOF test module configuration data
rotAxisM = np.array([1.0, 0.0, 0.0])
prvInit_FM = thetaInit * rotAxisM
PrescribedRot1DOF.r_FM_M = np.array([1.0, 0.0, 0.0])
PrescribedRot1DOF.rPrime_FM_M = np.array([0.0, 0.0, 0.0])
PrescribedRot1DOF.rPrimePrime_FM_M = np.array([0.0, 0.0, 0.0])
PrescribedRot1DOF.rotAxis_M = rotAxisM
PrescribedRot1DOF.thetaDDotMax = thetaDDotMax
PrescribedRot1DOF.omega_FM_F = np.array([0.0, 0.0, 0.0])
Expand All @@ -121,7 +118,7 @@ def prescribedRot1DOFTestFunction(show_plots, thetaInit, thetaRef, thetaDDotMax,
PrescribedRot1DOF.spinningBodyInMsg.subscribeTo(HingedRigidBodyMessage)

# Log the test module output message for data comparison
dataLog = PrescribedRot1DOF.prescribedMotionOutMsg.recorder()
dataLog = PrescribedRot1DOF.prescribedRotationOutMsg.recorder()
unitTestSim.AddModelToTask(unitTaskName, dataLog)

# Initialize the simulation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
void SelfInit_prescribedRot1DOF(PrescribedRot1DOFConfig *configData, int64_t moduleID)
{
// Initialize the output messages
PrescribedMotionMsg_C_init(&configData->prescribedMotionOutMsg);
PrescribedRotationMsg_C_init(&configData->prescribedRotationOutMsg);
HingedRigidBodyMsg_C_init(&configData->spinningBodyOutMsg);
}

Expand Down Expand Up @@ -74,11 +74,11 @@ void Update_prescribedRot1DOF(PrescribedRot1DOFConfig *configData, uint64_t call
// Create the buffer messages
HingedRigidBodyMsgPayload spinningBodyIn;
HingedRigidBodyMsgPayload spinningBodyOut;
PrescribedMotionMsgPayload prescribedMotionOut;
PrescribedRotationMsgPayload prescribedRotationOut;

// Zero the output messages
spinningBodyOut = HingedRigidBodyMsg_C_zeroMsgPayload();
prescribedMotionOut = PrescribedMotionMsg_C_zeroMsgPayload();
prescribedRotationOut = PrescribedRotationMsg_C_zeroMsgPayload();

// Read the input message
spinningBodyIn = HingedRigidBodyMsg_C_zeroMsgPayload();
Expand Down Expand Up @@ -146,11 +146,6 @@ void Update_prescribedRot1DOF(PrescribedRot1DOFConfig *configData, uint64_t call
configData->convergence = true;
}

// Determine the prescribed parameters: omega_FM_F and omegaPrime_FM_F
v3Normalize(configData->rotAxis_M, configData->rotAxis_M);
v3Scale(thetaDot, configData->rotAxis_M, configData->omega_FM_F);
v3Scale(thetaDDot, configData->rotAxis_M, configData->omegaPrime_FM_F);

// Determine dcm_FF0
double dcm_FF0[3][3];
double prv_FF0_array[3];
Expand All @@ -171,19 +166,16 @@ void Update_prescribedRot1DOF(PrescribedRot1DOFConfig *configData, uint64_t call
// Determine the prescribed parameter: sigma_FM
C2MRP(dcm_FM, configData->sigma_FM);

// Copy the module variables to the prescribedMotionOut output message
v3Copy(configData->r_FM_M, prescribedMotionOut.r_FM_M);
v3Copy(configData->rPrime_FM_M, prescribedMotionOut.rPrime_FM_M);
v3Copy(configData->rPrimePrime_FM_M, prescribedMotionOut.rPrimePrime_FM_M);
v3Copy(configData->omega_FM_F, prescribedMotionOut.omega_FM_F);
v3Copy(configData->omegaPrime_FM_F, prescribedMotionOut.omegaPrime_FM_F);
v3Copy(configData->sigma_FM, prescribedMotionOut.sigma_FM);
// Copy the module variables to the prescribedRotationOut output message
v3Copy(configData->omega_FM_F, prescribedRotationOut.omega_FM_F);
v3Copy(configData->omegaPrime_FM_F, prescribedRotationOut.omegaPrime_FM_F);
v3Copy(configData->sigma_FM, prescribedRotationOut.sigma_FM);

// Copy the local scalar variables to the spinningBodyOut output message
spinningBodyOut.theta = theta;
spinningBodyOut.thetaDot = thetaDot;

// Write the output messages
HingedRigidBodyMsg_C_write(&spinningBodyOut, &configData->spinningBodyOutMsg, moduleID, callTime);
PrescribedMotionMsg_C_write(&prescribedMotionOut, &configData->prescribedMotionOutMsg, moduleID, callTime);
PrescribedRotationMsg_C_write(&prescribedRotationOut, &configData->prescribedRotationOutMsg, moduleID, callTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@
#include <stdbool.h>
#include "architecture/utilities/bskLogging.h"
#include "cMsgCInterface/HingedRigidBodyMsg_C.h"
#include "cMsgCInterface/PrescribedMotionMsg_C.h"
#include "cMsgCInterface/PrescribedRotationMsg_C.h"

/*! @brief Top level structure for the sub-module routines. */
typedef struct {

/* User configurable variables */
double thetaDDotMax; //!< [rad/s^2] Maximum angular acceleration of spinning body
double rotAxis_M[3]; //!< Rotation axis for the maneuver in M frame components
double r_FM_M[3]; //!< [m] Position of the F frame origin with respect to the M frame origin in M frame components (fixed)
double rPrime_FM_M[3]; //!< [m/s] B frame time derivative of r_FM_M in M frame components (fixed)
double rPrimePrime_FM_M[3]; //!< [m/s^2] B frame time derivative of rPrime_FM_M in M frame components (fixed)
double omega_FM_F[3]; //!< [rad/s] Angular velocity of frame F wrt frame M in F frame components
double omegaPrime_FM_F[3]; //!< [rad/s^2] B frame time derivative of omega_FM_F in F frame components
double sigma_FM[3]; //!< MRP attitude of frame F with respect to frame M
Expand All @@ -53,9 +50,9 @@ typedef struct {
BSKLogger *bskLogger; //!< BSK Logging

/* Messages */
HingedRigidBodyMsg_C spinningBodyInMsg; //!< Input msg for the spinning body reference angle and angle rate
HingedRigidBodyMsg_C spinningBodyOutMsg; //!< Output msg for the spinning body angle and angle rate
PrescribedMotionMsg_C prescribedMotionOutMsg; //!< Output msg for the spinning body prescribed states
HingedRigidBodyMsg_C spinningBodyInMsg; //!< Input msg for the spinning body reference angle and angle rate
HingedRigidBodyMsg_C spinningBodyOutMsg; //!< Output msg for the spinning body angle and angle rate
PrescribedRotationMsg_C prescribedRotationOutMsg; //!< Output msg for the spinning body prescribed rotational states

}PrescribedRot1DOFConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

%include "architecture/msgPayloadDefC/HingedRigidBodyMsgPayload.h"
struct HingedRigidBodyMsg_C;
%include "architecture/msgPayloadDefC/PrescribedMotionMsgPayload.h"
struct PrescribedMotionMsg_C;
%include "architecture/msgPayloadDefC/PrescribedRotationMsgPayload.h"
struct PrescribedRotationMsg_C;

%pythoncode %{
import sys
Expand Down
Loading

0 comments on commit 0026775

Please sign in to comment.