1.1.1 satellite dynamic model A rigid-body satellite is used in this application as the slave satellite. It is being symmetric about all three axes. Therefore, the equation of motioncan be obtained for the attitude of the satellite using the Euler's equation of motion for a rigid body as described in Eq.1. πππ‘ππ + ππ +ππ = πΌπΜ π/π + ππ/π × πΌππ/π , (1) whereI is the inertia matrix of the satellite, πS/N and πΜ S/N are the angular rate and the angular acceleration of the satellite respectively in reference to the inertial system. πππ‘ππ is the control torque applied to the satellite by actuator and ππ is the total disturbance. ππ is the linearized gravity gradient disturbance. The ππ/π × πΌππ/π component represents a gyroscopic terms between angular velocity vectors. The body coordinate system axes being the same as the main inertia axes, therefore, Eq.1 can be written in the scalar form: πΜ π/ππ₯ πΌπ₯ = ππ/ππ¦ ππ/ππ§ (πΌπ¦ − πΌπ§ ) + ππ₯ πΜ π/ππ¦ πΌπ¦ = ππ/ππ₯ ππ/ππ§ (πΌπ§ − πΌπ₯ ) + ππ¦ πΜ π/ππ§ πΌπ§ = π π π π (πΌπ₯ − πΌπ¦ ) + ππ§ . ππ₯ (2) ππ¦ Ix,Iyand Iz are the inertia of the satellite about the x, y and z-axis; and Tx , Ty and Tz are the total toques about three axes respectively. An angular momentum in the coordinates of the orbital coordinate system can be expressed as π΄π·πΆπ ππ/π β1 = ππ/π + (−π π π −π 0 1 ∅ ) (−ππ ) , 0 −∅ 1 (3) where ∅, π and πare the Euler angles for three channels and ADCM is the approximate result of the direction cosine matrix (DCM) for small angles(Vallado 2001, Jiro Funamoto 2012).ππ/π is the angular velocity of the reference attitude system and ππ is the rotational velocity of the satellite.The quadratic terms can be ignored since they are of a low order. By denoting each axis inππ/π as ππ₯ , ππ¦ , ππ§ respectively and by substituting Eq.3 into Eq.2, the linearized equation of motion can then be expressed as Eq.4 πΜ π₯ = −σ1 ππ2 π + (1 − σ1 )ππ ππ§ + πΜ π¦ = ππ₯ πΌπ₯ ππ¦ πΌπ¦ πΜ π§ = σ3 ππ2 π − (1 + σ3 )ππ ππ₯ + where π1 = πΌπ¦ −πΌπ§ πΌπ₯ ; π2 = πΌπ§ −πΌπ₯ πΌπ¦ ; π3 = πΌπ₯ −πΌπ¦ πΌπ§ ππ§ πΌπ§ (4) . Before continuing to build the state space model, we use Psiaki’s idea(Vallado 2001) to implement thelinearized gravity gradient disturbance. −π1 ∅ ππ = 3πΌππ2 ( π2 π ) 0 (5) From Eq.3toEq.4, the linear satellite dynamic model can be derived: π₯Μ = π΄π₯ + [ 03,3 ] πππ‘ππ πΌ −1 (6) where: 0 0 0 π΄ = −4π2 π π 1 0 [ 0 0 0 0 0 3ππ2 π2 0 0 0 0 0 0 2 ππ π3 1 0 0 0 0 −ππ (1 + π3 ) 0 0 1 0 0 1 0 ππ (1 − π1 ) ; 0 0 0 0 ] The state vector is given asx = (∅ π π πx πy πz)T. The inputs to the model have units in [Nm]. 1.1.2 Design your controller Google PID: Matlab auto tuning is not recommended as the numbers are for idea model, where Kp is too small to be applied to the actual physical systems 1.1.3 Discretize your controller After you have designed your control system, you then need to convert it into a form that is directly implementable in the source code. In practice there are numerous ways in which this can be achieved. Examples include the “Approximate” digital implementation, the z-domain method (We will consider this) and the canonical form method. In all of these techniques, the ultimate aim is to convert your continuous control law into discrete form since your source code is discrete based. In our case, we shall use the z-operator method. The z-operator method consists of a difference equation where the coefficients are determined by the z-operator equation that describes your controller. The difference equation (Shown on following page) is one that approximately simulates your control law and can be directly written into your source code. Difference Equation: y[n] = a0 x[n] + a1 x[n − 1] + a1 x[n − 2] + β― + b1 y[n − 1] + b2 y[n − 2] + b3 y[n − 1] + β― Where your controller represented in z-domain is: K(z) = a0 + a1 z −1 + a2 z −2 + β― 1 − b1 z −1 − b2 z −2 − β― In these equations, n is the current sample step, (n-1) is the previous sample step (n-2) is the second previous sample step etc. In your case, x would be yaw angle error and y is the PWM signal to be fed to the motors. There is a function called “c2d” on MATLAB that allows you to convert from s-domain to z-domain. It is recommended that you use a sampling time of 0.1 seconds, and use the ‘tustin’ method to evaluate your z-domain function. Make sure the sampling time in your source code matches that used to find your z-domain function. 1.1.4 Environmental models The environmental models can be modeled as disturbance in your Simulink model. 1) Solar pressure: The solar pressure will instantly jump to the highest value once the satellite comes out of the shadow of the earth and as soon as the satellite will reach the earth shadow again it will also vanish nearly instantly. This would be the worst case scenario for the controller. The force of the solar pressure is calculated with the following formula from (Vallado 2001, Jiro Funamoto 2012): πΉπππππ = ππ ππ π΄π ππ‘ (7) whereππ is the solar pressure,π΄π ππ‘ is the solar illuminated cross section area of the satellite andππ = 2 is the reflection coefficient. Then the moment of solar disturbance can then be presented as πΉ π π ππ π½ 90π ≤ π½ ≤ 270π ππππππ = { πππππ πππππ , 0 πππ π (8) whereπ½ is the angle of the latitude of the satellite, ππππππ is the torsion arm. The torque generated through the solar pressure normally just affects the attitude in the y-axis. However, if we have bigger attitude changes, with respect to the reference coordinate system, also the x-axis of the satellite might be affected. The z-axis is unaffected as long as the center of gravity is near the z-axis. 2) Aerodynamic drag The acceleration due to aerodynamic drag can be estimated as 1 2 πΉππππ = − 2 ππ· π΄π ππ‘ ππ£πππ πππππ = πΉππππ × πππππ (9) whereππ· is the coefficient of drag;π is the density of the air and vrel is the relative velocity of the air and πππππ is the torsion arm of aerodynamic drag.In this work, we assume both disturbances are constant in the simulation.