94#include <MatrixLib/MatrixLib.h>
111#define FF_J2 0.001082
115#pragma mark Error Codes
126#pragma mark Formation Types
151#define FF_MAX_ITER 100
156#define FF_MAX_BURNS 10
161#define FF_MAX_MEMBERS 8
177#pragma mark Data Structures
356#pragma mark Control Law
377bool OptimalInPlaneDeltaV(
double nOrbMin,
double nOrbMax,
double a,
double th0,
double th1,
double delta_a,
double delta_th0,
double delta_q1,
double
378delta_q2,
double &dV1,
double &dV2,
double &dV3,
unsigned short &M,
unsigned short &N );
382double &t0,
double &tF,
unsigned short &nBurns );
389#pragma mark Guidance Law
400double NearestOffset(
double y0,
double width, ml_matrix extrema,
double minSepDistance,
double maxSepDistance );
436geom_s PCGoals(
double R,
double alpha0,
double sgn,
double y0 );
463bool EquallyPhased(
const ml_matrix& phi, ml_int_array u,
int Pu );
466ml_int_array
FindMinSet( ml_matrix& mat,
double& minSum );
469void permute(ml_int_array arr,
int start,
int num,
const ml_matrix& mat,
double& cost, ml_int_array& best);
474#pragma mark Linear Programming
480void LPCircular(
const ml_matrix& x0,
const ml_matrix& xF,
double n,
double duration,
double dT,
unsigned short constraintType,
double maxConstraint, ml_matrix& aC, ml_matrix& t,
bool& exitFlag);
483void LPEccentric(
double e,
double n,
const ml_matrix& x0,
const ml_matrix& xF,
double nu0,
double nuF,
int nS, ml_matrix cW,
unsigned short constraintType,
double maxConstraint, ml_matrix& aC, ml_matrix& t,
bool& exitFlag);
495void LPEccentricGVE(
orb_data_t el0,
const ml_matrix& x0,
const ml_matrix& xF,
double MF,
int nS, ml_matrix cW,
unsigned short constraintType,
double maxConstraint, ml_matrix& aC, ml_matrix& t,
bool& exitFlag);
499#pragma mark Eccentric Geometry
504void FFEccLinOrb(
double n,
double nu,
double e, ml_matrix& a, ml_matrix& b,
double dT );
507ml_matrix
FFEccLinOrb(
const ml_matrix& x,
const ml_matrix& acc,
double n,
double nu,
double e );
510ml_matrix
FFEccProp(
const ml_matrix& D,
const ml_matrix& nu,
double e,
double dH );
513ml_matrix
FFEccProp(
const ml_matrix& D,
double nu,
double e,
double dH );
516double FFEccDH(
double nu0,
double e );
525void FFEccIntConst(
const ml_matrix& xH0,
double nu0,
double e, ml_matrix& D,
double& dH, ml_matrix& R );
528ml_matrix
FFEccRMat(
double nu,
double e,
double dH );
531ml_matrix
FFEccRMat(
double nu,
double e );
534void FFEccXExt(
double e,
const ml_matrix& D,
double dH,
double epsilon,
int nMax, ml_matrix& x, ml_matrix& nu );
537void FFEccYExt(
double e,
const ml_matrix& D,
double dH,
double epsilon,
int nMax, ml_matrix& y, ml_matrix& nu );
540void FFEccZExt(
double e,
const ml_matrix& D,
double dH,
double epsilon,
int nMax, ml_matrix& z, ml_matrix& nu );
543void NuDot(
double n,
double e,
double nu,
double& nuDot,
double& nuDotDot );
546double FFEccDX(
double nu,
double e,
const ml_matrix& D,
double dH );
549double FFEccDY(
double nu,
double e,
const ml_matrix& D,
double dH );
552double FFEccDZ(
double nu,
double e,
const ml_matrix& D,
double dH );
555double FFEccDDX(
double nu,
double e,
const ml_matrix& D,
double dH );
558double FFEccDDY(
double nu,
double e,
const ml_matrix& D,
double dH );
561double FFEccDDZ(
double nu,
double e,
const ml_matrix& D,
double dH );
565#pragma mark Coordinate Frames
648void Nu2TimeDomain( ml_matrix& x,
double n,
double e,
double nu );
651void Time2NuDomain( ml_matrix& x,
double n,
double e,
double nu );
666void GetHillsMats(
const ml_matrix& r0,
const ml_matrix& v0, ml_matrix& A, ml_matrix& Adot );
669void AbsRelECI2Hills( ml_matrix r0, ml_matrix v0, ml_matrix dr, ml_matrix dv, ml_matrix& rH, ml_matrix& vH );
678bool AlignThruster(
const ml_matrix& aH,
const ml_matrix& bTh, ml_matrix& qHB );
681bool AlignThruster(
const ml_matrix& aH,
const ml_matrix& bTh,
const ml_matrix& bST,
const ml_matrix& r,
const ml_matrix& v,
double jD,
double sep, ml_matrix& qHB );
684ml_matrix
Hills2Frenet(
const ml_matrix &xH,
const double &e,
const double &nu,
const double &n );
688#pragma mark Propagation
693ml_matrix
HillsEqns(
const ml_matrix& xH0,
double n,
double t );
696ml_matrix
FFEccHillsEqns( ml_matrix xH0,
double nu0,
const ml_matrix& nu,
double e,
double n );
699ml_matrix
FFEccHillsEqns(
const ml_matrix& xH0,
double nu0,
const ml_matrix& nu,
double e );
702ml_matrix
DiscreteHills(
const ml_matrix& x0,
double n,
const ml_matrix& aC,
double dT );
705ml_matrix
FFEccDiscreteHills(
double e,
double n,
const ml_matrix& x0,
double nu0,
const ml_matrix& aC,
const ml_matrix& t );
708#pragma mark Collision Monitoring
713double CollProbSet(
double sigma,
const ml_matrix& S,
const ml_matrix& xc,
const ml_matrix& Ssc,
int n);
716ml_matrix
MonitoringAlg( ml_matrix& y, ml_matrix& t,ml_matrix& M, ml_matrix& nu, ml_matrix& accel, ml_matrix& aDiff,
coll_mon_data_t d );
728double distant_pt_ell(
const ml_matrix& S,
const ml_matrix& U,
const ml_matrix& xc,
const ml_matrix& x0, ml_matrix& x );
731double Laguerre(
const ml_matrix& a,
double x_guess );
755double TimeUntilTheta(
double a,
double w,
double e,
double theta0,
double& theta1 );
770ml_matrix
Tetrahedron(
double d,
const ml_matrix& eul );
773double vsum(
const ml_matrix& a );
776typedef double (*
nr_function)(
double x,
double e,
const ml_matrix& D,
double dH);
782char *
matout( ml_matrix mat );
Definition: sc_geometry.h:22
Physical and mathematical constants.
Coordinate transformation functions.
Time and data conversions and planetary movement, position, and eclipse computations.
Spherical harmonic gravity model type and functions.
Orbit mechanics functions and types, including Keplerian, spherical and cartesian elements.
Alfriend orbital elements data structure.
Definition: sc_formation.h:181
double inc
Inclination [rad].
Definition: sc_formation.h:183
double sma
Semi-major axis [km].
Definition: sc_formation.h:182
double true_lat
True latitude [rad].
Definition: sc_formation.h:185
double q1
ecc*cos(perigee).
Definition: sc_formation.h:186
double epoch
Epoch [Julian Days from J2000].
Definition: sc_formation.h:188
double raan
Right ascension of the ascending node [rad].
Definition: sc_formation.h:184
double q2
ecc*sin(perigee).
Definition: sc_formation.h:187
Assignment data structure.
Definition: sc_formation.h:333
int M
Number of fixed states.
Definition: sc_formation.h:335
int Pu
Number of unique variable states.
Definition: sc_formation.h:337
ml_matrix phi
Array of desired phase offsets for variable states.
Definition: sc_formation.h:339
int P
Number of variable states.
Definition: sc_formation.h:336
int N
Total number of states.
Definition: sc_formation.h:334
int Q
Number of points over which variable states are discretized.
Definition: sc_formation.h:338
ml_int_array u
Array of indices matching phase offsets with unique variable states.
Definition: sc_formation.h:340
Burn data structure.
Definition: sc_formation.h:296
double uY
Unit y-direction in Hills frame.
Definition: sc_formation.h:301
double dT
Burn duration [sec].
Definition: sc_formation.h:298
int iD
Spacecraft ID.
Definition: sc_formation.h:303
double uZ
Unit z-direction in Hills frame.
Definition: sc_formation.h:302
double dV
Delta-v magnitude [km/s].
Definition: sc_formation.h:299
double uX
Unit x-direction in Hills frame.
Definition: sc_formation.h:300
double t
Burn start time [MET].
Definition: sc_formation.h:297
Collision monitor data.
Definition: sc_formation.h:344
double lenSC
Spacecraft maximum dimension [m].
Definition: sc_formation.h:349
orb_data_t el_ref
Reference orbital data.
Definition: sc_formation.h:345
int nPts
Number of points for collision set probabilty.
Definition: sc_formation.h:352
ml_matrix init_bounds
Measurement error, 1x6 matrix [km, km/s].
Definition: sc_formation.h:346
double sigma
Sigma of measurement error.
Definition: sc_formation.h:347
ml_matrix Ssc
Spacecraft hard-body sphere [km2].
Definition: sc_formation.h:350
double Pmin
Probability corresponding to sigma.
Definition: sc_formation.h:348
ml_matrix S0
Initial ellipsoid, 6x6 matrix [km2].
Definition: sc_formation.h:351
Constraints data structure.
Definition: sc_formation.h:260
ml_matrix phase
Phase offset of each duplicate state [rad].
Definition: sc_formation.h:265
ml_int_array restrictID
Array of member IDs to restrict assignments to .
Definition: sc_formation.h:263
int nDuplicates
Number of duplicate states.
Definition: sc_formation.h:264
bool variable
Flag indicating whether the associated geomtric goals are fixed (false) or variable (true).
Definition: sc_formation.h:261
int nRestrict
Number of members to restrict assignments to.
Definition: sc_formation.h:262
Cost estimate data structure.
Definition: sc_formation.h:287
ml_int_array costLength
Length of the cost vector for each unique target state.
Definition: sc_formation.h:291
ml_int_array targetIndex
Array of indices corresponding to unique target states.
Definition: sc_formation.h:290
int nU
Number of unique target states that costs were computed for.
Definition: sc_formation.h:288
ml_matrix cost
Cost vectors for all unique target states.
Definition: sc_formation.h:292
int memID
Spacecraft ID.
Definition: sc_formation.h:289
Delta-V command data structure.
Definition: sc_formation.h:317
double pulsewidth
Burn duration [sec].
Definition: sc_formation.h:319
double timeTag
time at which to send the command [MET]
Definition: sc_formation.h:320
int kTank
Index of tank to use.
Definition: sc_formation.h:318
int iD
Maneuver command ID.
Definition: sc_formation.h:321
Eccentric geometry data structure.
Definition: sc_formation.h:221
double xMax
Maximum radial separation [km].
Definition: sc_formation.h:223
double nu_xMax
True anomaly where maximum radial separation occurs [rad].
Definition: sc_formation.h:224
double y0
Along-track offset of center of relative motion [km].
Definition: sc_formation.h:222
double nu_zMax
True anomaly where maximum cross-track separation occurs [rad].
Definition: sc_formation.h:226
double zMax
Maximum cross-track separation [km].
Definition: sc_formation.h:225
Eccentric geometry data structure (xy)
Definition: sc_formation.h:230
double y0
Along-track offset of center of relative motion [km].
Definition: sc_formation.h:231
double x
Radial position at nu_xy [km].
Definition: sc_formation.h:232
double nu_xy
True anomaly where maximum radial separation occurs [rad].
Definition: sc_formation.h:234
double nu_zMax
True anomaly where maximum cross-track separation occurs [rad].
Definition: sc_formation.h:236
double zMax
Maximum cross-track separation [km].
Definition: sc_formation.h:235
double y
Along-track position at nu_xy [km].
Definition: sc_formation.h:233
Eccentric team goals data structure.
Definition: sc_formation.h:278
constraints_t constraints[FF_MAX_MEMBERS]
Array of assignment constraints.
Definition: sc_formation.h:282
double dPhi
Angular resolution [rad].
Definition: sc_formation.h:283
int nU
Number of unique states.
Definition: sc_formation.h:279
int teamID
Team ID.
Definition: sc_formation.h:280
Geometry data structure.
Definition: sc_formation.h:212
double zLan
Maximum cross-track amplitude due to right ascension difference [km].
Definition: sc_formation.h:217
double y0
Along-track offset of center of relative motion [km].
Definition: sc_formation.h:213
double beta
Phase angle on relative ellipse at equator crossing, measured from -x axis to +y axis [rad].
Definition: sc_formation.h:215
double zInc
Maximum cross-track amplitude due to inclination difference [km].
Definition: sc_formation.h:216
double aE
Semi-major axis of relative ellipse [km].
Definition: sc_formation.h:214
Maneuver data structure.
Definition: sc_formation.h:307
bool achieve
Flag indicating whether to achieve the maneuver or not.
Definition: sc_formation.h:308
burn_t burnData[FF_MAX_BURNS]
Array of burn data structures.
Definition: sc_formation.h:310
double t0
Maneuver start time [MET].
Definition: sc_formation.h:311
int iD
Maneuver command ID.
Definition: sc_formation.h:313
double tF
Maneuver completion time [MET].
Definition: sc_formation.h:312
int nBurns
Number of burns.
Definition: sc_formation.h:309
Structure for storing orbit data.
Definition: sc_orbit.h:33
Orientation data structure.
Definition: sc_formation.h:325
ml_matrix qHB
Desired Hills-to-body quaternion to align the thruster properly.
Definition: sc_formation.h:326
double dT
Duration to remain at target orientation [sec].
Definition: sc_formation.h:328
int iD
Maneuver command ID.
Definition: sc_formation.h:329
double timeTag
time at which to send the command [MET]
Definition: sc_formation.h:327
Planning parameters data structure.
Definition: sc_formation.h:249
int nSPOCoarse
Number of samples per orbit to use in coarse LP planning.
Definition: sc_formation.h:254
double horizon
Minimum time required between planning and first burn [sec].
Definition: sc_formation.h:251
double fNom
Nominal thrust capability [kN].
Definition: sc_formation.h:250
double dTMin
Minimum achievable burn time [sec].
Definition: sc_formation.h:252
double maxDeltaV
Maximum achievable delta-v for a single burn [km/s].
Definition: sc_formation.h:253
int nSPOFine
Number of samples per orbit to use in fine LP planning.
Definition: sc_formation.h:255
double eTol
Eccentricity tolerance.
Definition: sc_formation.h:256
State data structure.
Definition: sc_formation.h:202
alf_orb_data_t dEl
Alfriend orbital element differences.
Definition: sc_formation.h:205
double mass
Mass.
Definition: sc_formation.h:208
ml_matrix xH
Relative position and velocity in Hills frame.
Definition: sc_formation.h:206
double tM
Measurement time [MET].
Definition: sc_formation.h:207
alf_orb_data_t elA
Alfriend orbital elements.
Definition: sc_formation.h:204
orb_data_t el
Standard orbital elements.
Definition: sc_formation.h:203
Team goals data structure.
Definition: sc_formation.h:269
int teamID
Team ID.
Definition: sc_formation.h:271
int nU
Number of unique states.
Definition: sc_formation.h:270
constraints_t constraints[FF_MAX_MEMBERS]
Array of assignment constraints.
Definition: sc_formation.h:273
double dPhi
Angular resolution [rad].
Definition: sc_formation.h:274
Team data structure.
Definition: sc_formation.h:192
ml_int_array memID
Team member IDs.
Definition: sc_formation.h:195
int nMembers
Number of team members.
Definition: sc_formation.h:194
int level
Level of team in hierarchy.
Definition: sc_formation.h:198
int teamID
Team ID.
Definition: sc_formation.h:193
int captainID
Captain ID.
Definition: sc_formation.h:197
int refID
Reference ID.
Definition: sc_formation.h:196
Time window data structure.
Definition: sc_formation.h:240
double startTime
Earliest allowable start time [MET].
Definition: sc_formation.h:241
double nOrbMax
Maximum number of orbits that the maneuver may last.
Definition: sc_formation.h:243
double nOrbMin
Minimum number of orbits that the maneuver may last.
Definition: sc_formation.h:242
int nManeuvers
Total number of maneuvers to plan, between min and max durations.
Definition: sc_formation.h:244
double timeWeightExp
Exponent for weighting the cost with maneuver time.
Definition: sc_formation.h:245