**3. Control system design**

### **3.1 Hierarchical sliding mode control design**

It can be assumed that all state variables are measurable. To design this controller in the *y*-*z* plane, first we introduce a suitable pair of SMSs

$$\begin{cases} s\_{\ge 1} = c\_{\ge 1} e\_{\ge 1} + \dot{e}\_{\ge 1} \\ s\_{\ge 2} = c\_{\ge 2} e\_{\ge 2} + \dot{e}\_{\ge 2} \end{cases} \tag{21}$$

where *cx*<sup>1</sup> and *cx*<sup>2</sup> are positive constants, *ex*<sup>1</sup> and *ex*<sup>2</sup> are tracking errors

$$\begin{cases} e\_{\ge 1} = \mathcal{y}\_k - \mathcal{y}\_{kd} \\ e\_{\ge 2} = \theta\_{\ge} - \theta\_{\ge d} \end{cases},\tag{22}$$

where *ykd* ¼ *const* denotes the desired position of the ball and θ*xd* is the desired tilt angle about the *x*-axis of the body.

When the Ballbot balances, it means that the desired tilt angle θ*xd* ¼ 0. Then, (21) can be rewritten as

$$\begin{cases} s\_{\ge 1} = c\_{\ge 1} (\mathcal{y}\_k - \mathcal{y}\_{kd}) + \dot{\mathcal{y}}\_k \\ s\_{\ge 2} = c\_{\ge 2} \theta\_{\ge} + \dot{\theta}\_{\ge} \end{cases} . \tag{23}$$

Let *s*\_*<sup>x</sup>*<sup>1</sup> ¼ 0 and *s*\_*<sup>x</sup>*<sup>2</sup> ¼ 0, the equivalent control laws of the two subsystems can be gotten as

$$\boldsymbol{\tau}\_{\text{xeq}1} = -G\_{\text{x1}}^{-1}(\mathbf{q}\_{\text{x}}) \left[ \boldsymbol{c}\_{\text{x1}} \dot{\boldsymbol{y}}\_{k} + F\_{\text{x1}}(\mathbf{q}\_{\text{x}}, \dot{\mathbf{q}}\_{\text{x}}) \right],\tag{24}$$

$$\tau\_{\text{xeq2}} = -G\_{\text{x2}}^{-1}(\mathbf{q}\_{\text{x}}) \left[ c\_{\text{x2}} \dot{\theta}\_{\text{x}} + F\_{\text{x2}}(\mathbf{q}\_{\text{x}}, \dot{\mathbf{q}}\_{\text{x}}) \right]. \tag{25}$$

The hierarchical SMC law is deduced as follows. The first layer SMS is defined as *Sx*<sup>1</sup> ¼ *sx*1. For the first layer SMS, the SMC law and the Lyapunov function are defined as

$$
\tau\_{\mathbf{x}1} = \tau\_{\mathbf{x}eq\mathbf{1}} + \tau\_{\mathbf{x}w1},\tag{26}
$$

and

$$V\_{\mathbf{x1}}(t) = \mathbf{0.5S}^2\_{\mathbf{x1}},\tag{27}$$

where *τxsw*<sup>1</sup> is the switch control part of the first layer SMC. Differentiate *Vx*1ð Þ*t* with respect to time *t*

$$
\dot{V}\_{\mathbf{x}1}(\mathbf{t}) = \mathbf{S}\_{\mathbf{x}1} \dot{\mathbf{S}}\_{\mathbf{x}1} \,. \tag{28}
$$

**Figure 3.** *Structure of hierarchical sliding mode surfaces.*

Let

$$\dot{\mathbf{S}}\_{\mathbf{x}1} = -k\_{\mathbf{x}1}\mathbf{S}\_{\mathbf{x}1} - \eta\_{\mathbf{x}1}\text{sign}(\mathbf{S}\_{\mathbf{x}1}),\tag{29}$$

where *kx*<sup>1</sup> and η*<sup>x</sup>*<sup>1</sup> are positive constants.

The first layer SMC law can be deduced from Eqs. (26) and (27), that is,

$$
\pi\_{\mathbf{x1}} = \pi\_{\mathbf{xeq1}} + G\_{\mathbf{x1}}^{-1}(\mathbf{q}\_{\mathbf{x}}) \dot{\mathbf{S}}\_{\mathbf{x1}}.\tag{30}
$$

The second layer SMS is constructed based on the first layer SMS *S*<sup>1</sup> and s2, as shown in **Figure 3**.

$$\mathbf{S}\_{\mathbf{x}2} = a\_{\mathbf{x}} \mathbf{S}\_{\mathbf{x}1} + \mathbf{s}\_{\mathbf{x}2},\tag{31}$$

where α*<sup>x</sup>* is the sliding mode parameter.

For the second layer SMS, the SMC law and the Lyapunov function are defined as

$$
\tau\_{\mathbf{x}2} = \tau\_{\mathbf{x}1} + \tau\_{\mathbf{x}eq2} + \tau\_{\mathbf{x}u\nu2},\tag{32}
$$

and

$$V\_{\mathbf{x2}}(\mathbf{t}) = \mathbf{0.5S}\_{\mathbf{x2}}^2,\tag{33}$$

where *τxsw*<sup>2</sup> is the switch control part of the second layer SMC. Differentiating *Vx*2ð Þ*t* with respect to time *t* yields

$$
\dot{V}\_{\mathbf{x}2}(t) = \mathbf{S}\_{\mathbf{x}2} \dot{\mathbf{S}}\_{\mathbf{x}2} \,. \tag{34}
$$

Let

$$\dot{\mathbf{S}}\_{\mathbf{x}2} = -k\_{\mathbf{x}2} \mathbf{S}\_{\mathbf{x}2} - \eta\_{\mathbf{x}2} \text{sign}(\mathbf{S}\_{\mathbf{x}2}),\tag{35}$$

where *kx*<sup>2</sup> and η*<sup>x</sup>*<sup>2</sup> are positive constants.

The total control law of the presented hierarchical SMC can be deduced as follows:

$$\tau\_{\mathbf{x2}} = \frac{a\_{\mathbf{x}} G\_{\mathbf{x1}}(\mathbf{q\_{x}}) \tau\_{\mathbf{xeq1}} + G\_{\mathbf{x2}}(\mathbf{q\_{x}}) \tau\_{\mathbf{xeq2}} + \dot{\mathbf{S}}\_{\mathbf{x2}}}{a\_{\mathbf{x}} G\_{\mathbf{x1}}(\mathbf{q\_{x}}) + G\_{\mathbf{x2}}(\mathbf{q\_{x}})}. \tag{36}$$

*Hierarchical Sliding Mode Control for a 2D Ballbot That Is a Class of Second-Order… DOI: http://dx.doi.org/10.5772/intechopen.101855*

Similarly, the total control law of the hierarchical SMC in the *x*-*z* plane also given as

$$\tau\_{\mathcal{Y}^2} = \frac{a\_{\mathcal{Y}} G\_{\mathcal{Y}1} \left( \mathbf{q}\_{\mathcal{Y}} \right) \tau\_{\mathcal{Y}^{eq1}} + G\_{\mathcal{Y}2} \left( \mathbf{q}\_{\mathcal{Y}} \right) \tau\_{\mathcal{Y}^{eq2}} + \dot{S}\_{\mathcal{Y}^2}}{a\_{\mathcal{Y}} G\_{\mathcal{Y}1} \left( \mathbf{q}\_{\mathcal{Y}} \right) + G\_{\mathcal{Y}^2} \left( \mathbf{q}\_{\mathcal{Y}} \right)}. \tag{37}$$

### **3.2 Stability analysis**

*Theorem 1*: If considering the total control law (36) and the SMSs (23) and (31) for the system dynamics (15) and (16), then SMSs, *Sx*<sup>1</sup> and *Sx*<sup>2</sup> are asymptotically stable. *Proof*: Integrating both sides (34) with respect to time obtains

$$\int\_{0}^{t} \dot{V}\_{\mathbf{x}2} d\tau = \int\_{0}^{t} (-\eta\_{\mathbf{x}2} |\mathbf{S}\_{\mathbf{x}2}| - k\_{\mathbf{x}2} \mathbf{S}\_{\mathbf{x}2}^{2}) d\tau,\tag{38}$$

Then

$$V\_{\mathbf{x}2}(t) - V\_{\mathbf{x}2}(0) = \int\_{0}^{t} (-\eta\_{\mathbf{x}2}|\mathbf{S}\_{\mathbf{x}2}| - k\_{\mathbf{x}2}\mathbf{S}\_{\mathbf{x}2}^{2})d\tau,\tag{39}$$

It can be found that

$$V\_{\mathbf{x}2}(\mathbf{0}) = V\_{\mathbf{x}2}(t) + \int\_{0}^{t} (\eta\_{\mathbf{x}2}|\mathbf{S}\_{\mathbf{x}2}| + k\_{\mathbf{x}2}\mathbf{S}\_{\mathbf{x}2}^{2}) d\tau \geq \int\_{0}^{t} (\eta\_{\mathbf{x}2}|\mathbf{S}\_{\mathbf{x}2}| + k\_{\mathbf{x}2}\mathbf{S}\_{\mathbf{x}2}^{2}) d\tau. \tag{40}$$

Therefore, it can be achieved that

$$\lim\_{t \to \infty} \int\_0^t (\eta\_{\ge 2} |S\_{\ge 2}| + k\_{\ge 2} S\_{\ge 2}^2) d\tau \le V\_{\ge 2}(0) < \infty.$$

By using Barbalat's lemma [23], we can obtain that if *t* ! ∞ then *η<sup>x</sup>*2j jþ *Sx*<sup>2</sup> *kx*2*S*<sup>2</sup> *<sup>x</sup>*<sup>2</sup> ! 0. Then, lim*<sup>t</sup>*!<sup>∞</sup> *Sx*<sup>2</sup> <sup>¼</sup> 0.

By applying Barbalat's lemma, we can get lim*<sup>t</sup>*!<sup>∞</sup> *Sx*<sup>2</sup> <sup>¼</sup> 0.

Thus, both *Sx*<sup>1</sup> and *Sx*<sup>2</sup> are asymptotically stable.

*Theorem 2*: If considering the control law (36) and the SMSs of (23) for the system dynamics (15) and (16), then SMSs, *sx*<sup>1</sup> and *sx*2, are also asymptotically stable.

*Proof*: From Theorem 1, the SMS of the ball subsystem dynamics is asymptotically stable.

Now, we will prove that the SMS of the body subsystem dynamics is asymptotically stable. Limiting of both sides of (31) obtains

$$\lim\_{t \to \infty} \mathbb{S}\_{\mathbf{x}2} = \lim\_{t \to \infty} (a\_{\mathbf{x}} \mathbb{S}\_{\mathbf{x}1} + s\_{\mathbf{x}2}) = a\_{\mathbf{x}} \left( \lim\_{t \to \infty} \mathbb{S}\_{\mathbf{x}1} \right) + \lim\_{t \to \infty} s\_{\mathbf{x}2} = \lim\_{t \to \infty} s\_{\mathbf{x}2}.\tag{41}$$

The result of (41) shows lim*<sup>t</sup>*!<sup>∞</sup> *sx*<sup>2</sup> <sup>¼</sup> lim*<sup>t</sup>*!<sup>∞</sup> *Sx*<sup>2</sup> <sup>¼</sup> 0. It demonstrates that the SMS of the body subsystem dynamics is asymptotically stable. Thus, the all SMSs of the subsystems are asymptotically stable.

$$\begin{aligned} 0 < \varepsilon\_{\mathbf{x}2} &< \left| \lim\_{\mathbf{x} \to \mathbf{0}} \left( \frac{F\_{\text{:2}}(\mathbf{q}\_{\mathbf{x}}, \dot{\mathbf{q}}\_{\mathbf{x}})}{\dot{\theta}\_{\mathbf{x}}} \right) \right|, \text{where } \mathbf{x} = \begin{bmatrix} \mathbf{q}\_{\mathbf{x}} & \dot{\mathbf{q}}\_{\mathbf{x}} \end{bmatrix}. \\ \text{Proof: By solving } \varepsilon\_{\mathbf{x}i} &= \mathbf{0}, \text{ the lower boundary of } c\_{\mathbf{x}i} \text{ can be obtained} \end{aligned}$$

$$\begin{cases} s\_{\mathbf{x1}} = c\_{\mathbf{x1}} (\mathbf{y}\_k - \mathbf{y}\_{kd}) + \dot{\mathbf{y}}\_k = \mathbf{0} \\ s\_{\mathbf{x2}} = c\_{\mathbf{x2}} \theta\_{\mathbf{x}} + \dot{\theta}\_{\mathbf{x}} = \mathbf{0} \end{cases} . \tag{42}$$

$$\begin{cases} \dot{s}\_{\mathbf{x}1} = c\_{\mathbf{x}1}\dot{\mathbf{y}}\_{\mathbf{k}} + F\_{\mathbf{x}1}(\mathbf{q}\_{\mathbf{x}}, \dot{\mathbf{q}}\_{\mathbf{x}}) + G\_{\mathbf{x}1}(\mathbf{q}\_{\mathbf{x}})\tau\_{\mathbf{x}eq1} = \mathbf{0} \\ \dot{s}\_{\mathbf{x}2} = c\_{\mathbf{x}2}\dot{\theta}\_{\mathbf{x}} + F\_{\mathbf{x}2}(\mathbf{q}\_{\mathbf{x}}, \dot{\mathbf{q}}\_{\mathbf{x}}) + G\_{\mathbf{x}2}(\mathbf{q}\_{\mathbf{x}})\tau\_{\mathbf{x}eq2} = \mathbf{0} \end{cases} \tag{43}$$

$$\begin{cases} \mathbf{c}\_{\mathbf{x}1} = \left| \frac{(\mathbf{F}\_{\mathbf{x}1}(\mathbf{q}\_{\mathbf{x}}, \dot{\mathbf{q}}\_{\mathbf{x}}) + \mathbf{G}\_{\mathbf{x}1}(\mathbf{q}\_{\mathbf{x}}) \tau\_{\mathbf{x}eq1})}{\dot{\nu}\_{k}} \right| \\ \mathbf{c}\_{\mathbf{x}2} = \left| \frac{(\mathbf{F}\_{\mathbf{x}2}(\mathbf{q}\_{\mathbf{x}}, \dot{\mathbf{q}}\_{\mathbf{x}}) + \mathbf{G}\_{\mathbf{x}2}(\mathbf{q}\_{\mathbf{x}}) \tau\_{\mathbf{x}eq2})}{\dot{\theta}\_{\mathbf{x}}} \right| \end{cases} \tag{44}$$

$$\begin{cases} c\_{\rm x1} < \frac{\left( \left| F\_{\rm x1} \left( \mathbf{q}\_{\rm x}, \dot{\mathbf{q}}\_{\rm x} \right) \right| + \left| G\_{\rm x1} \left( \mathbf{q}\_{\rm x} \right) \tau\_{\rm xeq} \right| \right)}{\left| \dot{\boldsymbol{\nu}}\_{k} \right|} \\ c\_{\rm x2} < \frac{\left( \left| F\_{\rm x2} \left( \mathbf{q}\_{\rm x}, \dot{\mathbf{q}}\_{\rm x} \right) \right| + \left| G\_{\rm x2} \left( \mathbf{q}\_{\rm x} \right) \tau\_{\rm xeq} \right| \right)}{\left| \dot{\boldsymbol{\theta}}\_{\rm x} \right|} \end{cases} \tag{45}$$

$$
\begin{bmatrix} \pi\_1\\ \pi\_2\\ \pi\_3 \end{bmatrix} = \begin{bmatrix} 2 & -1 & -1\\ 3\cos a & -\frac{3\cos a}{3\cos a} & -\frac{1}{3\cos a} \\ 0 & \frac{\sqrt{3}}{3\cos a} & -\frac{\sqrt{3}}{3\cos a} \end{bmatrix}^T \begin{bmatrix} \tau\_x\\ \tau\_y \end{bmatrix}.\tag{46}
$$

*Hierarchical Sliding Mode Control for a 2D Ballbot That Is a Class of Second-Order… DOI: http://dx.doi.org/10.5772/intechopen.101855*

**Figure 4.** *Block diagram of the control system.*
