Modeling and Attitude Control of Satellites in Elliptical Orbits

The attitude determination and control system (ADCS) for spacecraft is respon-sible for determining its orientation using sensor measurements and then applying actuation forces to change the orientation. This chapter details the different components required for a complete attitude determination and control system for satellites moving in elliptical orbits. Specifically, the chapter details the orbital mechanics; perturbations; controller design; actuation methods such as thrusters, reaction wheels, and magnetic torquers; actuation modulation methods such as bang-bang, pulse-width modulation, and pulse-width pulse-frequency; as well as attitude determination using vector measurements combined with mathematical models. In sum, the work describes in a tutorial manner how to put everything together to enable the design of a complete satellite simulator.


Introduction
The problem of developing attitude determination and control systems (ADCS) has received much attention in the last century with general books such as [1][2][3][4], as well as description of individual ADCS designs for different satellites in works such as [5][6][7][8]. While Refs. [1,2] can be considered excellent foundation books within the topic of spacecraft modeling and control, there is a need for a more concise presentation of the attitude control problem and how this can be modeled in a simple manner, both not only as a tutorial for new researchers but also to give insight into the different components required for ADCS design drawing on ideas and results from previous works as mentioned above.
This chapter is an extension of [9] and builds on much of the previous work, as well as the research done through the HiNCube project as presented in [10][11][12]. This work considers the problem of designing a complete ADCS system comprising all the required components. Figure 1 shows the control structure and the required signal paths, giving an overview of the contents in this chapter, as each block is described in detail to put the reader in position to design their own ADCS system. The required sensors for this system are a magnetometer to measure the Earth's magnetic field, a gyro to measure the angular velocity of the satellite, as well as Sun sensors for measuring the direction toward the Sun. Further, the mathematical models used together with sensor measurements to determine the attitude of the satellite requires a real-time clock, as the time and date are required to know the direction toward the Sun as well as what the magnetic field looks like at a given day and time. Comparing the sensor measurements with the mathematical models allows for the determination of the attitude of the satellite, something that is done using the Madgwick filter as presented in [13]. With an estimated attitude obtained using the Madgwick filter, the attitude can be controlled to point a sensor onboard the satellite in a desired direction, something that is solved in this chapter using a PD+ attitude controller, calculating the desired torques required in order to make the attitude and angular velocity errors go to zero. In order to create the desired moments, this chapter presents how this can be achieved using a number of different actuators, namely, magnetic torquers, reaction wheels, and thrusters. The orbital mechanics block describes how the satellite moves in its elliptical orbit, while the perturbing forces and moments block describe how the different perturbations affect the satellite. Simulations show the performance of the different methods and should put the reader in a position to simulate and design new attitude determination and control systems for satellites in elliptical orbits.

Mathematical modeling 2.1 Notation
This subsection is similar to the author's previous works, e.g., [9,14]. Let _ x ¼ dx=dt denote the time derivative of a vector, while the Euclidean length is defined as kxk ¼ ffiffiffiffiffiffiffiffi . Superscript denotes frame of reference for a given vector. The rotation matrix is denoted R c a ∈SO 3 ð Þ ¼ R∈R 3Â3 : R Τ R ¼ I; det R ð Þ ¼ 1 È É , which rotates a vector from frame a to frame c and where I denotes the identity matrix. The inverse rotation is found by taking its transpose, such that R a c ¼ R c a À Á Τ .
The angular velocity of frame c relative to frame a referenced in frame e is denoted ω e a, c , and angular velocities can be added together as ω e a, f ¼ ω e a, c þ ω e c, f (cf. [15]). The derivative of the rotation matrix is defined as _ R c a ¼ R c a S ω a c, a À Á where S Á ð Þ denotes the cross product operator, which is defined such that for two vectors Quaternions can be used to parameterize the rotation matrix, where q c, a ∈S 3 ¼ q∈R 4 : q Τ q ¼ 1 È É denotes the quaternion representing a rotation from frame a to frame c through the angle of rotation ϑ c, a around the axis of rotation k c, a . The inverse quaternion is defined as q a, c ¼ η c, a À ε Τ c, a Â Ã Τ , also sometimes denoted as q * . A quaternion comprises a scalar and a vector part, where η c, a denotes the scalar part, while ε c, a ∈R 3 denotes the vector part. This allows the rotation matrix to be constructed using quaternions as R c a ¼ I þ 2η c, a S ε c, a ð Þþ2S 2 ε c, a ð Þ. Composite quaternions can be found through quaternion multiplication as The use of the quaternion product ensures that the resulting quaternion maintains the unit length property. The quaternion kinematics is defined as For attitude control, several different frames are needed: Inertial: The Earth-centered inertial (ECI) has its origin in the center of the Earth, where the x i axis points toward the vernal equinox and the z i points through the North Pole, while y i completes the right-handed orthonormal frame. The inertial frame is denoted by F i .
Orbit: The orbit frame has its origin in the center of mass of the satellite (cf. [16], p. 479). The e r axis coincides with the radius vector r i ∈R 3 , which goes from the center of the Earth to the center of mass in the satellite. The e h axis is parallel to the orbital angular momentum vector, pointing in the normal direction of the orbit. The e θ completes the right-handed orthonormal frame where the vectors can be described as e r ¼ r i kr i k , e θ ¼ e h Â e r , and Body: The body frame has its origin in the center of mass of the satellite, where its axes coincide with the principal axes of inertia. The body frame is denoted by F b .
Desired: The desired frame can be defined arbitrarily to achieve any given objective (cf. [17]). The desired frame is denoted by F d .

Orbital mechanics
This section describes how the orbit frame can be related to the inertial frame through the six classical orbital parameters, and for more details, the reader is referred to [1]. Specifically, the objective with this subsection is to find the radius, velocity, and acceleration vector of the orbit, as well as its angular velocity and acceleration. From well-known orbital mechanics, the six classical parameters can be defined as the semimajor axis a, the eccentricity e, the inclination i, the right ascension of the ascending node Ω, the argument of the perigee ω, and the mean anomaly M. The distance to the apogee and perigee from the center of the Earth can be defined, respectively, as r a and r p , allowing the semimajor axis to be found as a ¼ r a þr p 2 and the eccentricity of the orbit as e ¼ r a Àr p r a þr p , while the mean motion can be found from n ¼ ffiffiffi ffi μ a 3 p . Here, μ ¼ GM Earth , where G is the gravitational constant, while M Earth is the mass of the Earth. With knowledge of the mean motion, the mean anomaly can be found as M ¼ n t À t 0 ð Þ¼ψ À e sin ψ ð Þ where ψ is the eccentric anomaly, t is the time, and t 0 is the time when passing the perigee. To properly describe where in the orbit the satellite is located, the true anomaly can be found as p. 42). When running a simulation, it is desirable to have a continuously increasing true anomaly, while the direct method will map the angle between 0 and 180°. Instead, by integrating the derivative overtime, a smooth true anomaly can be found that increases continuously. The eccentric anomaly, however, cannot be found analytically, but can be found through an iterative algorithm as described in where k is the iteration number. This algorithm is valid as long as 0 < e < 1, which holds for elliptical orbits. From these calculations, the rotation matrix from inertial frame to orbit frame can now be constructed as The radius, velocity, and acceleration vector can be defined in the orbit frame, respectively, as ( [1], pp. 26-27) a o ¼ À a 3 n 2 r 2 cos ψ ð Þ À a 3 n 2 where r ¼ kr i k is the length of the radius vector. Each of these vectors can be rotated to the inertial frame using Eq. (3), such that The angular velocity of the orbit frame relative to the inertial frame can be found as ð Þ Τ r i , while the angular acceleration can be found through differentiation as In order to implement the orbital mechanics in, e.g., a Simulink framework, the required input to the subsystem would be the time (t). Further, the orbital parameters must be defined as given in Table 1 and can be changed depending on the orbit. These constants allow for the calculations of the eccentricity (e), the semimajor axis (a), and mean motion (n). With the mean motion, the mean anomaly (M) can be found and used to approximate the eccentric anomaly (ψ) using the iterative algorithm presented above. The rate of change of the true anomaly ( _ θ) can also be found and by integration enables the calculation of true anomaly (θ). All these values allow for calculating the rotation matrix from the orbit frame to the inertial frame (R i o ), the radius vector (r o ), the velocity vector (v o ), the acceleration vector (a o ), angular velocity (ω i i, o ), and angular acceleration vector ( _ ω i i, o ). Hence, all the outputs from this subsystem can easily be found following this procedure and will be used in several other subsystems.

Attitude dynamics
The attitude dynamics can be derived with the basis in Euler's moment Equation ([1], p. 95). The angular momentum of a rigid body in the body frame is given as where J∈R 3x3 is the inertia matrix, while ω b i, b ∈R 3 is the angular velocity of the body frame relative to the inertial frame. The angular momentum can be found in the inertial frame as The rate of change of angular momentum is equal to the total torque, such that Hence, by differentiating Eq. (9), it is obtained that which can be written in the body frame by using Eq. (8) as where the inertia matrix is assumed to be constant. Decomposing the total torque into an actuation component and a perturbing component, τ b ¼ τ b a þ τ b p , allows the rotational dynamics to be written as where τ b a ∈R 3 denotes the actuation torques (e.g., output from reaction wheels), while τ b p ∈R 3 denotes the perturbing torques (e.g., gravity torque). Further, by using quaternion representation, the update law for the quaternion representing the attitude of the body frame relative to the inertial frame can be written as Hence, Eqs. (11) and (12) serve as governing equations describing the attitude and angular velocity of the satellite. The inputs that affect these values are the perturbation and actuation torques, where the latter will be found in the following sections.

Error dynamics
From Euler's moment equation, the angular acceleration is defined relative to the inertial frame. For attitude control, it is often more interesting controlling the attitude and angular velocity relative to the orbit frame. For that reason, the angular velocity of the body frame relative to the orbit frame can be found as giving a description of the attitude dynamics relative to the orbit frame. It is also possible to find the error dynamics, to enable tracking of a desired attitude and angular velocity. Let q o, d , ω d o, d , _ ω d o, d ∈L ∞ denote a desired quaternion, angular velocity, and acceleration; then, the quaternion and angular velocity error can be found as with the kinematics as The angular acceleration error can be found by differentiating Eq. (15) as Hence, the control objective can be defined as that of making ! 0; 0 ð Þ, which will make the satellite point in a desired direction and move with a desired angular velocity.

PD+ attitude controller
Takegaki and Arimoto [19] proposed in 1981 a simple method for position control of robots, something that was extended by [20] to enable trajectory tracking. The so-called PD+ controller has been applied for spacecraft by [21,22] showing good results. The author has applied this method in previous works such as [23,24].
In order to design a PD+ attitude controller, let a Lyapunov function candidate be chosen as where k p is a positive scalar gain. The derivative is found by using Eqs. (16)-(18) as A PD+ attitude control law can now be chosen as where k d is another positive scalar gain and τ b d denotes the desired torque required to make the attitude and angular velocity errors go to zero. Assuming no actuator dynamics, i.e., τ b a ¼ τ b d , and then by inserting Eq.
The inputs to the control law (Eq. 20) are the desired states q o, d , ω d o, d , and _ ω d o, d , which are to be defined by the reader, e.g., as part as a guidance block depending on the mission objective. The inertia matrix (J) is assumed to be known, while the angular velocity vector between the body frame and orbit frame (ω b o, b ) can be found as described above. The other angular velocities are found from the orbital mechanics, while the rotation matrices are found as composite rotations, e.g., or by using the relationship between the quaternions and rotation matrices directly (cf. Section 2A). The error quaternion and angular velocity are found from Eqs. (14) and (15), while the perturbing torques will be described in the following section.

Perturbing torques
There are different kinds of perturbing torques, such as gravity torque, aerodynamic torque, magnetic field due to the electronics inside the satellite, as well as solar radiation torque. This section only considers the gravity torque. In [16], p. 147, the gravity torque is defined as where the terms have previously been defined. As can be seen from this equation, non-diagonal inertia matrices will induce gravitational torques to align the satellite with the gravity field. This is also sometimes used for passive control, using e.g., a gravity boom to ensure that one side of the satellite is always facing the Earth. For this chapter, the perturbing toque is set equal to the gravity torque such that

Actuators
The control signal must be mapped to an actuator that must generate the desired torque. With limitations in actuation, the saturation must be modeled in order to obtain realistic results when simulating attitude control. This section considers three types of actuators commonly used for spacecraft attitude control: magnetic torquers, reaction wheels, and thrusters.

Magnetic torquers
Magnetic torquers operate by creating a local magnetic field that interacts with the Earth's magnetic field. In simple terms, magnetic torques can be explained as that of a compass needle. By applying current through a coil, a local magnetic field is created, which will try to align itself with the Earth's magnetic field. This allows the attitude of a spacecraft to be changed and is a very popular approach for small satellites, e.g., cubesats. One of the drawbacks or challenges with magnetic actuation lies in the fact that the Earth's magnetic field goes from the North Pole to the South Pole as shown in Figure 2. 1 As can be seen, when the satellite crosses the North Pole, there will be mainly a downward magnetic field component, reducing the possibility of actuation to only two axes, and similarly along the equator. This subsection is based on [12] and will describe how to model magnetic torquers and how it can be applied for attitude control. A magnetic torquer produces a magnetic torque by applying a current through a coil, which can be expressed as [2]. Magnetic field of the Earth visualized using the IGRF model. The control torque using magnetic torquers is always perpendicular to the magnetic field, such that a the poles, only roll, and pitch control are available, while at the equator, only pitch and yaw control is available [25]. 1 Figure created using the MATLAB script "international geomagnetic reference field (IGRF) model" by where N is the number of turns of the coils, i Á ð Þ is the current around a given axis, and A is the area of the coils. The Earth's magnetic field is represented through the vector b b , meaning that to use magnetic actuation for attitude control, a good model of the Earth's magnetic field is needed.
From a control point of view, the physical parameters A and N are defined when the spacecraft is designed, such that the controller needs to dictate which currents that must be sent to the torquers in order to get a desired torque. This means that Eq. (22) must be inverted with regard to m b , which is not straightforward due to the cross product, meaning that you obtain rank 2 when inverting the right-hand side, losing information about one of the axes. To that end, an approximation to inverting this equation is given in [25].
enabling the currents to be found as It is here assumed that all three torquers are identical, but depending on satellite configuration, there might be differences in the number of turns and areas. Hence, the desired torque τ b d can be used to find the magnetic moment m b in Eq. (23) and solved for the currents and applied resulting in the actuation torque in Eq. (22). Hence, the control law (Eq. 20) can be mapped to a desired magnetic moment (Eq. 23), which then can be used to find the desired current to each of the three coils. Then, the limits in current will dictate the maximum magnetic moment that can be generated.
Consider the HiNCube satellite as shown in Figure 3. The cubesat comprises three orthonormal magnetic torquers with an area A ¼ 0:00757 m 2 and with a maximum current of 47.27 mA and N ¼ 100 turns. This gives a maximum magnetic moment of m max ¼ 0:03578 mA 2 . Hence, an implementation of using magnetic torquers for attitude control would encompass mapping the output from the control law to a desired magnetic moment using Eq. (23) and then imposing the maximum magnetic moment on each axis, before finding the resulting actuation torque using Eq. (22). Note that to ensure sign correctness due to the projection, the actuation torque can be found as To show the performance of magnetic torquers, consider again the HiNCube satellite, which had an inertia matrix of J ¼ 1:67 Á 10 À3 I kg m 2 . Consider the problem of making rotating 90°from an initial quaternion The gains for the PD+ controller are set k p ¼ 1 Á 10 À5 and k d ¼ 5 Á 10 À3 , and the satellite is assumed to have an orbit of r p ¼ 500 km and r a ¼ 600 km, with inclination of 75°. Figure 4 shows the attitude, angular velocity, and actuation torque. It is evident that magnetic torquers produce very low torque, such that it takes a very long time to change the attitude of the spacecraft (about 1 h).
To some extents, this can be improved by being in a lower orbit where the magnetic  field is stronger or by using larger coils with higher currents. Also, note that the actuation signal varies in strength as a function of time, depending on the orbital position of the satellite.

Reaction wheels
Another way of changing the attitude of a satellite is through reaction wheels. Reaction wheels are based on the principle of Newton's third law: When one body exerts a force on a second body, the second body simultaneously exerts a force equal in magnitude and opposite in direction on the first body. This means that by spinning a reaction wheel in one direction, the satellite will rotate in the other direction. Mounting three reaction wheels in an orthogonal configuration enables three-axis attitude control of spacecraft. From Newton's third law, the momentum generated by the reaction wheels will have opposite sign of the momentum of the satellite, such that _ w is the momentum production by the reaction wheels, _ h i is the momentum acting on the satellite, and τ b w . By employing Euler's moment equation similarly as in Section 3, the torque generated by the reaction wheels can be found by differentiating h w is the angular velocity of the reaction wheels and J w denotes their inertia. This gives where τ b w ¼ _ h b w is the torque generated by the reaction wheels. Now, consider a set of three orthonormal reaction wheels, where one produces torques around the xaxis, one around the y-axis, and one around the z-axis of the body frame. Then, the PD+ control law dictates a desired torque, τ b d , which shall be achieved by the reaction wheels. To that end, the torque by the reaction wheel can be rewritten as where τ b w must be bounded by the motor torque limit, while the angular momentum will be bounded as a function of maximum rotational speed. After imposing the torque and speed constraints, the angular momentum of the reaction wheels is found by integrating _ h b w allowing the actuation torque to be calculated using Eq. (26).
Consider the HiNCube satellite again, where it is possible to use three small reaction wheels as described in [11] where the main idea is to place most of the mass away from the center as shown in Figure 5. The inertia of an individual reaction wheel was found to be J w ¼ 1:46 Á 10 À5 kg m 2 , and by assuming a maximum rotation speed of 13,700 rpm with maximum torque of τ max ¼ 0:0047 Nm, the maximum momentum generated by the reaction wheels is found as h max ¼ J w ω w ¼ 1:46 Á 10 À5 Á 13700 Á 2π 60 ¼ 1:52389 Á 10 À6 . Now, consider the same simulation as when using the magnetic torquers, where the gains for the PD+ controller is changed to k p ¼ k d ¼ 2 and the reaction wheels has the limits as defined above. Figure 6 shows the simulation results, where it is obvious that by using reaction wheels, the satellite is able to change its orientation after about 80 s. To some extent, this can be credited to the higher gains, but it lies mainly with the better actuation system that is able to produce higher torque than the reaction wheels. From the figure, the reaction wheels quickly go into saturation of 13, 700 RPM, where the angular velocity also goes into saturation. As the quaternion error goes toward zero, the reaction wheel despin, reducing the angular velocity and the control objective, is completed.

Thrusters
The third kind of actuator that will be studied is using reaction control thrusters. This section presents how to map the control signal (Eq. 20) to four thrusters used for attitude control. Let the location of each thruster be denoted by  r b i ¼ r x r y r z Â Ã Τ , and let them have an azimuth and an elevation angle described by χ and γ. Then, the torque produced by a given thruster can be found as [1], p. 262 where f i denotes the total thrust from the ith thruster. Given the thruster configuration defined in Table 2, let the vector of thruster signals be denoted Given a desired torque from the PD+ control law, it must be mapped to the desired thruster firings, such that the combination of thrusters produces the desired torque. To that end, there are several different modulation methods that can be applied, ranging from a simple bang-bang modulation to more sophisticated pulsewidth pulse-frequency modulation. This section will give an introduction to the different methods and detail how they can be implemented. In general the desired torque can be mapped to the desired thruster firings as u d ¼ B † τ b d where † denotes the Moore-Penrose pseudoinverse and u d ¼ u 1 u 2 u 3 u 4 ½ Τ denotes the magnitude of each of the thrusters.
1. Bang-bang modulation: The easiest approach to thruster firings is bang-bang modulation, where the thruster is fully actuated as long as the ith signal of u d is above zero, such that where f max denotes the maximum available thrust from the ith thruster. After applying bang-bang modulation, the vector u can be constructed allowing the actuator torque to be found as τ b a ¼ Bu. 2. Bang-bang modulation with dead zone: One of the major drawbacks by using simple bang-bang modulation is when the tracking error has converged to zero, where the thruster firings will continue to maintain the desired attitude. Sensor noise is another source that leads to continuous firings, quickly spending all the propellant. To that end, bang-bang modulation can be augmented with a dead zone, giving where D>0 denotes the dead zone. By properly selecting a suitable dead zone enables the thrusters to avoid firing when close to the equilibrium point.
3. Pulse-width modulation: Another approach that is often used for thruster firings is by using pulse-width modulation (PWM), where an analogue signal (desired torque) can be mapped to discrete signals using PWM. Instead of changing the thrust level, the duration of the pulses can be changed, leading to a pulse that is proportional to the torque command from the PD+ controller. A simple way of achieving this is by using the intersective technique, which uses a sawtooth signal that is compared to the control signal. When the sawtooth is less than the control signal, the PWM signal is in a high state and otherwise in a low state. This makes it possible to go from continuous control signal to a discrete representation which can be used for thruster firings. Figure 7 shows how to achieve the PWM signal, enabled through a simple comparison of the two signals.
4.Pulse-width pulse-frequency modulation: In addition to controlling the width of the pulse as in PWM, it is also possible to control the frequency of the pulse-something that is done through pulse-width pulse-frequency (PWPF) modulation ([1], p. 265) (Figure 8). The modulation approach comprises a lag filter and a Schmitt trigger as shown in Figure 9. As long as the input to the Schmitt trigger is below U on , the output is kept at zero and must be larger than U on K to produce an output, where K is a DC gain, τ is the time constant, U on and U off are the on and off limits for the Schmitt trigger, while U m is the maximum output. Much research has been performed on improving PWPF modulation, and in [26], the authors propose the following settings (cf. Figure 9): 2 < K < 6, 0:1 < τ < 0:5, U on >0:3, U off < 0:8U on , and U m ¼ 1. Figure 7.
Thruster configuration. The left subfigure shows the definition of azimuth and elevation angles used to dictate the orientation of the thruster, while the right subfigure shows a satellite with thrusters placed and oriented as given in Table 2.    Figure 11. Thruster firings when using bang-bang modulation. where the objective is to perform a yaw maneuver of 90°using four thrusters with 0:1 N force, with a specific impulse of 200 s. Figure 10 shows the attitude and angular velocity vectors when using bang-bang modulation, where the satellite is able to make the errors go to zero. However, due to the modulation, the thrusters will continue firing as shown in Figure 11. To that end, consider the bang-bang modulation with dead zone. Let the dead zone be chosen as D ¼ 0:05, and then the satellite obtains an accuracy as shown in Figure 12 where there is a small Figure 13.
Thruster firings when using bang-bang modulation with dead zone.

Figure 14.
Attitude control using thrusters with PWM modulation.
offset from the origin which is proportional to the dead zone. On the other hand, the thruster firings are much less prone to do continuous firings as shown in Figure 13. Now, consider pulse-width modulation. Let the sawtooth signal have an amplitude of 1 and a frequency of 1 Hz. Then, the attitude and angular velocity error is obtained as shown in Figure 14, while the thruster firings are shown in Figure 15. It is possible to tune on sawtooth frequency to improve the performance.  The final scenario is using PWPF modulation, where the parameters are chosen as K ¼ 3, τ ¼ 0:2, U on ¼ 0:35, and U off ¼ 0:28. Figure 15 shows the attitude and angular velocity, which go close to zero, while the thruster firings are shown in Figure 16, which is able to constrain the amount of thruster firings, and therefore propellant.
For satellite control using thrusters, propellant is a critical resource that must not be wasted. To that end it is desirable to limit the amount of propellant while at the same time obtain good pointing accuracy ( Figure 17). With the basis in  Tsiolkovsky's rocket equation, the propellant consumption during thruster firings can be found as m propellant ¼ Ð t 0 f I sp g dt where f is the force from one of the thrusters and I sp is the specific impulse, while g ¼ 9:81 m/s 2 is the acceleration due to gravity. Figure 18 shows a comparison between the different modulation methods, where it is evident that the PWPF method allows for the least amount of propellant while obtaining close to acceptable performance. The bang-bang modulation will continue spending propellant until running out of fuel but on the other hand obtains the best tracking performance.

Attitude determination
As a preliminary step before trying to estimate the attitude of the satellite, some knowledge of measurement vectors must be known, i.e., what is the direction toward the Sun and how does the magnetic field vector look like at a given position. There are several other quantities that can be measured to obtain the attitude, where star trackers are known to be the most accurate. For the reader to obtain insight into using multiple measurements and combine it to find the attitude, this work presents a Sun vector model and a simplified magnetic field model that can be used for simulation purposes.

Sun vector model
To find the direction toward the Sun, there are several models that can be applied. The simplest would be to divide a circle into 365 days and have a vector always point toward the Sun. Then, by knowing which day it is, it is straightforward to find the direction toward the Sun. This approach would be coarse, such that more accurate models exist. For example, the Sun vector model in [3], pp. 281-282, has an accuracy of 0:01 ∘ and is valid until 2050. First, the time and date must be converted into the Julian date as [3], p. 189.
Here, the number of Julian centuries is denoted by T UT1 , the mean longitude of the Sun is denoted by λ M ⊙ , the mean anomaly for the Sun is denoted by M ⊙ , the ecliptic longitude is denoted by λ ecliptic , and the obliquity of the ecliptic is denoted by ε, while the Sun vector in orbit frame is denoted by s o .

Magnetic field model
Several different geomagnetic models can be applied for attitude determination in conjunction with a magnetometer. The most basic are simple dipole models [27], while more advanced are, e.g., the chaos model or the 12th generation IGRF model [28], which is the most commonly used model for attitude determination. This section presents the simple dipole model by [27], which can be described by the magnetic field vector in orbit frame as where the time measured from passing the ascending node of the orbit relative to the geomagnetic equator is denoted by t and the dipole strength is denoted μ f ¼ 7:9 Á 10 À15 Wb-m, while ω 0 ¼ kω i i, o k denotes the angular speed of the orbit. For a real application, the reader is recommended to apply the IGRF model, which is available in Simulink inside the Aerospace Toolbox, as C++ implementation 2 or using Python. 3

Attitude determination using the Madgwick filter
The objective of attitude determination is to find what direction the satellite is pointing. In its core, it mainly requires two vector measurements and two mathematical models that can be compared and used to find the attitude. There are several different kinds of filters applied for attitude estimation, such as the Triad method [29], the Kalman filter [30], or the Mahony filter [31]. The Madgwick filter by [13] has shown good results in attitude estimation based on IMU measurements and is commonly applied in drone applications. The main idea by the filter is to use gradient descent in combination with the complementary filter to fuse sensor data together to produce an estimated quaternion. This section presents an application of the Madgwick filter by using measurements of the Sun vector and the magnetic field vector as well as the acceleration vector (gravity) and shows how to fuse that data together to estimate the attitude of a satellite in an elliptical orbit.
Let the quaternion estimate be denoted byq ¼ q 1 q 2 q 3 q 4 Â Ã Τ . The measured acceleration, Sun vector, and magnetic field vectors can be defined, respectively, as a b , s b , and m b and can be combined with the mathematical models of the acceleration, Sun vector, and magnetic field vector given in Eqs. (6), (38), and (39) to estimate the attitude. Here, the current estimate is denoted by subscript k, while the previous estimate is denoted by k À 1. Let the objective function be where β and ζ are gains, the time step is denoted by ΔT, the estimated angular velocity based on vector measurements is denotedω b k ∈R 4 , and the estimated gyro bias is denoted by ω b bias, k ∈R 4 , while the angular velocity of the body frame relative to the orbit frame is denoted ω b o, b ∈R 3 (expected output) and the estimated quaternion is denotedq k describing the body frame relative to the orbit frame. Note that the quaternion must be normalized to ensure unit length and that the first elements ofω b k , ω b bias, k ∈R 4 are enforced to zero. To map the angular velocity from four to three elements, the projection matrix is defined as H ¼ 0 I ½ ∈R 3Â4 , which has a column vector of zeros followed by the identity matrix such that ω b o, b ∈R 3 .

Simulation
Let a satellite have the inertia matrix as given in Eq. (43), which contains nondiagonal terms which therefore will create perturbing moments due to the gravity. Furthermore, let the satellite have the following initial conditions: To model noise in the sensor measurements, the quaternion is converted into Euler angles, where noise is added to the different sensors. Then, creating the rotation matrix from the noisy Euler angles allows the Sun vector, acceleration, and magnetometer models in the orbit frame to be rotated to the body frame, where the measurements now contain noise. The step size of the simulation is 0:01, while the sensors are sampled every 0:1 s.
The quaternion and angular velocity error of the satellite are shown in Figure 18. After about 50 s, the objective of making the attitude error and angular velocity Figure 19. Attitude and angular velocity during the maneuver [9]. error go to zero is achieved. Since the attitude is not measured directly, the Madgwick filter is used for attitude estimation as shown in Figure 19. Both the quaternion error (estimated truth) and angular velocity error converge close to zero.
From the PD+ controller, the desired torque is mapped to the desired thrust firings using bang-bang modulation ( Figure 20). Figure 21 shows the thruster firings required to maintain the attitude error close to zero.

Conclusion
This chapter has presented all the components required to create an attitude determination and control system for satellites in elliptical orbits. With this as basis, it is the hope by the author that the work can help in developing new results within attitude determination and control systems, ranging from nonlinear controllers to new understanding in orbital mechanics, attitude determination, new sensors, and new actuation methods and strategies.

Author details
Espen Oland Department of Electrical Engineering, UiT -The Arctic University of Norway, Narvik, Norway *Address all correspondence to: espen.oland@uit.no © 2018 The Author(s). Licensee IntechOpen. This chapter is distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/ by/3.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.