**4.3 Actuator assembly dynamics**

There are two fundamental equations describing the characteristics of a DC motor. The first one relates torque (*τ*) on the shaft proportional to the armature current ( )*l* and the second expresses the back emf voltage (e) proportional to the shaft's rotational velocity ( ) *enc* , where *enc* represent the velocity measured by the encoder mounted on the same frame as the DC motor. This velocity represents the shaft velocity with respect to the DC motor itself.

$$
\pi = \text{Ki} \tag{1}
$$

$$
\epsilon = \mathbb{K}\_{\epsilon} \alpha\_{\text{enc}} \tag{2}
$$

#### **4.4 Body dynamics**

74 E-Learning – Organizational Infrastructure and Tools for Specific Areas

ROBOLAB programming. Level 1 is the easiest and Level 4 has more flexibility. Each level builds on the previous one. There are limitations within this section but it is a simple way for users to become familiar with the software. The Pilot Level 1 template is a simple task that introduces students to the programming features of ROBOLAB. Each level of Pilot provides additional flexibility and options. Students will always be successful in their

The design of a low-cost balancing robot is accomplished by using a popular development platform plint pack for the components and Lego for the construction material. The balancing robot is intended to improve the learning experience of students or hobbyists who are interested in control of mechanical components by presenting hands-on experiments and controller design examples that anyone would be able to follow easily and cost effectively.

The system consists of motors, wheels, and two pairs of spur gears that connect the motors and the wheels. The spur gear was added because the motor shaft was not long enough to support the distance required by the optical encoder. The optical encoder requires some space between the striped disk and the optical sensors to read black and white. The top stage consists of a microcontroller and an H-bridge. The microcontroller is the brain of the robot and is responsible for sampling and processing all the data collected by the sensors. The H-bridge is used with the microcontroller to control the directions of the motors. There is one more sensor attached to a vertical strut between the two stages. In general it is called an Inertial Measurement Unit, (IMU), and this one contains two accelerometers and one

To make the project simple and manageable, only a two-dimensional movement in which the system moves in one plane will be considered. The two motors are assumed to move together symmetrically when an identical input is given. Although this is unlikely the case, it is a good approximation for motors which are manufactured as the same product. A control voltage is applied to the motors, which results in displacement of the wheels and change in angular attitude of the body. A mathematical model for the system is obtained by

There are two fundamental equations describing the characteristics of a DC motor. The first one relates torque (*τ*) on the shaft proportional to the armature current ( )*l* and the second expresses the back emf voltage (e) proportional to the shaft's rotational velocity ( )

the DC motor. This velocity represents the shaft velocity with respect to the DC motor itself.

*e enc e K* 

*enc* represent the velocity measured by the encoder mounted on the same frame as

*Ki* (1)

(2)

*enc* ,

gyro to determine the robot's attitude in one angular direction.

programming within Pilot.

**4. Dynamics course**

**4.1 System description**

**4.2 System modeling**

where

observing the free body diagram.

**4.3 Actuator assembly dynamics**

The rotational motion of the pendulum body about its center of gravity can be described by

$$\text{I}\ddot{\theta} = -\text{2}\tau + -\text{2}\text{H}l\cos\theta + \text{2}Vl\sin\theta\tag{3}$$

where I is the moment of inertia of the pendulum body about its center of gravity. The horizontal force, vertical force and torque are applied as pairs on both sides and each pair is assumed to be equal because only two-dimensional motion was considered. The horizontal motion is given by:

$$2H = M\frac{d^2}{dt^2}(\mathbf{x} + l\sin\theta) \tag{4}$$

The linearised equations are:

$$\text{J}\ddot{\theta} = -2\pi - 2\text{Hl} + 2\text{Vl}\theta \tag{5}$$

$$
\Im H = M \left( \ddot{\mathbf{x}} + l \ddot{\boldsymbol{\theta}} \right) \tag{6}
$$

$$
\mathcal{D}V = \mathcal{M}\mathbf{g} \tag{7}
$$

#### **4.5 System dynamics**

The objective here is to find suitable ordinary differential equations that fully describe the system in terms of input v, the states *x*, and their derivatives , *x* . The following formulae describes how to characterize the essence of the system in two differential equations.

$$
\tau = \left(\frac{\text{J}}{r} + rm + \frac{rM}{2}\right)\ddot{\mathbf{x}} + \frac{rMl}{2}\ddot{\theta} \tag{8}
$$

$$\frac{R}{K} \left( \frac{I}{r} + rm + \frac{rM}{2} \right) \ddot{\mathbf{x}} + \frac{R\tau M l}{2K} \ddot{\theta} + \frac{K}{r} \dot{\mathbf{x}} - K\dot{\theta} = \nu \tag{9}$$

$$\left(I + rMl + ml^2\right)\ddot{\theta} + 2\left(\frac{J}{r} + rm + \frac{rM + lM}{2}\right)\ddot{x} - Mgl\theta = 0\tag{10}$$

Finally the overall equation yields:

$$\left(I + rMl + Ml^2\right)\ddot{\theta} + 2\left(\frac{J}{r} + rm + \frac{rM + lM}{2}\right)\ddot{x} - Mgl\theta = 0\tag{11}$$

These equations describe the motion of the system and constitute the two-dimensional linearized mathematical model of the system. Finally this set of equations can be expressed in a more convenient state space form:

$$
\begin{bmatrix}
\dot{\boldsymbol{x}} \\
\dot{\theta} \\
\ddot{\boldsymbol{\alpha}} \\
\ddot{\theta}
\end{bmatrix} = \begin{bmatrix}
0 & 0 & 1 & 0 \\
0 & 0 & 0 & 1 \\
0 & A\_{32} & A\_{33} & A\_{34} \\
0 & A\_{42} & A\_{43} & A\_{44}
\end{bmatrix} \begin{bmatrix}
\boldsymbol{x} \\
\boldsymbol{\theta} \\
\dot{\boldsymbol{\alpha}} \\
\dot{\theta}
\end{bmatrix} + \begin{bmatrix}
0 \\
0 \\
B3 \\
B4
\end{bmatrix} \boldsymbol{\nu} \tag{12}
$$

Lego Based Computer Communication for Business and Learning 77

It is very interesting to observe that the Kalman filter is following well the patterns of the gyro in a very noisy environment, whereas, at the end of the shaking process the sensor is

One of the easiest ways may be through implementing a controller for the DC Motor. A digital controller for position reference will transform the DC motor to behave like a servo. The code for the controller was generated using the MATLAB Real time Toolbox Embedded encoder. To confirm the DC motor model, a simple proportional control was designed and

Figures 6 and 7 illustrate the simulation result versus the real data. The rise time is shorter in reality. This is probably because of the sensor dynamics that was not considered in simulation. In reality the encoder has large quantization error. When conducting this experiment 64 lines were used by the encoder. This means 5.6 degrees was the maximum

Fig. 4. Unsteady motion measurement using Kalman filter.

stable; it pertains to the more accurate accelerometer data.

**5. Digital control for the motor position**

Fig. 5. Block diagram for motor position control.

implemented.

The unknown properties, *JMmrK* , , , , and *R* should be obtained by direct or experimental measurements.

#### **4.6 Sensors**

In here, inertia measurement unit (IMU) is developed by an open source approach from the Kalman filter. The graphs below illustrate how the Kalman filter can be useful in fusing single-axis angular attitudes collected separately. Ideally a jig would be required to provide an absolute reference angle at any given moment, but since the data will only be used as an observational reference and not in the core algorithm itself, it is reasonable to do without a costly jig and roughly compare data from the two sources, accelerometer unit and gyro unit and ultimately with the Kalman filtering results

Figure 3 represents a response to a steady movement. The Y-axis indicates the angle in degrees and the X-axis is the step count or sampling count from the microcontroller. Usually when implementing a microcontroller a task is programmed to be executed in a routine basis, but the experiment may also be operated in an endless loop without any delay time allowing the Euler Integration to produce higher quality results. It can be observed that both units reflect the angle quite similarly. The experiment was not long enough to catch the drift of the gyro but overall all data seemed to be reliable. So it was necessary to provide a harsh environment to intentionally invoke degradation in data. The next experiment was performed in a hard shaking circumstance.

Figure 4 shows interesting results. The IMU board was not only rotated radically but also shaken in order to generate lateral acceleration. The lateral acceleration introduces noise to the system so that by using accelerometers alone one cannot measure where about the angular attitude is. At the end of the shaking process the gyro reveals an offset compared to the angle provided by the accelerometer. In this case the accelerometer is more reliable and the offset can be considered as an integration propagation error or a continuous drift angle.

The unknown properties, *JMmrK* , , , , and *R* should be obtained by direct or experimental

In here, inertia measurement unit (IMU) is developed by an open source approach from the Kalman filter. The graphs below illustrate how the Kalman filter can be useful in fusing single-axis angular attitudes collected separately. Ideally a jig would be required to provide an absolute reference angle at any given moment, but since the data will only be used as an observational reference and not in the core algorithm itself, it is reasonable to do without a costly jig and roughly compare data from the two sources, accelerometer unit and gyro unit

Figure 3 represents a response to a steady movement. The Y-axis indicates the angle in degrees and the X-axis is the step count or sampling count from the microcontroller. Usually when implementing a microcontroller a task is programmed to be executed in a routine basis, but the experiment may also be operated in an endless loop without any delay time allowing the Euler Integration to produce higher quality results. It can be observed that both units reflect the angle quite similarly. The experiment was not long enough to catch the drift of the gyro but overall all data seemed to be reliable. So it was necessary to provide a harsh environment to intentionally invoke degradation in data. The next experiment was

Figure 4 shows interesting results. The IMU board was not only rotated radically but also shaken in order to generate lateral acceleration. The lateral acceleration introduces noise to the system so that by using accelerometers alone one cannot measure where about the angular attitude is. At the end of the shaking process the gyro reveals an offset compared to the angle provided by the accelerometer. In this case the accelerometer is more reliable and the offset can be considered as an integration propagation error or a continuous drift angle.

measurements.

and ultimately with the Kalman filtering results

Fig. 3. Steady motion using Kalman filter.

performed in a hard shaking circumstance.

**4.6 Sensors**

Fig. 4. Unsteady motion measurement using Kalman filter.

It is very interesting to observe that the Kalman filter is following well the patterns of the gyro in a very noisy environment, whereas, at the end of the shaking process the sensor is stable; it pertains to the more accurate accelerometer data.
