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

Add clang format hook to pre-commit #367

Merged
merged 10 commits into from
Dec 13, 2024
5 changes: 4 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
BasedOnStyle: Mozilla
BasedOnStyle: Google
ColumnLimit: '120'
IndentWidth: '4'
TabWidth: '4'
BinPackArguments: false
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: false
...
13 changes: 9 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
exclude: '.*\.(tls|bsp|tpc|bc)$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
args: ['--maxkb=10000']
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: [-i, -style=file]
131 changes: 53 additions & 78 deletions src/simulation/dynamics/facetDragEffector/facetDragDynamicEffector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,35 @@
*/

#include "facetDragDynamicEffector.h"
#include "architecture/utilities/linearAlgebra.h"

#include "architecture/utilities/astroConstants.h"
#include "architecture/utilities/avsEigenSupport.h"
#include "architecture/utilities/avsEigenMRP.h"
#include "architecture/utilities/avsEigenSupport.h"
#include "architecture/utilities/linearAlgebra.h"

FacetDragDynamicEffector::FacetDragDynamicEffector()
{
FacetDragDynamicEffector::FacetDragDynamicEffector() {
this->forceExternal_B.fill(0.0);
this->torqueExternalPntB_B.fill(0.0);
this->v_B.fill(0.0);
this->v_hat_B.fill(0.0);
this->numFacets = 0;
return;
}

/*! The destructor.*/
FacetDragDynamicEffector::~FacetDragDynamicEffector()
{
return;
}



void FacetDragDynamicEffector::reset(uint64_t currentSimNanos)
{
// check if input message has not been included
if (!this->atmoDensInMsg.isLinked()) {
bskLogger.bskLog(BSK_ERROR, "facetDragDynamicEffector.atmoDensInMsg was not linked.");
}

return;
void FacetDragDynamicEffector::reset(uint64_t currentSimNanos) {
// check if input message has not been included
if (!this->atmoDensInMsg.isLinked()) {
bskLogger.bskLog(BSK_ERROR, "facetDragDynamicEffector.atmoDensInMsg was not linked.");
}
}

/*! The DragEffector does not write output messages to the rest of the sim.
@return void
*/
void FacetDragDynamicEffector::WriteOutputMessages(uint64_t CurrentClock)
{
return;
}


/*! This method is used to read the incoming density message and update the internal density/
atmospheric data.
@return void
*/
bool FacetDragDynamicEffector::ReadInputs()
{
bool FacetDragDynamicEffector::readInputs() {
bool dataGood;
this->atmoInData = this->atmoDensInMsg();
dataGood = this->atmoDensInMsg.isWritten();
return(dataGood);
return dataGood;
}

/*!
Expand All @@ -79,12 +56,15 @@ bool FacetDragDynamicEffector::ReadInputs()
@param B_normal_hat
@param B_location
*/
void FacetDragDynamicEffector::addFacet(double area, double dragCoeff, Eigen::Vector3d B_normal_hat, Eigen::Vector3d B_location){
this->scGeometry.facetAreas.push_back(area);
this->scGeometry.facetCoeffs.push_back(dragCoeff);
this->scGeometry.facetNormals_B.push_back(B_normal_hat);
this->scGeometry.facetLocations_B.push_back(B_location);
this->numFacets = this->numFacets + 1;
void FacetDragDynamicEffector::addFacet(double area,
double dragCoeff,
Eigen::Vector3d B_normal_hat,
Eigen::Vector3d B_location) {
this->scGeometry.facetAreas.push_back(area);
this->scGeometry.facetCoeffs.push_back(dragCoeff);
this->scGeometry.facetNormals_B.push_back(B_normal_hat);
this->scGeometry.facetLocations_B.push_back(B_location);
this->numFacets = this->numFacets + 1;
}

/*! This method is used to link the dragEffector to the hub attitude and velocity,
Expand All @@ -93,72 +73,67 @@ which are required for calculating drag forces and torques.
@param states dynamic parameter states
*/

void FacetDragDynamicEffector::linkInStates(DynParamManager& states){
this->hubSigma = states.getStateObject("hubSigma");
this->hubVelocity = states.getStateObject("hubVelocity");
void FacetDragDynamicEffector::linkInStates(DynParamManager& states) {
this->hubSigma = states.getStateObject("hubSigma");
this->hubVelocity = states.getStateObject("hubVelocity");
}

/*! This method updates the internal drag direction based on the spacecraft velocity vector.
*/
void FacetDragDynamicEffector::updateDragDir(){
*/
void FacetDragDynamicEffector::updateDragDir() {
Eigen::MRPd sigmaBN;
sigmaBN = (Eigen::Vector3d)this->hubSigma->getState();
Eigen::Matrix3d dcm_BN = sigmaBN.toRotationMatrix().transpose();

this->v_B = dcm_BN*this->hubVelocity->getState(); // [m/s] sc velocity
this->v_B = dcm_BN * this->hubVelocity->getState(); // [m/s] sc velocity
this->v_hat_B = this->v_B / this->v_B.norm();

return;
}

/*! This method WILL implement a more complex flat-plate aerodynamics model with attitude
dependence and lift forces.
*/
void FacetDragDynamicEffector::plateDrag(){
Eigen::Vector3d facetDragForce, facetDragTorque;
Eigen::Vector3d totalDragForce, totalDragTorque;
void FacetDragDynamicEffector::plateDrag() {
Eigen::Vector3d facetDragForce;
Eigen::Vector3d facetDragTorque;
Eigen::Vector3d totalDragForce;
Eigen::Vector3d totalDragTorque;

//! - Zero out the structure force/torque for the drag set
//! - Zero out the structure force/torque for the drag set
double projectedArea = 0.0;
double projectionTerm = 0.0;
totalDragForce.setZero();
totalDragTorque.setZero();
totalDragForce.setZero();
totalDragTorque.setZero();
this->forceExternal_B.setZero();
this->torqueExternalPntB_B.setZero();

for(size_t i = 0; i < this->numFacets; i++){
projectionTerm = this->scGeometry.facetNormals_B[i].dot(this->v_hat_B);
projectedArea = this->scGeometry.facetAreas[i] * projectionTerm;
if(projectedArea > 0.0){
facetDragForce = 0.5 * pow(this->v_B.norm(), 2.0) * this->scGeometry.facetCoeffs[i] * projectedArea * this->atmoInData.neutralDensity * (-1.0)*this->v_hat_B;
facetDragTorque = (-1)*facetDragForce.cross(this->scGeometry.facetLocations_B[i]);
totalDragForce = totalDragForce + facetDragForce;
totalDragTorque = totalDragTorque + facetDragTorque;
}
}
this->forceExternal_B = totalDragForce;
this->torqueExternalPntB_B = totalDragTorque;

return;
}
for (size_t i = 0; i < this->numFacets; i++) {
projectionTerm = this->scGeometry.facetNormals_B[i].dot(this->v_hat_B);
projectedArea = this->scGeometry.facetAreas[i] * projectionTerm;
if (projectedArea > 0.0) {
facetDragForce = 0.5 * pow(this->v_B.norm(), 2.0) * this->scGeometry.facetCoeffs[i] * projectedArea *
this->atmoInData.neutralDensity * (-1.0) * this->v_hat_B;
facetDragTorque = (-1) * facetDragForce.cross(this->scGeometry.facetLocations_B[i]);
totalDragForce = totalDragForce + facetDragForce;
totalDragTorque = totalDragTorque + facetDragTorque;
}
}
this->forceExternal_B = totalDragForce;
this->torqueExternalPntB_B = totalDragTorque;

return;
}

/*! This method computes the body forces and torques for the dragEffector in a simulation loop,
selecting the model type based on the settable attribute "modelType."
*/
void FacetDragDynamicEffector::computeForceTorque(double integTime, double timeStep){
updateDragDir();
plateDrag();
return;
void FacetDragDynamicEffector::computeForceTorque(double integTime, double timeStep) {
this->updateDragDir();
this->plateDrag();
}

/*! This method is called to update the local atmospheric conditions at each timestep.
Naturally, this means that conditions are held piecewise-constant over an integration step.
@return void
@param currentSimNanos The current simulation time in nanoseconds
*/
void FacetDragDynamicEffector::updateState(uint64_t currentSimNanos)
{
ReadInputs();
return;
}
void FacetDragDynamicEffector::updateState(uint64_t currentSimNanos) { this->readInputs(); }
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,52 @@

*/


#ifndef FACET_DRAG_DYNAMIC_EFFECTOR_H
#define FACET_DRAG_DYNAMIC_EFFECTOR_H

#include <Eigen/Dense>
#include <vector>
#include "simulation/dynamics/_GeneralModuleFiles/dynamicEffector.h"
#include "simulation/dynamics/_GeneralModuleFiles/stateData.h"
#include "architecture/_GeneralModuleFiles/sys_model.h"

#include "architecture/msgPayloadDefC/AtmoPropsMsgPayload.h"
#include "architecture/_GeneralModuleFiles/sys_model.h"
#include "architecture/messaging/messaging.h"

#include "architecture/utilities/rigidBodyKinematics.h"
#include "architecture/msgPayloadDefC/AtmoPropsMsgPayload.h"
#include "architecture/utilities/bskLogging.h"




#include "architecture/utilities/rigidBodyKinematics.h"
#include "simulation/dynamics/_GeneralModuleFiles/dynamicEffector.h"
#include "simulation/dynamics/_GeneralModuleFiles/stateData.h"

/*! @brief spacecraft geometry data */
typedef struct {
std::vector<double> facetAreas; //!< vector of facet areas
std::vector<double> facetCoeffs; //!< vector of facet coefficients
std::vector<Eigen::Vector3d> facetNormals_B; //!< vector of facet normals
std::vector<Eigen::Vector3d> facetLocations_B; //!< vector of facet locations
}SpacecraftGeometryData;

std::vector<double> facetAreas; //!< vector of facet areas
std::vector<double> facetCoeffs; //!< vector of facet coefficients
std::vector<Eigen::Vector3d> facetNormals_B; //!< vector of facet normals
std::vector<Eigen::Vector3d> facetLocations_B; //!< vector of facet locations
} SpacecraftGeometryData;

/*! @brief faceted atmospheric drag dynamic effector */
class FacetDragDynamicEffector: public SysModel, public DynamicEffector {
public:


class FacetDragDynamicEffector : public SysModel, public DynamicEffector {
public:
FacetDragDynamicEffector();
~FacetDragDynamicEffector();
void linkInStates(DynParamManager& states);
void computeForceTorque(double integTime, double timeStep);
void reset(uint64_t currentSimNanos); //!< class method
void updateState(uint64_t currentSimNanos);
void WriteOutputMessages(uint64_t CurrentClock);
bool ReadInputs();
void linkInStates(DynParamManager& states) override;
void computeForceTorque(double integTime, double timeStep) override;
void reset(uint64_t currentSimNanos) override;
void updateState(uint64_t currentSimNanos) override;
void addFacet(double area, double dragCoeff, Eigen::Vector3d B_normal_hat, Eigen::Vector3d B_location);

private:
uint64_t numFacets = 0; //!< number of facets
ReadFunctor<AtmoPropsMsgPayload> atmoDensInMsg; //!< atmospheric density input message
StateData* hubSigma; //!< -- Hub/Inertial attitude represented by MRP
StateData* hubVelocity; //!< m/s Hub inertial velocity vector
Eigen::Vector3d v_B; //!< m/s local variable to hold the inertial velocity
Eigen::Vector3d v_hat_B; //!< class variable

private:
bool readInputs();
void plateDrag();
void updateDragDir();
public:
uint64_t numFacets; //!< number of facets
ReadFunctor<AtmoPropsMsgPayload> atmoDensInMsg; //!< atmospheric density input message
StateData *hubSigma; //!< -- Hub/Inertial attitude represented by MRP
StateData *hubVelocity; //!< m/s Hub inertial velocity vector
Eigen::Vector3d v_B; //!< m/s local variable to hold the inertial velocity
Eigen::Vector3d v_hat_B; //!< class variable
BSKLogger bskLogger; //!< -- BSK Logging

private:
AtmoPropsMsgPayload atmoInData;
SpacecraftGeometryData scGeometry; //!< -- Struct to hold spacecraft facet data

SpacecraftGeometryData scGeometry; //!< -- Struct to hold spacecraft facet data
};

#endif
Loading