Skip to content

Commit 66a5059

Browse files
authored
Merge pull request #367 from lasp/ci/add-clang-format-clang-tidy-precommit
Add clang format hook to pre-commit
2 parents eb4b824 + c29db2f commit 66a5059

File tree

4 files changed

+91
-123
lines changed

4 files changed

+91
-123
lines changed

.clang-format

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
2-
BasedOnStyle: Mozilla
2+
BasedOnStyle: Google
33
ColumnLimit: '120'
44
IndentWidth: '4'
55
TabWidth: '4'
6+
BinPackArguments: false
7+
BinPackParameters: false
8+
AllowAllParametersOfDeclarationOnNextLine: false
69
...

.pre-commit-config.yaml

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
exclude: '.*\.(tls|bsp|tpc|bc)$'
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v2.3.0
4+
rev: v5.0.0
55
hooks:
6-
- id: trailing-whitespace
7-
- id: end-of-file-fixer
8-
- id: check-yaml
96
- id: check-added-large-files
107
args: ['--maxkb=10000']
118
- id: check-case-conflict
129
- id: check-merge-conflict
10+
- id: check-yaml
1311
- id: debug-statements
12+
- id: end-of-file-fixer
13+
- id: trailing-whitespace
14+
- repo: https://github.com/pocc/pre-commit-hooks
15+
rev: v1.3.5
16+
hooks:
17+
- id: clang-format
18+
args: [-i, -style=file]

src/simulation/dynamics/facetDragEffector/facetDragDynamicEffector.cpp

+53-78
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,35 @@
1818
*/
1919

2020
#include "facetDragDynamicEffector.h"
21-
#include "architecture/utilities/linearAlgebra.h"
21+
2222
#include "architecture/utilities/astroConstants.h"
23-
#include "architecture/utilities/avsEigenSupport.h"
2423
#include "architecture/utilities/avsEigenMRP.h"
24+
#include "architecture/utilities/avsEigenSupport.h"
25+
#include "architecture/utilities/linearAlgebra.h"
2526

26-
FacetDragDynamicEffector::FacetDragDynamicEffector()
27-
{
27+
FacetDragDynamicEffector::FacetDragDynamicEffector() {
2828
this->forceExternal_B.fill(0.0);
2929
this->torqueExternalPntB_B.fill(0.0);
3030
this->v_B.fill(0.0);
3131
this->v_hat_B.fill(0.0);
32-
this->numFacets = 0;
33-
return;
34-
}
35-
36-
/*! The destructor.*/
37-
FacetDragDynamicEffector::~FacetDragDynamicEffector()
38-
{
39-
return;
4032
}
4133

42-
43-
44-
void FacetDragDynamicEffector::reset(uint64_t currentSimNanos)
45-
{
46-
// check if input message has not been included
47-
if (!this->atmoDensInMsg.isLinked()) {
48-
bskLogger.bskLog(BSK_ERROR, "facetDragDynamicEffector.atmoDensInMsg was not linked.");
49-
}
50-
51-
return;
34+
void FacetDragDynamicEffector::reset(uint64_t currentSimNanos) {
35+
// check if input message has not been included
36+
if (!this->atmoDensInMsg.isLinked()) {
37+
bskLogger.bskLog(BSK_ERROR, "facetDragDynamicEffector.atmoDensInMsg was not linked.");
38+
}
5239
}
5340

54-
/*! The DragEffector does not write output messages to the rest of the sim.
55-
@return void
56-
*/
57-
void FacetDragDynamicEffector::WriteOutputMessages(uint64_t CurrentClock)
58-
{
59-
return;
60-
}
61-
62-
6341
/*! This method is used to read the incoming density message and update the internal density/
6442
atmospheric data.
6543
@return void
6644
*/
67-
bool FacetDragDynamicEffector::ReadInputs()
68-
{
45+
bool FacetDragDynamicEffector::readInputs() {
6946
bool dataGood;
7047
this->atmoInData = this->atmoDensInMsg();
7148
dataGood = this->atmoDensInMsg.isWritten();
72-
return(dataGood);
49+
return dataGood;
7350
}
7451

7552
/*!
@@ -79,12 +56,15 @@ bool FacetDragDynamicEffector::ReadInputs()
7956
@param B_normal_hat
8057
@param B_location
8158
*/
82-
void FacetDragDynamicEffector::addFacet(double area, double dragCoeff, Eigen::Vector3d B_normal_hat, Eigen::Vector3d B_location){
83-
this->scGeometry.facetAreas.push_back(area);
84-
this->scGeometry.facetCoeffs.push_back(dragCoeff);
85-
this->scGeometry.facetNormals_B.push_back(B_normal_hat);
86-
this->scGeometry.facetLocations_B.push_back(B_location);
87-
this->numFacets = this->numFacets + 1;
59+
void FacetDragDynamicEffector::addFacet(double area,
60+
double dragCoeff,
61+
Eigen::Vector3d B_normal_hat,
62+
Eigen::Vector3d B_location) {
63+
this->scGeometry.facetAreas.push_back(area);
64+
this->scGeometry.facetCoeffs.push_back(dragCoeff);
65+
this->scGeometry.facetNormals_B.push_back(B_normal_hat);
66+
this->scGeometry.facetLocations_B.push_back(B_location);
67+
this->numFacets = this->numFacets + 1;
8868
}
8969

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

96-
void FacetDragDynamicEffector::linkInStates(DynParamManager& states){
97-
this->hubSigma = states.getStateObject("hubSigma");
98-
this->hubVelocity = states.getStateObject("hubVelocity");
76+
void FacetDragDynamicEffector::linkInStates(DynParamManager& states) {
77+
this->hubSigma = states.getStateObject("hubSigma");
78+
this->hubVelocity = states.getStateObject("hubVelocity");
9979
}
10080

10181
/*! This method updates the internal drag direction based on the spacecraft velocity vector.
102-
*/
103-
void FacetDragDynamicEffector::updateDragDir(){
82+
*/
83+
void FacetDragDynamicEffector::updateDragDir() {
10484
Eigen::MRPd sigmaBN;
10585
sigmaBN = (Eigen::Vector3d)this->hubSigma->getState();
10686
Eigen::Matrix3d dcm_BN = sigmaBN.toRotationMatrix().transpose();
10787

108-
this->v_B = dcm_BN*this->hubVelocity->getState(); // [m/s] sc velocity
88+
this->v_B = dcm_BN * this->hubVelocity->getState(); // [m/s] sc velocity
10989
this->v_hat_B = this->v_B / this->v_B.norm();
110-
111-
return;
11290
}
11391

11492
/*! This method WILL implement a more complex flat-plate aerodynamics model with attitude
11593
dependence and lift forces.
11694
*/
117-
void FacetDragDynamicEffector::plateDrag(){
118-
Eigen::Vector3d facetDragForce, facetDragTorque;
119-
Eigen::Vector3d totalDragForce, totalDragTorque;
95+
void FacetDragDynamicEffector::plateDrag() {
96+
Eigen::Vector3d facetDragForce;
97+
Eigen::Vector3d facetDragTorque;
98+
Eigen::Vector3d totalDragForce;
99+
Eigen::Vector3d totalDragTorque;
120100

121-
//! - Zero out the structure force/torque for the drag set
101+
//! - Zero out the structure force/torque for the drag set
122102
double projectedArea = 0.0;
123103
double projectionTerm = 0.0;
124-
totalDragForce.setZero();
125-
totalDragTorque.setZero();
104+
totalDragForce.setZero();
105+
totalDragTorque.setZero();
126106
this->forceExternal_B.setZero();
127107
this->torqueExternalPntB_B.setZero();
128108

129-
for(size_t i = 0; i < this->numFacets; i++){
130-
projectionTerm = this->scGeometry.facetNormals_B[i].dot(this->v_hat_B);
131-
projectedArea = this->scGeometry.facetAreas[i] * projectionTerm;
132-
if(projectedArea > 0.0){
133-
facetDragForce = 0.5 * pow(this->v_B.norm(), 2.0) * this->scGeometry.facetCoeffs[i] * projectedArea * this->atmoInData.neutralDensity * (-1.0)*this->v_hat_B;
134-
facetDragTorque = (-1)*facetDragForce.cross(this->scGeometry.facetLocations_B[i]);
135-
totalDragForce = totalDragForce + facetDragForce;
136-
totalDragTorque = totalDragTorque + facetDragTorque;
137-
}
138-
}
139-
this->forceExternal_B = totalDragForce;
140-
this->torqueExternalPntB_B = totalDragTorque;
141-
142-
return;
143-
}
109+
for (size_t i = 0; i < this->numFacets; i++) {
110+
projectionTerm = this->scGeometry.facetNormals_B[i].dot(this->v_hat_B);
111+
projectedArea = this->scGeometry.facetAreas[i] * projectionTerm;
112+
if (projectedArea > 0.0) {
113+
facetDragForce = 0.5 * pow(this->v_B.norm(), 2.0) * this->scGeometry.facetCoeffs[i] * projectedArea *
114+
this->atmoInData.neutralDensity * (-1.0) * this->v_hat_B;
115+
facetDragTorque = (-1) * facetDragForce.cross(this->scGeometry.facetLocations_B[i]);
116+
totalDragForce = totalDragForce + facetDragForce;
117+
totalDragTorque = totalDragTorque + facetDragTorque;
118+
}
119+
}
120+
this->forceExternal_B = totalDragForce;
121+
this->torqueExternalPntB_B = totalDragTorque;
144122

123+
return;
124+
}
145125

146126
/*! This method computes the body forces and torques for the dragEffector in a simulation loop,
147127
selecting the model type based on the settable attribute "modelType."
148128
*/
149-
void FacetDragDynamicEffector::computeForceTorque(double integTime, double timeStep){
150-
updateDragDir();
151-
plateDrag();
152-
return;
129+
void FacetDragDynamicEffector::computeForceTorque(double integTime, double timeStep) {
130+
this->updateDragDir();
131+
this->plateDrag();
153132
}
154133

155134
/*! This method is called to update the local atmospheric conditions at each timestep.
156135
Naturally, this means that conditions are held piecewise-constant over an integration step.
157136
@return void
158137
@param currentSimNanos The current simulation time in nanoseconds
159138
*/
160-
void FacetDragDynamicEffector::updateState(uint64_t currentSimNanos)
161-
{
162-
ReadInputs();
163-
return;
164-
}
139+
void FacetDragDynamicEffector::updateState(uint64_t currentSimNanos) { this->readInputs(); }

src/simulation/dynamics/facetDragEffector/facetDragDynamicEffector.h

+25-40
Original file line numberDiff line numberDiff line change
@@ -17,67 +17,52 @@
1717
1818
*/
1919

20-
2120
#ifndef FACET_DRAG_DYNAMIC_EFFECTOR_H
2221
#define FACET_DRAG_DYNAMIC_EFFECTOR_H
2322

2423
#include <Eigen/Dense>
2524
#include <vector>
26-
#include "simulation/dynamics/_GeneralModuleFiles/dynamicEffector.h"
27-
#include "simulation/dynamics/_GeneralModuleFiles/stateData.h"
28-
#include "architecture/_GeneralModuleFiles/sys_model.h"
2925

30-
#include "architecture/msgPayloadDefC/AtmoPropsMsgPayload.h"
26+
#include "architecture/_GeneralModuleFiles/sys_model.h"
3127
#include "architecture/messaging/messaging.h"
32-
33-
#include "architecture/utilities/rigidBodyKinematics.h"
28+
#include "architecture/msgPayloadDefC/AtmoPropsMsgPayload.h"
3429
#include "architecture/utilities/bskLogging.h"
35-
36-
37-
38-
30+
#include "architecture/utilities/rigidBodyKinematics.h"
31+
#include "simulation/dynamics/_GeneralModuleFiles/dynamicEffector.h"
32+
#include "simulation/dynamics/_GeneralModuleFiles/stateData.h"
3933

4034
/*! @brief spacecraft geometry data */
4135
typedef struct {
42-
std::vector<double> facetAreas; //!< vector of facet areas
43-
std::vector<double> facetCoeffs; //!< vector of facet coefficients
44-
std::vector<Eigen::Vector3d> facetNormals_B; //!< vector of facet normals
45-
std::vector<Eigen::Vector3d> facetLocations_B; //!< vector of facet locations
46-
}SpacecraftGeometryData;
47-
36+
std::vector<double> facetAreas; //!< vector of facet areas
37+
std::vector<double> facetCoeffs; //!< vector of facet coefficients
38+
std::vector<Eigen::Vector3d> facetNormals_B; //!< vector of facet normals
39+
std::vector<Eigen::Vector3d> facetLocations_B; //!< vector of facet locations
40+
} SpacecraftGeometryData;
4841

4942
/*! @brief faceted atmospheric drag dynamic effector */
50-
class FacetDragDynamicEffector: public SysModel, public DynamicEffector {
51-
public:
52-
53-
43+
class FacetDragDynamicEffector : public SysModel, public DynamicEffector {
44+
public:
5445
FacetDragDynamicEffector();
55-
~FacetDragDynamicEffector();
56-
void linkInStates(DynParamManager& states);
57-
void computeForceTorque(double integTime, double timeStep);
58-
void reset(uint64_t currentSimNanos); //!< class method
59-
void updateState(uint64_t currentSimNanos);
60-
void WriteOutputMessages(uint64_t CurrentClock);
61-
bool ReadInputs();
46+
void linkInStates(DynParamManager& states) override;
47+
void computeForceTorque(double integTime, double timeStep) override;
48+
void reset(uint64_t currentSimNanos) override;
49+
void updateState(uint64_t currentSimNanos) override;
6250
void addFacet(double area, double dragCoeff, Eigen::Vector3d B_normal_hat, Eigen::Vector3d B_location);
6351

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

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

77-
private:
7864
AtmoPropsMsgPayload atmoInData;
79-
SpacecraftGeometryData scGeometry; //!< -- Struct to hold spacecraft facet data
80-
65+
SpacecraftGeometryData scGeometry; //!< -- Struct to hold spacecraft facet data
8166
};
8267

8368
#endif

0 commit comments

Comments
 (0)