scieee AI-readable full text Open interactive document viewer

Attitude Measurement and Control Techniques on the Earth's Surface

Pretel Villanueva, Jorge

Abstract

Grupo de Electrónica Aeroespacial, GranaSAT

Full text

Trabajo Fin de Grado en F´ısica Attitude Measurement and Control Techniques on the Earth’s Surface Jorge Pretel Villanueva Universidad de Granada Julio de 2019 Universidad de Granada Abstract The following bachelor thesis introduces the basis of the attitude representation and measurement theory on Earth’s surface from inertial and magnetic measurement units data, as well as the use of sensor fusion algorithms as the optimal and complementary filters. Moreover, a review of the control system formalism is presented, where the stability and the reach of the controllers is analyzed, as well as two of the most used control techniques at the present time: the Proportional Integral Derivative controller and the Linear Quadratic Regulator. Finally, a study of the measurement and filtering methods on a real inverted pendulum with reaction wheel is conducted. Resumen En el presente trabajo se realiza una introducci´on a la teor´ıa de la medida de la orientaci´on en la superficie terrestre mediante el uso de sensores inerciales y magn´eticos con t´ecnicas de fusi´on de se˜nales, a trav´es del uso de filtros ´optimos y complementarios. A continuaci´on se hace una presentaci´on del formalismo de sistemas de control, en la cual se analiza la estabilidad y el alcance de dichos sistemas, as´ı como dos de los m´etodos de control m´as comunes, el controlador Proporcional Integral Derivativo y el Regulador Lineal Cuadr´atico. Por ´ultimo, se hace un estudio de la medida para un sistema real, el p´endulo invertido con volante de inercia. Agradecimientos Quiero expresar mi agradecimiento a todo el equipo de Granasat, por su ayuda incondicional y la alegr´ıa que han sabido transmitir cada d´ıa, incluso cuando m´as inmersos est´an en sus cables y sus osciloscopios. A Andr´es, mi tutor, por brindar a j´ovenes estudiantes la oportunidad de soltar el libro y, a golpe de martillo y con sangre y sudor, materializar lo que alg´un d´ıa s´olo fueron ideas. A toda mi familia, a los que han llegado y tambi´en a los que se fueron. En especial a mi madre, por su salmorejo, fuente de inspiraci´on y gozo en mis jornadas de trabajo. A los amigos con los que he terminado esta carrera, con los que tantos buenos y malos ratos he compartido. A la gente de Monachil. Al Marqu´es de Salda˜na: sin ´el el mundo ser´ıa un poco peor. En ´ultimo lugar, a Lasas. A todos y a ninguno, gracias. Contents 1 Introduction 5 2 Orientation representation 6 2.1 Euler angles .................................... 6 2.2 Quaternions .................................... 8 3 Orientation measurement 9 3.1 Measurement devices ............................... 9 3.1.1 Accelerometer ............................... 9 3.1.2 Magnetometer .............................. 10 3.1.3 Gyroscope ................................. 11 3.2 Sensor fusion ................................... 13 3.2.1 Kalman filter ............................... 15 3.2.2 Complementary filter .......................... 16 4 Control theory 17 4.1 Linear time-invariant systems .......................... 18 4.2 System representation .............................. 20 4.2.1 Ordinary differential equations ..................... 20 4.2.2 Laplace domain .............................. 20 4.2.3 Block diagrams .............................. 20 4.2.4 State space representation ........................ 21 4.3 Control analysis .................................. 22 4.3.1 Stability of linear systems ........................ 23 4.3.2 Observability ............................... 23 4.3.3 Controllability .............................. 24 4.3.4 Inverted pendulum ............................ 24 4.4 Controllers .................................... 26 4.4.1 PID controller .............................. 26 4.4.2 LQR controller .............................. 28 5 Inverted pendulum with reaction wheel 31 5.1 Sensor calibration and characterization ..................... 31 5.2 Orientation measurement ............................ 35 5.3 Discussion ..................................... 37 6 Conclusions and future work 38 References 39 5 1 INTRODUCTION 1 Introduction The study of attitude measurement and control has been indispensable for the developement of fields as aeronautical and aerospace engineering. Every satellite has incorporated systems that allow them to know their orientation respect to the Earth, the sun, or distant stars and galaxies in the case of astronomical satellites, as well as tools to control that orientation, like reaction wheels, gimballs, thrusters, magnetorquers, ect. Figure 1: Control moment gyroscope installed in the International Space Station [25] Before being sent into orbit, spacecrafts are tested on ground, generally by using test platforms with air bearing systems [7], which can be constructed in such a way that the center of mass of the suspended system is coincident with the center of rotation. This way, the effect of gravitational forces and torques is reduced considerably, simulating an almost perfect zero-gravity enviroment for testing and developement of spacecraft attitude control software. Other applications of orientation measurement and control theory include the developement of autonomous navigation systems and self balancing vehicles, among others. Figure 2: Test platform with air bearing designed by the Granasat team [21] At the beginning of this work, a brief overview of the mathematical representation of the attitude is provided, as well as the different transformation rules and temporal evolution of the representation elements. After that, the different inertial measurement sensors are introduced, and the relation between the measured data and the orientation of the system respect to a ground frame is determined. 2 ORIENTATION REPRESENTATION 6 In particular, sensor fusion algorithms will be introduced for the data analysis. Sensor fusion is the combination of data from different noisy or imprecise sensors that are measuring the value of certain magnitude, in order to obtain information that is more precise than that from the individual sources. This combination can be done by making use of statistical methods and optimal estimators like the Kalman filter [25], one of the most famous and widely used filters nowadays, or taking into account some characteristics of the noise from each individual sensor and trying to take advantage of the useful part of it’s data. In the case of orientation measurement, this filtering process leads to the reduction of noise from the accelerometer and magnetometer data, as well as the minimization of the characteristic bias errors that arise when gyroscope data is integrated. This constitutes a great improvement with respect to the non filtered values. Once the orientation data is known, it can be fed into a controller that is able to manipulate the state of a certain system, turning or moving it, by using passive or active actuators. There is a wide set of control approaches available and, depending on the particular system, different methods can be used. This work introduces the basics of such control systems from a theoretical and practical point of view. 2 Orientation representation The orientation of a body-fixed frame of reference respect to a laboratory or Earth-surface reference frame and it’s temporal evolution can be represented in many ways. (Note: vectors are written in bold letters to distinguish them from scalars.) 2.1 Euler angles According to Euer’s rotation theorem, any rotation in Rnspace can be described by a sequence of no more than nrotations around coordinate vectors, such that consecutive rotations are performed around distinct vectors. Those vectors are usually chosen to be the three basis vectors ˆ x,ˆ yand ˆ z(but could also be ˆ y,ˆ xand ˆ z, or ˆ x,ˆ zand ˆ xagain, etc). z yaw x roll pitch y Figure 3: Roll, pitch and yaw angles The angles of rotation around ˆ x,ˆ yand ˆ zare called roll (φ), pitch (θ) and yaw (ψ). 7 2 ORIENTATION REPRESENTATION The change of attitude around each axis can be defined by the following three rotation matrices [1].: Rx(φ) =   1 0 0 0c(φ)−s(φ) 0s(φ)c(φ) Ry(θ) =   c(θ) 0 s(θ) 0 1 0 −s(θ) 0 c(θ)  Rz(ψ) =   c(ψ)s(ψ) 0 −s(ψ)c(ψ) 0 0 0 1   (2.1) Where s(α) and c(α) represent the sine and cosine functions. The complete rotation after the consecutive individual rotations (2.1) is given by it’s product: R(φ, θ, ψ) =   c(θ)c(ψ)s(φ)c(ψ)−c(θ)s(ψ)c(φ)s(θ)c(ψ) + s(φ)s(ψ) c(θ)s(ψ)s(φ)s(θ)s(ψ) + c(φ)c(ψ)c(φ)s(θ)s(ψ)−s(φ)s(ψ) −s(θ)s(φ)c(θ)c(φ)c(θ)  (2.2) This transformation R∈SO (3) has the following properties: R−1=RTRRT=RTR=I3×3(2.3) that is, the inverse rotation transformation is described by the transpose of R:R(−φ, −θ, −ψ) = RT(φ, θ, ψ). k j g g ib jb kb ig Figure 4: Ground and body frames In general, a rotation matrix that defines the orientation of a body-fixed reference frame respect to a laboratory (ground) frame can be constructed as the projection of each one of the basis vectors ˆ ib,ˆ jband ˆ kbof the body frame onto each basis vector ˆ ig,ˆ jgand ˆ kgof the ground frame: RBG =   ˆ ig·ˆ ibˆ jg·ˆ ibˆ kg·ˆ ib ˆ ig·ˆ jbˆ jg·ˆ jbˆ kg·ˆ jb ˆ ig·ˆ kbˆ jg·ˆ kbˆ kg·ˆ kb   (2.4) 2 ORIENTATION REPRESENTATION 8 This matrix is called the direction cosine matrix (DCM), as the scalar product of each pair of unitary basis vectors is the cosine of the angle between both. This matrix is equivalent to (2.2). A vector vbexpressed in the body reference frame can be expressed in the ground frame as: vg=RBGvb(2.5) and from ground frame to body frame: vb=RGBvg, RBGRGB =I3×3(2.6) 2.2 Quaternions Quaternions are an extension to complex numbers with one real and three imaginary parts [10]: q=s+iq1+jq2+kq3(2.7) with i2=j2=k2=ijk =−1. They are usually represented in form of a 4-dimensional vector: q= (s, v) (2.8) with v= (q1, q2, q3). Since only 3 values are required to fully describe a 3D rotation, the use of quaternions in the orientation description is limited to unitary vectors: |q|=qs2+q2 1+q2 2+q2 3= 1 (2.9) A rotation by an angle αaround an unit vector vis represented in quaternion notation as: qα,v=cosα 2,vsinα 2(2.10) so the first component represents the magnitude of the rotation and the last three correspond with the rotation direction. a v Figure 5: Quaternion representation of a rotation The conjugate of an unit quaternion is: q∗(α, v) = q(α, −v) (2.11) 9 3 ORIENTATION MEASUREMENT Similarly to Euler angles case, a rotation matrix can be obtained for a given quaternion: Rq=  1−2q2 2−2q2 32q1q2+ 2sq32q1q3−2sq2 2q1q2+ 2sq31−2q2 1−2q2 32q2q3−2sq1 2q1q3−2sq22q2q3−2sq11−2q2 1−2q2 2  (2.12) The composition (◦) of two rotations qaand qbis given by the quaternion product: qa◦qb= (sa,va)◦(sb,vb)=(sasb−vavb, savb+vasb+va×vb) (2.13) In general, the composition of quaternions does not commute. An important thing to take into account when computing quaternions is that any precision error (floating error) can lead to not normalized results which don’t represent proper rotations, so algorithms must implement a constant normalization process. Conversion from quaternion notation to Euler angles can be done as:            φ=atan 2sq1+q2q3 1−2(q2 1+q2 2) θ=asin (2 (sq2−q3q1)) ψ=atan 2sq3+q1q2 1−2(q2 2+q2 3) (2.14) Each representation has some advantages and some drawbacks. The use of Euler angles is more intuitive and all the information is contemplated in only 3 values, but it suffers from a problem called gimbal lock whereby the system loses a degree of freedom for certain continuous rotations. They are also more ambiguous than quaternions in the sense that Euler angles can be defined for different sets of axes. Quaternions are less intuitive but they get rid of the gimbal lock problem and the computational cost associated to it’s use is smaller. 3 Orientation measurement 3.1 Measurement devices In order to obtain information relative to the orientation of a body, we have to be able to measure certain magnitudes whose directions are known to us in a ground-fixed frame. In Earth’s surface, those magnitudes are the Earth’s gravity and magnetic field vectors. In other enviroments like the outer space, further methods like star tracking systems can be applied. In any case, the following formalism can be applied for any orientation measurement problem in general. 3.1.1 Accelerometer In a static situation, an accelerometer measurement provides a constant actualization of the gravity vector’s direction. When the body is subjected to other accelerations, if a model of the body’s motion is available, some corrections can be made in order to separate the gravitational from the rest of the dynamical accelerations. Sometimes those accelerations are small compared to gravity and can therefore be neglected. Even when the accelerations 3 ORIENTATION MEASUREMENT 16 x− k=Axk−1+Buk−1(3.32) as well as the estimate error covariance matrix, which represents the prediction of the error associated to the predicted state x− k: P− k=EekeT k=APk−1AT+Q(3.33) 1. Correction phase: a new measurement of the state is made (3.31), and the a posteriori predicted state is computed as a linear combination of both the predicted and the measured values: xk=x− k+Kkyk−Hx− k(3.34) which bears resemblance to the monodimensional case (3.24). Here, the weighting parameter is given by the matrix K, known as the Kalman gain. As in (3.24), it represents the gain that minimizes the error covariance matrix: Kk=P− kHT HP− kHT+R(3.35) If the measurement error covariance Ris small, the value of the a posteriori predicted state stays closer to the measurement. If P− kis smaller, then the a posteriori predicted state approaches more to the a priori prediction. Finally, the a posteriori estimate error covariance matrix Pis computed: Pk= (I−KkH)P− k(3.36) The next iteration, the a posteriori predicted state xkbecomes the new previous state xk−1, and matrix Pkbecomes the new previous Pk−1. 3.2.2 Complementary filter A much simpler version of a linear estimator (3.24) is the complementary filter. When an angle is measured by integrating the gyroscope signal over time (3.19), the integration of the measurement errors along with the error intrinsic to the discretizacion in digital signals produces a bias that grows over time and causes the measure to deviate from the real value in the long term. On the other hand, the accelerometer provides a unbiased measurement of the orientation that is accurate over long periods of time, but the signal is submited to a large amount of noise. We can say then that the accelerometer signal is more valuable at low frequencies and the gyroscope data has more desirable properties at low frequencies. 17 4 CONTROL THEORY 18 19 20 21 22 23 24 25 Time (seconds) -10 -5 0 Angle (deg) Acc Gyro Figure 10: Example of gyroscope and accelerometer signals in angle measurement The complementary filter exploits this frequency features by adding the pass-filtered data from each sensor: a low pass filter reduces the high frequency noise from the accelerometer, and a high pass filter minimizes the effect of the bias of the gyroscope measurement, so from the addition of both filtered data we can a measurement that is useful and reliable in the entire frequency spectrum. The complementary high and low pass filters in the Laplace domain are given by [23]: Glow (s) = α 1 + αs Ghigh (s)=1−Glow (s) (3.37) The measured angle in the Laplace domain θ(s) is computed as the sum of the filtered measurements from the accelerometer, θacc(s), and from the gyroscope, θgyro(s): θ(s) = Glow (s)θgyro(s) + (1 −Glow (s)) θacc(s) (3.38) performing the inverse Laplace transform to express the function in time domain and discretizing [6]: θk=αθgyro,k + (1 −α)θacc,k =α(θk−1+4tωk−1) + (1 −α)θacc,k (3.39) with α=τ τ+4t(3.40) where τis the time constant of the filter. 4 Control theory The control theory, as it’s name indicates, is based on the study of the control of the dynamic state of a given system (also called plant) through the action of elements which are capable of modifying it’s behavior, as well as the analysis of the stability and the reach of such control. These elements are called actuators, and they’re operated by an element called controller. In order to control a system, an aim state or setpoint is defined, that is, a specific set of values for the state variables that we want our system to reach. 4 CONTROL THEORY 18 From the difference between the current state and the aim state an error is defined, and from this error signal and through the use of a particular control law, the controller decides how the actuators will operate. This kind of control in which there is a feedback from the state is called closed loop control. In the case of attitude control on Earth’s surface, the feedback will come from the signal of the different inertial measurement sensors attached to the body, which provide a constant uptate of the state of the system. 4.1 Linear time-invariant systems Although the vast majority of physical systems present inherent nonlinear characteristics, they can be approximately described by a linear approximation in the neighbourhood of an equilibrium point by performing a first order Taylor expansion of the dynamic functions. The reason behind this linearization is the amount of vastly simpler methods for studying control and it’s stability compared to the nonlinear case. In particular, for linear systems the total reaction y(t) to a set of inputs/actions fi(ti) (for example, a voltage step function applied to a circuit, or a certain amount of impulse generated by a thruster in a spacecraft) is the sum of the individual responses for every input. This property is known as superposition. The impulse response of a system, h(t), is defined as the output of the system corresponding to a delta function input f(t) = δ(t) for zero-boundary conditions. Because of linearity, the response of the system is [14]: y(t) = t ˆ 0 f(τ)h(t−τ)dτ (4.1) This equation is known as the convolution integral, also represented by the convolution operator y(t)=(u∗h)(t). The idea behind this comes from expressing any input f(t) as a set of nscaled and time-shifted delta impulses, and bringing the expression to the continuum limit (n→ ∞). To visualize this superposition feature, we take as an exaple a simple mass-spring- damper model with an input force, described by the linear differential equation m¨y(t) + b˙y(t) + ky(t) = u(t). The impulse response to a delta function at t= 0, f(t) = cδ(t), is in this case equal to a instant change in the momentum of the system m˙y(0+) = c. The solution to the differential equation reads: h(t) = e−b 2mtsin(ω0t)ω0=sk m−b 2m2 (4.2) If the system is subjected to an input force f(t) = sin(10t), t ∈0,π ω0, we can approximate it by a set of nscaled and time-shifted delta impulses. Here, these inpulses could be intuitively seen as “knocks” of a very short duration that change the momentum of the mass instantaneously. 19 4 CONTROL THEORY 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Time (seconds) -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 Amplitude (m) 0 0.2 0.4 0.6 0.8 1 Time (seconds) 0 0.2 0.4 0.6 0.8 1 Force (N) Figure 11: Impulse function h(t) for the mass-spring system and input function f(t) As nbecomes larger, the sum of the individual responses becomes closer to the real response. 0 0.05 0.1 0.15 0.2 0.25 0.3 Time (seconds) 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Force (N) 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Time (seconds) -0.02 0 0.02 0.04 0.06 0.08 Amplitude (m) Added response Real response Figure 12: Delta inpulse approximation for n= 5 and added response compared to real 0 0.05 0.1 0.15 0.2 0.25 0.3 Time (seconds) 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Force (N) 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Time (seconds) -0.02 0 0.02 0.04 0.06 0.08 Amplitude (m) Added response Real response Figure 13: Delta inpulse approximation for n= 14 and added response compared to real When ntends to infinity, the sum of every individual response becomes the convolution of f(t) and h(t). In this property lies the simplicity and potential of linear time-invariant systems (LTI ): the behavior of the system as response to any perturbation or control force is completely determined by a function h(t). 4 CONTROL THEORY 20 4.2 System representation 4.2.1 Ordinary differential equations As in the mass-spring example, the physical description of linear systems is generally represented by a set of ordinary differential equations that determine the temporal evolution of the generalized coordinates of the system: xi(t) = X n an,i(t)x(n) i+X n bn,i(t)u(n) i(4.3) where xirepresents the value of the generalized coordinates that define the state of the system, and uirepresent the variables that define an external action or force from the actuators. In a complete description, the number of equations is equal to the number of degrees of freedom of the system. 4.2.2 Laplace domain A system that responds to a certain signal or input can be seen as a black box that transforms in a specific way the incoming input into another output signal. In case of a LTI system, this transformation is completely described by it’s impulse function h(t). The Laplace transform of h(t) is called transfer function, H(s), and it represents the relation between output (Y) and input (U) in the Laplace domain. In it’s more general form [13]: Y(s) = H(s)U(s) (4.4) and as in the case of h(t), it completely defines the behavior of the system. The advantage of working in the Laplace domain is that the response of a number of connected interacting systems to an initial signal is computed as simply the product of the individual transfer functions times the signal, whereas in time domain this response comes from the convolution (4.1), which can be more arduous to perform. The transfer function representation also allows us to obtain a large number of characteristics of the system’s dynamics in a relatively easy way. The transfer function of a system is usually denoted with capital letters. 4.2.3 Block diagrams In engineering fields, another typical way of describing a system is through block diagrams, which visually display the different parts of the system and their connections, representing them by their particular transfer functions. (here the term signal may not strictly refer to an electric signal, but to any output of an element that generates a reaction on another) H(s) Figure 14: System component represented by a block with associated transfer function H(s) 21 4 CONTROL THEORY The case shown below is the most general case of closed loop system: a controller connected to a plant, and a feedback signal that is substracted to a reference signal to determine the error that is then sent into the controller. C(s) P(s) u(s) e(s) y(s) + - r(s) sensor Figure 15: Block diagram for closed loop system The transfer function for a closed loop system can be obtained by noticing the following relations: E(s) = R(s)−Y(s) Y(s) = P(s)C(s)E(s)(4.5) Subtituing the first equation into the second we get the closed loop transfer function: Hcl(s) = Y(s) R(s)=C(s)P(s) 1 + C(s)P(s)(4.6) 4.2.4 State space representation The evolution of the state variables can be expressed in form of matrix equations [11]: ˙ x(t) = Ax(t) + Bu(t) y(t) = Cx(t) + Du(t)(4.7) where x(t) is the state vector, which comprises the variables that define the state of the system at a certain time t,y(t) is the output vector, and u(t) is the input vector from the controller signal. The matrix Ais called state matrix, and it determines how the current state affects the variation of the state variables, and Bis the control matrix, which describes how the input affects these variables. Cand D, known as output and feed-forward matrices, define the output vector in terms of the current state. Intuitively, Cdetermines the portion of the system variables that can be observed. For closed loop systems, and in particular when the state feedback is constant, ucan be expressed as a function of x. In general we have: u(t) = Kx(t) (4.8) where Kis known as closed loop feedback matrix or gain matrix. To change from state space representation to Laplace domain representation, we perform the Laplace transform to the state equations (4.7): 4 CONTROL THEORY 22 sx(s) = Ax(s) + Bu(s)→(sI −A)x(s) = Bu(s) y(s) = Cx(s) + Du(s)(4.9) then multiplying both sides of the first by (sI −A)−1and subtituing in the second: y(s) = hC(sI −A)−1B+Diu(s) (4.10) where H(s) = hC(sI −A)−1B+Diis equal to the transfer function of the system. 4.3 Control analysis The solution to the set of differential equations that appear in the State Space description (4.8) can be divided in two separate terms: an homogeneous solution xhfor zero input that describes the response of the system to some initial conditions x0, and a particular solution xpthat corresponds with nonzero input and zero boundary conditions. The solution to the homogeneous equation x0(t) = Ax(t) has an exponential form: xh(t) = eAtx(0) (4.11) where the square matrix exponential is computed as the usual power series expansion: eAt =∞ X n=0 (At)n n!=I+At +A2t2 2! +A3t3 3! +... (4.12) The matrix Φ=eAt is called the state transition matrix of the system. It presents the following properties [24]:  Φ(0) = I  Φ(−t)=Φ−1(t)  Φ(t1)Φ(t2) = Φ(t1+t2) The particular solution is obtained by multiplying both sides of the first equation in (4.7) by e−At and integrating: t ˆ 0e−Atx0(t)−e−AtAx(t)= t ˆ 0d dt e−Atx(t)= t ˆ 0 e−AtBu(t) (4.13) rearranging the terms: x(t) = eAtx(0) + t ˆ 0 eA(t−τ)Bu(t) (4.14) where the first term on the right is the homogeneous solution xh(t), also called zero input response, and the second is the convolution integral, also known as the zero state response of the system. 23 4 CONTROL THEORY 4.3.1 Stability of linear systems In general, a linear system is said to be stable if the state vector doesn’t diverge as time goes to infinity. In particular, a system is asymptotically stable if the state variables tend to 0 [22] : lim t→∞xi(t) = 0 (4.15) and marginally stable if the state remains bounded: sup t≥0kxi(t)k< ki(4.16) Given a transfer function H(s) = Pn i=0 bnsn Pm i=0 amsm(4.17) the function can be expanded into a sum of partial fractions: H(s) = n X i=0 ri s−pi (4.18) where piand riare called the poles and the residues of the transfer function respectively. By performing the inverse Laplace transform we get the system impulse response: L−1(H(s)) = h(t) = n X i=0 riepit(4.19) We can see that if the real part of a pole is positive, then the response of the system diverges to infinity with time. This fact implies the following property: the system is asypmtotically stable if and only if all poles of the transfer function have a negative real part. If the real part of a pole is zero, then the system is marginally stable. From (4.10) it can be proved that the poles of the transfer function and the eigenvalues of the state matrix Acoincide, so the same criterion can be applied for the real part of the eigenvalues. 4.3.2 Observability A system is said to be observable if the system state x(t) can be known from the input u(t) and output y(t) vectors at a given time tand the initial state x(t0). A system is observable if and only if the observability matrix O(A, C) has rank n, equal to the dimension of A[20]: O=CCA CA2··· CAn−1T(4.20) This ensures that we can obtain an independent system of equations that determines each value of x(t). 4 CONTROL THEORY 24 4.3.3 Controllability A system is said to be controllable if for any given time t, and any given initial and final states x(t0) and x(t), there is some input u(t) that can take the state from x(t0) to x(t). A sufficient condition for controllability is that the controllability matrix Q(A, B) has rank n: Q=BAB A2B··· An−1BT(4.21) 4.3.4 Inverted pendulum The inverted pendulum is a very useful system when it comes to studying attitude control and control systems in general. On one hand, it represents the archetypal model of a system that is subjected to forces or torques that tend to unstabilize it (balancing problem). On the other hand, because it’s an observable system, the stability can be achieved by using a wide set of possible control approaches, which will be later discussed in more detail. The simplest version of an inverted pendulum consists of a body attached to a pivot, with a constant distance between the body’s center of mass and the pivot. It’s (called) inverted because the center of mass is above the rotation point of the system. The system in this first approximation is assumed to be frictionless. l q m Figure 16: Inverted pendulum We also assume that the center of gravity coincides with the center of the mass. The torque produced by the gravity is τ=mlgsinθ, with the associated differential equation ¨ θ+g lsinθ = 0. To linearize the equation, we perform the first order Taylor expansion of the sine function around the top equilibrium point ¨ θ−g lθ= 0 (4.22) Expressed in state space representation and taking θand ˙ θas state variables: dx dt =˙ θ ¨ θ=0 1 g l0 θ ˙ θ y=1 0 x (4.23) The eigenvalues of the state matrix are λ1=√g land λ2=−√g l, and therefore the point is unstable and the body tends to fall when it’s at the top, as expected. 25 4 CONTROL THEORY In order to stabilize the system, we define as error the difference between the current angle of the pendulum and the top position, in our case equal to θ. The goal of this control will then be to bring the state as close as possible to the top equilibrium point θ=˙ θ= 0. First, the functional dependence between an external torque τext that will control the pendulum and the error has to be set, that is, a control law has to be defined. Given that the gravitational torque increases with θ, we can assume a proportional dependence with θas a first ansatz [19]: ¨ θ−g lθ=τext =αθ (4.24) In the state space representation, this feedback can be expressed as: u(t) = Kx(t) = α0x(t) (4.25) The state space equations then read: ˙ x=˙ θ ¨ θ=0 1 g l0 θ ˙ θ+0 1α0θ ˙ θ=0 1 g l+α0 θ ˙ θ y=1 0 θ ˙ θ(4.26) For constant gain closed loop, the state matrix becomes Acl =A+BK, and the system equation can be treated as for the open loop control case , ˙ x=Aclx. In this case, the eigenvalues of the state matrix can either be a positive-negative pair or a pure imaginary pair. In the first case the system response diverges, and in the second the imaginary pair creates a constant oscillatory response (4.19). Therefore the control law (4.25) is not useful. -1 -0.5 0 0.5 1 θ (rad) -1 -0.5 0 0.5 1 dθ/dt (rad/s) -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 θ (rad) -1 -0.5 0 0.5 dθ/dt (rad/s) Figure 17: Phase portraits of the system for divergent and constant responses This divergence of the dynamic variables corresponds to the linearized equations; in the real inverted pendulum system, the divergence is translated into a proggresive shift away from the top unstable equilibrium position towards the lower stable point. As a second attempt, we can introduce in the feedback a negative dependence with ˙ θ: ¨ θ−g lθ=τext =αθ −β˙ θ(4.27) The characteristic equation then reads: 5 INVERTED PENDULUM WITH REACTION WHEEL 32 0 10 20 30 40 50 60 70 Time (seconds) -4 -3 -2 -1 0 Angular velocity (deg/s) -2.5 -2 -1.5 -1 Gyro measurement (deg/s) 0 200 400 600 800 Frequency Figure 21: Gyroscope static measurements and value histogram The gyroscope noise can be well approximated by a normal probability density distribution with variance σ2 gyro = 0.1166. To obtain the scaling error, a rotation of 90 ° is performed on the system and the angle is integrated. The value obtained from the measurement is 91.5 ° , so ∆scal =91.5 90 = 1.0167.x 0 10 20 30 40 50 60 Time (seconds) -50 0 50 100 150 Angle (degrees) Reference Calibrated Non-calibrated Figure 22: Orientation measurement from gyroscope before and after calibration compared to reference A quick method for calibrating the accelerometer is to use the orthogonality property of the axes to determine the maximum gravity output value for each individual axis. This is done by slowly rotating the sensor in a way that the measured acceleration in two of the axes becomes zero at some point, in which the third axis displays the absolute value of the gravitational acceleration. Figure 23: Acceleration measurement during rotation. The Yaxis reaches it’s maximum value at the junction point 33 5 INVERTED PENDULUM WITH REACTION WHEEL Acc 1 Positive (m/s2) Negative (m/s2) Zero state error (m/s2) Scaling error X axis 9.60 -10.31 -0.35 1.02 Y axis 10.06 -10.15 -0.05 1.03 Z axis 10.00 -10.37 -0.19 1.04 Table 1: Maximum values of acceleration, zero-state bias and scaling error for accelerometer 1 Acc 2 Positive (m/s2) Negative (m/s2) Zero state error (m/s2) Scaling error X axis 9.96 -10.25 -0.16 1.04 Y axis 9.80 -10.06 -0.13 1.01 Z axis 9.65 -9.92 -0.14 9.99 Table 2: Maximum values of acceleration, zero-state bias and scaling error for accelerometer 2 The noise asociated with the accelerometer’s angle measurement (and with accelerometers in general) is not constant; it presents a dependence with the motion of the system and becomes higher as the magnitude of the accelerations grow. To model the acceleration noise, a set of different measurements is made. For each measurement, the system is subjected to an oscillatory movement with different frequency for a certain period of time. The higher the frequency is, the faster the system oscillates and therefore the larger the noise becomes. The noise error is computed as the diference between the angle from the accelerometer measurement (5.5) minus the angle obtained by filtering the data with a complementary filter. Then this noise is associated to the squared average of the gyroscope signal’s rate of change, a measure of the sharpness of the motion. ¯α2=1 n2 n X k=1 ωk+1 −ωk 4t2 (5.2) 5 INVERTED PENDULUM WITH REACTION WHEEL 34 0 1 2 3 4 5 6 7 Time (seconds) -30 -20 -10 0 10 20 30 Angle (deg) Acc filter error -6 -4 -2 0 2 4 6 Error (deg) 0 20 40 60 80 Frequency Figure 24: Accelerometer measurement error for smooth motion and error histogram. The yellow line represents the difference between accelerometer and filter data. 0 1 2 3 4 5 6 7 Time (seconds) -40 -20 0 20 40 60 Angle (deg) Acc filter error -10 -5 0 5 10 15 Error (deg) 0 20 40 60 80 Frequency Figure 25: Accelerometer measurement error for sharp motion and error histogram 0 100 200 300 400 500 600 700 α2(deg 2/s4) 0 20 40 60 Noise variance (deg 2) Figure 26: Relation between noise variance and sharpness parameter The relation between the variance σ2 acc and ¯α2is given by: σ2 acc ≈0.078¯α2+ 0.1442 (5.3) 35 5 INVERTED PENDULUM WITH REACTION WHEEL 5.2 Orientation measurement In order to decouple the gravity part of the acceleration measurement from other dynamical terms [23], in this case the centripetal acceleration caused by the rotation motion, the two IMUs are placed at a different distance from the rotating point. q d1 d2 z x Figure 27: Accelerometers configuration scheme If the distances are d1and d2, the accelerometer measurement vectors (xand zaxes) read: an= (an,1, an,1) = dn¨ θ+gsinθ, −˙ θ2dn−gcosθ(5.4) Cancelling the terms of order higher than 2 from the two vectors a1and a2, we can compute the angle (3.4): θ=atan2a1,1−µa2,1 −a1,2−µa2,2(5.5) where µ=d1 d2= 4.17. To make sure that the gravity vectors measured by both accelerometers are indeed parallel, first a measurement of the gravity vector is performed for both sensors. Then, the angle between both is computed and one measurement vector is multiplied by the convenient rotation matrix. Then, a signal fusion is performed between both accelerometers and a gyroscope to minimize the noise and the bias. A state vector is defined for the Kalman filter; a common approach is to chose as variables the angle θand the gyroscope bias b[6]: xk=θk bk(5.6) The last one is not observable, so the output matrix presents only one nonzero term: H= (1,0) (5.7) During the observation phase, the previous state is propagated using the gyroscope data to obtain an a priori estimate (3.28) of the current state: 5 INVERTED PENDULUM WITH REACTION WHEEL 36 x− k=θ− k b− k=1−4t 0 1  θk−1 bk−1+4t 0ωk(5.8) The measurement noise covariance matrix Rin this case is given by the variance of the accelerometer’s angle measurement noise. Finally, for the determination of the process noise covariance matrix Q, we can assume that the error associated with the prediction is proportional to the sampling period (the longer the time between the measurements, the more the noise can affect the variables) and to the gyroscope noise variance previously computed: Q=4tσgyro 0 04tσgyro (5.9) The complementary filter is tuned by trial and error. The final value for the gain constant cis 0.97. That means that the 97% of the measurement value comes from the gyroscope data. 0 5 10 15 20 25 Time (seconds) -40 -20 0 20 40 Angle (deg) Acc Gyro Comp Kal 14.5 15 15.5 16 Time (seconds) -20 0 20 40 Angle (deg) Acc Gyro Comp Kal 25 25.5 26 26.5 27 27.5 Time (seconds) -10 -5 0 5 10 Angle (deg) Acc Gyro Comp Kal Figure 28: Angle measurement by accelerometer, gyroscope, complementary filter and Kalman filter 37 5 INVERTED PENDULUM WITH REACTION WHEEL 5.3 Discussion From figure (28) we can see that the accelerometer pair presents a small amplitude noise when the body remains fixed, but this noise gets larger when the system moves abruptly, to the point that the angle obtained by it’s measurement reaches twice the value from the gyroscope. This is due, as it’s shown in (5.3), to the fact that accelerometers become unstable when the accelerations vary rapidly in time. Nevertheless, the two parallel accelerometers system is fully able to decouple the signal correspondant to the gravity vector and the rest of accelerations. The effect of the bias in the gyroscope measurement is also noticeable. After 25 seconds, the difference between the real angle and the biased is of 2.5 ° even when the gyroscope has been previously calibrated. Even though this bias doesn’t seem disproportionate, it’s effect in the long term may become large. The running time for each filtering algorithm is shown in the following figure: Complementary Kalman 0 5 10 15 20 25 30 Running time (ms) Figure 29: Running times for Kalman and complementary filters The Kalman filter algorithm takes 3.24 times more time to run than the complementary filter. The signals from the Kalman and complementary filters stay practically the same, but the complementary filter signal seems to differ slightly in the oscillating period. Lastly, a small phase shift arises in both filtered signals, which could be overcome by using a faster microcontroller. 6 CONCLUSIONS AND FUTURE WORK 38 6 Conclusions and future work The performance of the Kalman filter and the complementary filter are very similar in the studied case. This is due to the fact that the gyroscope itself provides a very accurate value of the orientation, so the data is provided mostly from it in both cases. The accelerometers only correct the bias in the long term, but don’t affect much the instantaneous measurement of the device. Given that the running time of the complementary filter is more than three times lower, it’s use could be more appropiate for simple applications like the one studied here. Also, even though the Kalman filter is optimal, it’s optimallity depends completely on knowing the right value of the elements of each covariance matrix, which can be difficult to get in some occasions. Because of this, Kalman filter will be more useful for systems that present more complexity, and where a higher degree of accuracy is needed, or where the system parameters change with time and the weights must be adjusted. We have a similar situation for the controllers. The PID controller is very easy to implement, as only 3 parameters need to be tuned to configurate the whole control. This simplicity makes of the PID a good option when the system’s behavior is not precisely known and trial and error methods could be used for the adjustement of the parameters, even when there is any analytical model available. On the other hand, the LQR control is much more complex when it comes to the tuning process; not only a bigger set of parameters have to be defined, but also the dynamics of the system have to be determined (a model has to be available). Another consequence of the state-feedback nature of the LQR is that the system has to be observable (otherwise the dynamics of some variable could not affect the cost function). Nevertheless, the LQR method allows us to perform a more complete and optimized control, not only of the different state variables but also of the energy/resources consumption of the system. It also can manage a bigger set of inputs/outputs, whereas the classical PID controller is designed to control a single error parameter (although further improvements can be done). The next step in this study will be to finish the inverted pendulum prototype and test the control algorithms. By measuring features like the settling time or the overshot of the system, we can have a good idea of which control approach is more convinient for a given system, as well as the real difficulties that can arise in the implementation and tuning processes. 39 REFERENCES References [1] H. Goldstein, C. Poole and J. Safko. Classical mechanics. Adison Wesley, 2002. [2] A. Zisserman. Lectures on Estimators. Oxford University, 2007. [3] Y. Pei, S. Biswas, D. Fussell, K. Pingali. An elementary introduction to Kalman Filtering. CoRR,2017. [4] G. Welch, G. Bishop. An introduction to the Kalman Filter. Proc. Siggraph Course, 2006. [5] M. Kok, J. Hol, T. Sch¨on. Using inertial sensors for position and orientation estimation. Foundation and Trends of Signal Processing, 2017. [6] P. Gui, L. Tang, S. Mukhopadhyay. MEMS based IMU for tilting measurement: comparison of complementary and kalman filter based data fusion. Proceedings of the 10th IEEE Conference on Industrial Electronics and Applications, 2015. [7] J. Schwarz, M. Peck, C. Hall. Historical review of Air-Bearing spacecraft simulators. Journal of Guidance, Control and Dynamics, 2003. [8] E. Kalman, Rudolph & others. A new approach to linear filtering and prediction problems. Journal of basic Engineering, 1960. [9] R. Bieda, J. Krzysztof. Determining of an object orientation in 3D space using direction cosine matrix and non-stationary Kalman filter. Archives of Control Sciences, 2016. [10] M. Blanke, M. Larsen. Satellite Dynamics and control in a Quaternion Formulation (2nd edition). Technical University of Denmark, Departament of Electrical Engineering, 2010. [11] H. Werner. Control Systems Theory and Design, 2019. [12] Wikibooks. Control Systems. 2019. https://en.wikibooks.org/w/index.php?title=Control Systems&oldid=3482645. [13] R. Jurgen. Standard Handbook of Electronic Engineering, Fifth Edition. Mc Graw Hill. 2005. [14] C. Graham, S, Goodwin, M. Salgado. Control System Design. Valpara´ıso, 2000. [15] I. Rosu. The Bellman Principle of Optimallity. 2002. https://pdfs.semanticscholar.org/bc80/746fb737a4de056e4a49515829bd07fd00b3.pdf [16] I. Manchester. Guidance, Navigation and Control. Course notes, University of Sydney, 2013. [17] P. Maybeck. Stochastic Models, Estimation and Control. Academic Press Inc, 1999. [18] M. Gajamohan, M. Merz, I. Thommen, R. D’Andrea. The Cubli: a cube that can jump up and balance. IEE/RJS International Conference on Intelligent Robots and Systems, 2012. REFERENCES 40 [19] E. D. Sontag. Mathematical Control Theory: Deterministic Finite-Dimensional Systems. Springer-Verlag New York, 1998. [20] J. Bellon. Riccati Equations in Optimal Control Theory. 2008. [21] Granasat Electronics Aerospace Group website. https://granasat.ugr.es/ [22] E. W. Kamen. The poles and zeros of a linear time-varying system: Linear Algebra and it’s Applications, volume 98, 1988. [23] N. S. Nise. Control Systems Engineering. Wiley, 2010. [24] S. Shinners. Modern Control System Theory and Design. Wiley, 1998. [25] International Space Station website. https://www.nasa.gov/mission pages/station/main/index.html