ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
orbitutils.h
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17Orbit Utilities header file
18---------------------------
19This file contains orbit utilities for converting between "classical"
20keplerian orbital elements and xyz cartesian position and velocity.
21
22It also contains a number of utilities for calculating parameters associated
23with keplerian orbits.
24
25TODO: Protect edge cases in these files. Right now they only work for
26elliptical orbits
27
28The converters in this file are based on those found in Vallado's
29Fundamentals of Astrodynamics and Applications, fourth edition, Chapter
302.5. The test cases are drawn from that text as well.
31
32Author: Alex Reynolds
33*/
34#ifndef UTILS_ORBIT_UTILS_H
35#define UTILS_ORBIT_UTILS_H
36
37#include "core/macros.h"
38#include "core/Matrix.hpp"
39#include "core/CartesianVector.hpp"
40#include "six_dof_dynamics/Frame.hpp"
41#include "six_dof_dynamics/DCM.hpp"
42
43namespace clockwerk {
44 double true2eccentric(double true_anomaly);
45
46 /// @brief Function to convert cartesian xyz pos/vel to orbital elements
47 /// @param pos The x, y, z position of the reference object
48 /// @param vel The x, y, z velocity of the reference object
49 /// @param mu The gravitational parameter of the reference planet
50 /// @param elements The orbital elements returned as {a, e, i, W, w, f} -- angles in radians
51 /// @return Error code corresponding to success/failure
52 /// @note Overloaded for float and double
53 /// @note Automatically rounds 0 values for circular and zero-inclined orbits
54 /// to a minimum tolerance. Some values for orbits in circular and zero-inclined
55 /// orbits may not be valid.
56 /// @note Automatically rounds 0 values for circular and zero-inclined orbits
57 /// to a minimum tolerance. Some values for orbits in circular and zero-inclined
58 /// orbits may not be valid.
59 int rv2coe(const CartesianVector<double, 3> &pos,
60 const CartesianVector<double, 3> &vel,
61 double mu,
62 CartesianVector<double, 6> &elements);
63 /// @brief Function to convert cartesian xyz pos/vel to orbital elements
64 /// @param pos The x, y, z position of the reference object
65 /// @param vel The x, y, z velocity of the reference object
66 /// @param mu The gravitational parameter of the reference planet
67 /// @param elements The orbital elements returned as {a, e, i, W, w, f} -- angles in radians
68 /// @return Error code corresponding to success/failure
69 /// @note Overloaded for float and double
70 /// @note Automatically rounds 0 values for circular and zero-inclined orbits
71 /// to a minimum tolerance. Some values for orbits in circular and zero-inclined
72 /// orbits may not be valid.
73 int rv2coe(const CartesianVector<float, 3> &pos,
74 const CartesianVector<float, 3> &vel,
75 float mu,
76 CartesianVector<float, 6> &elements);
77
78 /// @brief Function to convert orbital elements to cartesian xyz
79 /// @param elements The orbital elements as {a, e, i, W, w, f} -- angles in radians
80 /// @param mu The gravitational parameter of the reference planet
81 /// @param pos Return of the x, y, z position of the reference object
82 /// @param vel Return of the x, y, z velocity of the reference object
83 /// @return Error code corresponding to success/failure
84 /// @note Overloaded for float and double
85 /// @note Automatically rounds 0 values for circular and zero-inclined orbits
86 /// to a minimum tolerance. Some values for orbits in circular and zero-inclined
87 /// orbits may not be valid.
88 /// @todo Update to handle parabolic orbits
89 int coe2rv(CartesianVector<double, 6> &elements,
90 double mu,
91 CartesianVector<double, 3> &pos,
92 CartesianVector<double, 3> &vel);
93 /// @brief Function to convert orbital elements to cartesian xyz
94 /// @param elements The orbital elements as {a, e, i, W, w, f} -- angles in radians
95 /// @param mu The gravitational parameter of the reference planet
96 /// @param pos Return of the x, y, z position of the reference object
97 /// @param vel Return of the x, y, z velocity of the reference object
98 /// @return Error code corresponding to success/failure
99 /// @note Overloaded for float and double
100 /// @todo Update to handle parabolic orbits
101 int coe2rv(CartesianVector<float, 6> &elements,
102 float mu,
103 CartesianVector<float, 3> &pos,
104 CartesianVector<float, 3> &vel);
105
106 /// @brief Function to generate a 3-1-3 DCM to rotate from PQR to XYZ coordinates
107 /// @param i Orbit inclination, in radians
108 /// @param W RAAN, in radians
109 /// @param w Argument of periapsis, in radians
110 /// @return DCM defining the relationship
111 /// @note TODO: Make this function more efficient by pre-defining DCM
112 DCM<double> dcmPqr2Xyz(double i, double W, double w);
113 /// @brief Function to generate a 3-1-3 DCM to rotate from PQR to XYZ coordinates
114 /// @param i Orbit inclination, in radians
115 /// @param W RAAN, in radians
116 /// @param w Argument of periapsis, in radians
117 /// @return DCM defining the relationship
118 /// @note TODO: Make this function more efficient by pre-defining DCM
119 DCM<float> dcmPqr2Xyz(float i, float W, float w);
120
121 /// @brief Function to generate an LVLH frame attitude DCM from position and velocity
122 /// @param pos Spacecraft position
123 /// @param vel Spacecraft velocity
124 /// @param lvlh_frame DCM describing the LVLH frame attitude
125 /// @param lvlh_ang_vel__lvlh Cartesian vector to return angular velocity of LVLH frame in LVLH coordinates
126 /// @return Error code corresponding to success/failure
127 /// @note This model creates and maintains the LVLH reference frame
128 /// according to the NASA definition here:
129 /// https://ntrs.nasa.gov/api/citations/19780010162/downloads/19780010162.pdf
130 /// +Z axis directed toward the center of the Earth
131 /// +Y axis perpendicular to the orbit plane with direction opposite angular momentum
132 /// +X axis completes the right hand frame in the direction of orbit travel
133 int lvlhFrame(const CartesianVector3D &pos, const CartesianVector3D &vel, DCMD &lvlh_frame, CartesianVector3D &lvlh_ang_vel__lvlh);
134
135 /// @brief Function to generate an LVLH frame attitude DCM from position and velocity
136 /// @param pos Spacecraft position
137 /// @param vel Spacecraft velocity
138 /// @param lvlh_frame DCM describing the LVLH frame attitude
139 /// @param lvlh_ang_vel__lvlh Cartesian vector to return angular velocity of LVLH frame in LVLH coordinates
140 /// @return Error code corresponding to success/failure
141 /// @note This model creates and maintains the LVLH reference frame
142 /// according to the NASA definition here:
143 /// https://ntrs.nasa.gov/api/citations/19780010162/downloads/19780010162.pdf
144 /// +Z axis directed toward the center of the Earth
145 /// +Y axis perpendicular to the orbit plane with direction opposite angular momentum
146 /// +X axis completes the right hand frame in the direction of orbit travel
147 int lvlhFrame(const CartesianVector3F &pos, const CartesianVector3F &vel, DCMF &lvlh_frame, CartesianVector3F &lvlh_ang_vel__lvlh);
148
149}
150
151#endif
Standard vector class derived from Matrix.
Definition CartesianVector.hpp:39
Class defining a direction cosine matrix inherited from Matrix.
Definition DCM.hpp:71
#define CartesianVector3F
Definition macros.h:55
#define CartesianVector3D
Definition macros.h:54
#define DCMD
Definition macros.h:70
#define DCMF
Definition macros.h:71