# Design and Implementation of Model Predictive Control for a Gyroscopic Inverted Pendulum
## 2 Dynamic System Modeling  
The gyroscopic inverted pendulum uses the principle of the gyroscopic effect of a spinning disk as shown in Figure 1. A disk with mass moment of initial \(\mathbf{I}\) rotates about its z axis at a speed of \(\dot{\phi}\). When its precession angle changes at the rate of \(\stackrel{{\rightarrow}}{{\dot{\alpha}}}\), a torque is generated along its x axis with a magnitude and its direction is determined by:  
\[\stackrel{{\rightarrow}}{{T}}=-\stackrel{{ \rightarrow}}{{\dot{\alpha}}}\times\mathbf{I}\dot{\phi}. \tag{1}\]  
At a precession angle \(\alpha\), the effective torques of the gyroscope effect on the horizontal and vertical axes are, respectively,  
\[T_{H}=-\dot{\alpha}\mathbf{I}\dot{\phi}\cos\alpha, \tag{2}\]  
\[T_{V}=-\dot{\alpha}\mathbf{I}\dot{\phi}\sin\alpha, \tag{3}\]  
where \(T_{H}\) is used to stabilize the vehicle system in the roll motion and \(T_{V}\) is an unwanted torque since it causes some uncontrolled effects on the yaw motion of the vehicle. By using two flywheels rotating in opposite directions at the same speed, the torque on the vertical axis of a flywheel will cancel out that of the other one. Since the magnitude of \(T_{H}\) depends on the cosine of the precession angle \(\alpha\), the precession angle should be kept as small as possible in order to generate a larger effective toque on the horizontal axis. At a precession angle of \(\pm 90^{\circ}\), the effective torque on the horizontal axis is zero.  
Figure 1: The design principle: (**a**) The gyroscopic effect of a spinning disk; (**b**) The effective torques of the gyroscopic effect on the horizontal and vertical axes.  
When designing control strategies to stabilize a single-track vehicle, an inverted pendulum-like bicycle model (as shown in Figure 2) is obtained by assuming that the bicycle tires are knife-edge rolling disks with point contacts on a flat road surface, that there is no longitudinal or lateral slip at the contact points, and that the bicycle steering is fixed at a constant angle. In this figure, \(\Gamma_{o}\) is an inertial coordinate system of Society of Automotive Engineers (SAE) standard, \(m\) is the total mass of the system, \(h_{c}\) is the height of the centre of mass, \(g\) is the gravitational acceleration, \(r\) is radius of the circular path, \(v\) is the longitudinal speed of the bicycle, \(F_{c}\) is the centrifugal force, \(N\) is the normal reaction force of the ground to the bicycle tires, \(F_{f}\) is the friction force between the tires and the road surface at the contact points, and \(\theta\) is the roll angle of the bicycle. In order to evaluate the performance of both the designs and the control strategies, a nonlinear inverted pendulum model is developed in the next section.  
In this study, the design of the gyroscopic inverted pendulum includes two spinning flywheels attached to gimbal frames, four electric motors, and level gears as shown in Figure 3a. The two flywheels spin in opposite directions at the same speed in order to cancel the unwanted effect of a rotating mass on the yaw dynamics of the vehicle. By using two flywheels, the maximum effective torque that can be generated is the sum of the torque values for each flywheel.  
As shown in Figure 3, the flywheels rotate on gimbal frames and are powered by the driving torques of two direct current (DC) electric motors that are attached to the gimbal frames and connected to the flywheel's shafts via couplings. Two other DC motors are used to rotate the gimbal frames. The driving torques of these motors are transmitted to the gimbal axes via level gears. The maximum and minimum values of the gimbal angle are limited from \(-90^{\circ}\) to \(90^{\circ}\) by limiting switches. To avoid any damage to the system due to a failure in control, four rubber restraints are placed on the platform to prevent the inverted pendulum from falling more than \(45^{\circ}\). A total of five encoders are used to measure the angle of each joint in the system.  
Figure 2: Forces acting on a pendulum-like bicycle model when turning.