# International Journal of Robotic Engineering

(ISSN: 2631-5106)

Volume 5, Issue 2

Research Article

#### DOI: 10.35840/2631-5106/4128

# A Two-Link Robot Manipulator: Simulation and Control Design

Mahboub Baccouch^{1*} and Stephen Dodds^{2}

### Table of Content

### Figures

**Figure 1:** A simplified model of a two-link....

A simplified model of a two-link planar robot manipulator.

**Figure 2:** The initial positions (left) and the.....

The initial positions (left) and the final position (right) of *M _{1}* and

*M*for example 1.

_{2} **Figure 3:** The positions of *M _{1}* (left) and

*M*....

_{2}
The positions of *M _{1}* (left) and

*M*(right) versus time for example 1.

_{2} **Figure 4:** The errors e(*θ*_{1}) = *θ*_{1}(t) - *θ*_{1f} and....

The errors *e*(*θ*_{1}) = *θ*_{1}(t) - *θ _{1f}* and

*e*(

*θ*

_{2}) =

*θ*

_{2}(t) -

*θ*

_{2f}versus time for example 1.

**Figure 5:** The torques of *θ*_{1} (left) and *θ*_{2} (right)....

The torques of *θ*_{1} (left) and *θ*_{2} (right) versus time for example 1.

**Figure 6:** The initial positions (left) and the final....

The initial positions (left) and the final position (right) of *M _{1}* and

*M*for example 2.

_{2} **Figure 7:** The positions of *M _{1}* (left) and

*M*...

_{2}
The positions of *M _{1}* (left) and

*M*(right) versus time for example 2.

_{2} **Figure 8:** The errors e(*θ*_{1}) = *θ*_{1}(t) - *θ _{1f}* and...

The errors e(*θ*_{1}) = *θ*_{1}(t) - *θ _{1f}* and e(

*θ*

_{2}) =

*θ*

_{2}(t) -

*θ*versus time for example 2.

_{2f} **Figure 9:** The torques of *θ*_{1} (left) and *θ*_{2} (right)...

The torques of *θ*_{1} (left) and *θ*_{2} (right) versus time for example 2.

**Figure 10:** The initial positions (left) and the final position...

The initial positions (left) and the final position (right) of *M _{1}* and

*M*for example 3.

_{2} **Figure 11:** The positions of *M _{1}* (left) and

*M*(right)...

_{2}
The positions of *M _{1}* (left) and

*M*(right) versus time for example 3.

_{2} **Figure 12:** The errors e(*θ*_{1}) = *θ*_{1}(t) - *θ _{1f}* and...

The errors e(*θ*_{1}) = *θ*_{1}(t) - *θ _{1f}* and e(

*θ*

_{2}) =

*θ*

_{2}(t) -

*θ*versus time for example 3.

_{2f} **Figure 13:** The torques of *θ*_{1} (left) and *θ*_{2} (right)....

The torques of *θ*_{1} (left) and *θ*_{2} (right) versus time for example 3.

**Figure 14:** The initial positions (left) and the final...

The initial positions (left) and the final position (right) of *M _{1}* and

*M*for example 4.

_{2} **Figure 15:** The positions of *M _{1}* (left) and

*M*....

_{2}
The positions of *M _{1}* (left) and

*M*(right) versus time for example 4.

_{2} **Figure 16:** The errors e(*θ*_{1}) = *θ*_{1}(t) - *θ _{1f}* and....

The errors *e*(*θ*_{1}) = *θ*_{1}(t) - *θ _{1f}* and e(

*θ*

_{2}) =

*θ*

_{2}(t) -

*θ*versus time for example 4.

_{2f} **Figure 17:** The torques of *θ*_{1} (left) and *θ*_{2}...

The torques of *θ*_{1} (left) and *θ*_{2} (right) versus time for example 4.

### References

- RM Murray, Z Li, SS Sastry (1994) A mathematical introduction to robotic manipulation. CRC press.
- RL Burden, JD Faires, AM Burden (2016) Numerical analysis. Cengage Learning, Boston, MA.
- JYS Luh (1983) Conventional controller design for industrial robots a tutorial. IEEE Transactions on Systems, Man, and Cybernetics SMC-13: 298-316.
- J Shah, S Rattan, B Nakra (2015) Dynamic analysis of two link robot manipulator for control design using computed torque control. International Journal of Research in Computer Applications and Robotics 3: 52-59.
- G Nandy, B Chatterjee, A Mukherjee (2018) Dynamic analysis of two-link robot manipulator for control design. Advances in Communication, Devices and Networking, Springer, 767-775.
- JS Kumar, EK Amutha (2014) Control and tracking of robotic manipulator using PID controller and hardware in loop simulation. International Conference on Communication and Network Technologies, IEEE.
- A Mohammed, A Eltayeb (2018) Dynamics and control of a two-link manipulator using PID and sliding mode control. International Conference on Computer, Control, Electrical, and Electronics Engineering (ICC- CEEE), IEEE.
- NK Chaturvedi, L Prasad (2018) A comparison of computed torque control and sliding mode control for a three link srobot manipulator. International Conference on Computing, Power and Communication Technologies (GUCON), IEEE.
- J Romero, L Diago, J Shinoda, I Hagiwara (2015) Evaluation of brain models to control a robotic origami arm using holographic neural networks. International Design Engineering Technical Conferences and Computers and Information in Engineering Conference, 57137.
- DM Wolpert, RC Miall, M Kawato (1998) Internal models in the cerebellum. Trends in cognitive sciences 2: 338-347.
- CH Edwards, DE Penney, DT Calvis (2016) Differential equations and boundary value problems. Pearson Education Limited.

**Author Details**

Mahboub Baccouch^{1*} and Stephen Dodds^{2}

^{1}Professor, Department of Mathematics, University of Nebraska at Omaha, USA

^{2}CEO, JUUK CO, Austin, USA

**Corresponding author**

Mahboub Baccouch, Professor, Department of Mathematics, University of Nebraska at Omaha, USA, Tel: 402-554-4016, Fax: 402-554-2975.

Accepted: December 08, 2020 | Published Online: December 10, 2020

Citation: Baccouch M, Dodds S (2020) A Two-Link Robot Manipulator: Simulation and Control Design. Int J Robot Eng 5:028

Copyright: © 2020 Baccouch M, et al. This is an open-access article distributed under the terms of the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.

## Abstract

In this paper, we design a robust, fast, and practical proportional-integral-derivative (PID) controller for the classical double pendulum system. We first derive the equations of motion for the two-link robot manipulator using the Lagrangian approach. These equations are described by nonlinear system of ordinary differential equations. Because closed form solutions of the equations of motion are not available, we use the classical fourth-order Runge-Kutta method to approximate the solution of the initial-value problem. Because of the nonlinear behavior, it is a challenging task to control the motion of the two-link robot manipulator at accurate position defined by the user. For this, we focus mainly on control of the robot manipulator to get the desired position using the computed torque control method. After deriving the equation of motion, control simulation is represented using MATLAB. Several computer simulations are used to verify the performance of the controller. In particular, we present a PID controller to simulate how we would balance the two-links on a moving robot to any specific angle including upside-down.

## Keywords

Two-link robot manipulator, Robotics, PID controller, Dynamic control, Simulation

## Introduction

Robotic manipulators are a major component in the manufacturing industry. They are used for many reasons including speed, accuracy, and repeatability. Increasingly, robotic manipulators are finding their way into our everyday life. In fact in almost every product we encounter, a robotic manipulator has played a part in its production. In robotics, one of the most difficult tasks is to perform a precise and fast movement of a robotic arm. In this paper, one control model is proposed to solve this problem.

The double pendulum system is a common and typical model to investigate nonlinear dynamics due to its various and complex dynamical phenomenon. The double pendulum is an example of a simple dynamical system that exhibits complex behavior, including chaos. It consists of two point masses at the end of light rods. Each mass plus rod is a regular simple pendulum. The two pendula are joined together and the system is free to oscillate in a plane. Two-link manipulators are two-degree-of-freedom robots. They are useful because they function like human arms. We can begin to understand the complex movement of human arms after defining the movement of the two-link manipulator [1]. The total potential and kinetic energies of the two-link system are defined and used to form the Lagrangian. The Euler-Lagrangian equation was used to define the torques applied to each link [2]. A proportional-integral-derivative (PID) controller is implemented to simulate the behavior of the system when torques are applied [3]. The PID controllers are the most common used controllers, due to their easy implementation and versatility. PID controllers remain the standard for industry and research given their flexibility and ease of use in both simulation and hardware systems [4-6].

Due to the nonlinear nature of the two-link manipulator, specialized control systems are often required to maintain a position or perform a task [7]. Researchers have found success using Sliding Mode Control compared to PID [8]. Others have used Artificial Neural Networks and Holographic Neural Networks as part of their PID feedback loop to perform the task of folding paper [9,10]. The proposed solution uses the command ode45 in MATLAB to solve for the angle of each link relative to the positive X-axis. PID control is developed and considered to show how you can force the system to specific angles. We also show graphical results of the system after the PID control is applied.

In this paper, we propose a PID controller for a double pendulum system. We derive the equations of motion for a two-link robot manipulator based on Lagrangian Formulation. The equation of motion for two link robot is a nonlinear differential equation. As the closed form solutions are not available we have to use numerical solution. After deriving the equation of motion, control simulation is represented using MATLAB. We expand upon the standard two-link manipulator problem, to that of an upside-down pendulum with multiple links on top of a moving object. In this case we look to implement the control system into a mobile robot called the Computer and Electronics Engineering Robot (CEEnBot).

The structure of this paper is as follows. In section 4, we derive the equations of motion for a two-link robotic manipulator using the Lagrangian method. We also describe how to obtain the numerical solution using the ode45 command defined in MATLAB to solve the system of ordinary differential equations numerically. We explain the design of the PID controller for the double pendulum system in section 5. In section 6, we present several numerical examples to test the PID controller. Finally, we provide some concluding remarks in section 7.

## Dynamics of Two-Link Manipulators

Double pendula are an example of a simple physical system which can exhibit chaotic behavior. Understanding the two-link manipulator is key to learning robotic manipulators as a whole. We consider the two-link robotic manipulator which is a classic example studied in introductory robotics courses. The physical system is shown in Figure 1.

The system consists of two masses connected by weightless bars. The bars have lengths *L _{1}* and

*L*. The masses are denoted by

_{2}*M*and

_{1}*M*, respectively. Let

_{2}*θ*

_{1}and

*θ*

_{2}denote the angles in which the first bar rotates about the origin and the second bar rotates about the endpoint of the first bar, respectively. This system has two degrees of freedom

*θ*

_{1}and

*θ*

_{2}.

The first step in deriving the equations of motion using the Lagrangian approach is to find the kinetic energy KE and the potential energy *PE* of the system.

The equations for the *x*-position and the *y*-position of *M _{1}* are given by

$${x}_{1}\text{}=\text{}{L}_{1}\mathrm{cos}\left({\theta}_{1}\right),\text{}{y}_{1}\text{}=\text{}{L}_{1}\mathrm{sin}\left({\theta}_{1}\right)\text{(4}\text{.1)}$$

Similarly, the equations for the *x*-position and the *y*-position of *M _{2}* are given by

$${x}_{2}\text{}=\text{}{L}_{1}\mathrm{cos}\left({\theta}_{1}\right)\text{}+\text{}{L}_{2}\mathrm{cos}\left({\theta}_{2}\right)\text{,}{y}_{2}\text{}=\text{}{L}_{1}\mathrm{sin}\left({\theta}_{1}\right)\text{}+\text{}{L}_{2}\mathrm{sin}\left({\theta}_{2}\right)\text{(4}\text{.2)}$$

Next, we calculate the velocities of *M _{1}* and

*M*using the following formulas

_{2}$${v}_{1}\text{}=\text{}\sqrt{{\dot{x}}_{1}^{2}\text{}+\text{}{\dot{y}}_{1}^{2}},\text{}{v}_{2}\text{}=\text{}\sqrt{{\dot{x}}_{2}^{2}\text{}+\text{}{\dot{y}}_{2}^{2}},\text{(4}\text{.3)}$$

where,

$${\dot{x}}_{1}\text{}=\text{}-\text{}{L}_{1}{\dot{\theta}}_{1}\mathrm{sin}\left({\theta}_{1}\right),{\dot{y}}_{1}\text{}=\text{}{L}_{1}{\dot{\theta}}_{1}\mathrm{cos}\left({\theta}_{1}\right),$$

$${\dot{x}}_{2}\text{}=\text{}-\text{}{L}_{1}{\dot{\theta}}_{1}\mathrm{sin}\left({\theta}_{1}\right)\text{}-\text{}{L}_{2}{\dot{\theta}}_{2}\mathrm{sin}\left({\theta}_{2}\right),{\dot{y}}_{2}\text{}=\text{}{L}_{1}{\dot{\theta}}_{1}\mathrm{cos}\left({\theta}_{1}\right)\text{}+\text{}{L}_{2}{\dot{\theta}}_{2}\mathrm{cos}\left({\theta}_{2}\right)$$

Here and below the dot ˙ is a derivative with respect to *t*, i.e., ${\dot{\theta}}_{k}\text{}=\text{}\frac{d{\theta}_{k}}{dt},{\dot{x}}_{k}\text{}=\text{}\frac{d{x}_{k}}{dt},$ for *k* = 1, 2.

The kinematic energy can be calculated as follows

$$KE\text{}=\text{}\frac{1}{2}{M}_{1}{v}_{1}^{2}\text{}+\text{}\frac{1}{2}{M}_{2}{v}_{2}^{2}\text{(4}\text{.4)}$$

The equation for the kinetic energy can be written as

$$KE\text{}=\text{}\frac{1}{2}{M}_{1}\left({\dot{x}}_{1}^{2}\text{}+\text{}{\dot{y}}_{1}^{2}\right)\text{}+\text{}\frac{1}{2}{M}_{2}\left({\dot{x}}_{2}^{2}\text{}+\text{}{\dot{y}}_{2}^{2}\right)\text{(4}\text{.5)}$$

Substituting (4.1) - (4.2) into (4.5), we get

$$\begin{array}{l}KE\text{}=\text{}\frac{1}{2}{M}_{1}\left({\left(-\text{}{L}_{1}{\dot{\theta}}_{1}\mathrm{sin}\left({\theta}_{1}\right)\right)}^{2}\text{}+\text{}{\left({L}_{1}{\dot{\theta}}_{1}\mathrm{cos}\left({\theta}_{1}\right)\right)}^{2}\right)\\ \text{}+\text{}\frac{1}{2}{M}_{2}\left({\left(-\text{}{L}_{1}{\dot{\theta}}_{1}\mathrm{sin}\left({\theta}_{1}\right)\text{}-\text{}{L}_{2}{\dot{\theta}}_{2}\mathrm{sin}\left({\theta}_{2}\right)\right)}^{2}\text{}+\text{}{\left({L}_{1}{\dot{\theta}}_{1}\mathrm{cos}\left({\theta}_{1}\right)\text{}+\text{}{L}_{2}{\dot{\theta}}_{2}\mathrm{cos}\left({\theta}_{2}\right)\right)}^{2}\right),\end{array}$$

which can be simplified as

$$KE\text{}=\text{}\frac{1}{2}\left({M}_{1}\text{}+\text{}{M}_{2}\right){L}_{1}^{2}{\dot{\theta}}_{1}^{2}\text{}+\text{}\frac{1}{2}{M}_{2}{L}_{2}^{2}{\dot{\theta}}_{2}^{2}\text{}+\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{1}{\dot{\theta}}_{2}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{(4}\text{.6)}$$

In order to calculate the Lagrangian, the potential energy *PE* has to be calculated. By definition the potential energy of the system due to gravity of the i^{th} pendulum is

$$P{E}_{i}\left(\theta \right)\text{}=\text{}{M}_{i}g{h}_{i}\left(\theta \right),\text{i=1,2,(4}\text{.7)}$$

which *h _{i}* is the height of the center of mass of the

*i*pendulum,

^{th}*g*is the acceleration due to gravity constant, and

*M*is the mass of the

_{i}*i*pendulum. Therefore, the total potential energy for both pendulums can be given by

^{th}$$\begin{array}{l}PE\text{}=\text{}PE\left(\theta \right)\text{}=\text{}{\displaystyle {\sum}_{i\text{}=\text{}1}^{2}P{E}_{i}\left(\theta \right)}\text{}=\text{}{\displaystyle {\sum}_{i\text{}=\text{}1}^{2}{M}_{i}g{h}_{i}\left(\theta \right)}\text{}=\text{}{M}_{1}g{L}_{1}\mathrm{sin}\left({\theta}_{1}\right)\text{}+\text{}{M}_{2}g\left({L}_{1}\mathrm{sin}\left({\theta}_{1}\right)\text{}+\text{}{L}_{2}\mathrm{sin}\left({\theta}_{2}\right)\right)\text{(4}\text{.8)}\\ \text{}=\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right)g{L}_{1}\mathrm{sin}\left({\theta}_{1}\right)\text{}+\text{}{M}_{2}g{L}_{2}\mathrm{sin}\left({\theta}_{2}\right)\end{array}$$

Next, by Lagrange Dynamics, we form the Lagrangian $\mathcal{L}$ which is defined as

$$\mathcal{L}\text{}=\text{}KE-PE\text{(4}\text{.9)}$$

Substituting the expressions for the kinetic energy (4.6) and potential energy (4.8) in for *KE* and

*PE* we get

$$\begin{array}{l}\mathcal{L}\text{}=\text{}\frac{1}{2}\left({M}_{1}\text{}+\text{}{M}_{2}\right){L}_{1}^{2}{\dot{\theta}}_{1}^{2}\text{}+\text{}\frac{1}{2}{M}_{2}{L}_{2}^{2}{\dot{\theta}}_{2}^{2}\text{}+\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{1}{\dot{\theta}}_{2}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right)\text{(4}\text{.10)}\\ g{L}_{1}\mathrm{sin}\left({\theta}_{1}\right)\text{}-\text{}{M}_{2}g{L}_{2}\mathrm{sin}\left({\theta}_{2}\right).\end{array}$$

The Euler-Lagrange equation is given by the equation

$$\frac{d}{dt}\left[\frac{\partial \mathcal{L}}{\partial {\dot{\theta}}_{i}}\right]\text{}-\text{}\frac{\partial \mathcal{L}}{\partial {\theta}_{i}}\text{}=\text{}{\tau}_{i},\text{i=1,2,(4}\text{.11)}$$

where ${\tau}_{i}$ is the torque applied to the *i ^{th}* link.

The derivations for the Lagrangian equation and Euler-Lagrange equation can be found in [1]. We were more concerned with using the formulas in this problem rather than going into too much in detail for these derivations.

From (4.10), we have

$$\frac{\partial \mathcal{L}}{\partial {\dot{\theta}}_{i}}\text{}=\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right){L}_{1}^{2}{\dot{\theta}}_{1}\text{}+\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{2}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right),$$

$$\frac{\partial \mathcal{L}}{\partial {\theta}_{1}}\text{}=\text{}-\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{1}{\dot{\theta}}_{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right)g{L}_{1}\mathrm{cos}\left({\theta}_{1}\right),$$

and

$$\frac{d}{dt}\left[\frac{\partial \mathcal{L}}{\partial {\dot{\theta}}_{i}}\right]\text{}=\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right){L}_{1}^{2}{\ddot{\theta}}_{1}\text{}+\text{}{M}_{2}{L}_{1}{L}_{2}{\ddot{\theta}}_{2}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{2}\left({\dot{\theta}}_{1}\text{}-\text{}{\dot{\theta}}_{2}\right)\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)$$

Similarly, we compute

$$\frac{\partial \mathcal{L}}{\partial {\dot{\theta}}_{2}}\text{}=\text{}{M}_{2}{L}_{2}^{2}{\dot{\theta}}_{2}\text{}+\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{1}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right),$$

$$\frac{\partial \mathcal{L}}{\partial {\theta}_{2}}\text{}=\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{1}{\dot{\theta}}_{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}{M}_{2}g{L}_{2}\mathrm{cos}\left({\theta}_{2}\right),$$

and

$$\frac{d}{dt}\left[\frac{\partial \mathcal{L}}{\partial {\dot{\theta}}_{2}}\right]\text{}=\text{}{M}_{2}{L}_{2}^{2}{\ddot{\theta}}_{2}\text{}+\text{}{M}_{2}{L}_{1}{L}_{2}{\ddot{\theta}}_{1}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{1}\left({\dot{\theta}}_{1}\text{}-\text{}{\dot{\theta}}_{2}\right)\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)$$

Therefore, (4.11) gives the following two nonlinear equations of motion which are second-order system of ordinary differential equations

$$\begin{array}{l}\left({M}_{1}\text{}+\text{}{M}_{2}\right){L}_{2}^{2}{\ddot{\theta}}_{1}\text{}+\text{}{M}_{2}{L}_{1}{L}_{2}{\ddot{\theta}}_{2}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}+\text{(4}\text{.12a)}\\ {M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{2}^{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}+\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right)g{L}_{1}\mathrm{cos}\left({\theta}_{1}\right)\text{}=\text{}{\tau}_{1},\end{array}$$

$${M}_{2}{L}_{2}^{2}{\ddot{\theta}}_{2}\text{}+\text{}{M}_{2}{L}_{1}{L}_{2}{\ddot{\theta}}_{2}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{1}^{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}+\text{}{M}_{2}g{L}_{2}\mathrm{cos}\left({\theta}_{2}\right)\text{}=\text{}{\tau}_{2},\text{(4}\text{.12b)}$$

or equivalently,

$${L}_{1}{\ddot{\theta}}_{1}\text{}+\text{}\delta {L}_{1}{L}_{2}{\ddot{\theta}}_{2}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}=\text{}\frac{\delta {\tau}_{1}}{{M}_{2}{L}_{1}}\text{}-\text{}\delta {L}_{2}{\dot{\theta}}_{2}^{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}g\mathrm{cos}\left({\theta}_{1}\right),\text{(4}\text{.13a)}$$

$${L}_{2}{\ddot{\theta}}_{2}\text{}+\text{}{L}_{1}{\ddot{\theta}}_{1}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}=\text{}\frac{{\tau}_{2}}{{M}_{2}{L}_{2}}\text{}+\text{}{L}_{1}{\dot{\theta}}_{1}^{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}g\mathrm{cos}\left({\theta}_{2}\right),\text{(4}\text{.13b)}$$

where, $\delta \text{}=\text{}\frac{{M}_{2}}{{M}_{1}\text{}+\text{}{M}_{2}}$.

Solving for ${\ddot{\theta}}_{1}$ and ${\ddot{\theta}}_{2}$, we get the normal form of the dynamics equations

$${\ddot{\theta}}_{1}\text{}=\text{}{g}_{1}\left(t,{\theta}_{1},{\theta}_{2},{\dot{\theta}}_{1},{\dot{\theta}}_{2}\right),{\ddot{\text{}\theta}}_{2}\text{}=\text{}{g}_{2}\left(t,{\theta}_{1},{\theta}_{2},{\dot{\theta}}_{1},{\dot{\theta}}_{2}\right),\text{(4}\text{.14a)}$$

where,

$${g}_{1}\text{}=\text{}\frac{\frac{\delta {\tau}_{1}}{{M}_{2}{L}_{1}}\text{}-\text{}\delta {L}_{2}{\dot{\theta}}_{2}^{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}g\mathrm{cos}\left({\theta}_{1}\right)\text{}-\text{}\delta \mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\left(\frac{{\tau}_{2}}{{M}_{2}{L}_{2}}\text{}+\text{}{L}_{1}{\dot{\theta}}_{1}^{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}g\mathrm{cos}\left({\theta}_{2}\right)\right)}{{L}_{1}\left(1\text{}-\text{}\delta {\mathrm{cos}}^{2}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\right)},\text{(4}\text{.14b)}$$

$${g}_{2}\text{}=\text{}\frac{\frac{{\tau}_{2}}{{M}_{2}{L}_{2}}\text{}+\text{}{L}_{1}{\dot{\theta}}_{1}^{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}g\mathrm{cos}\left({\theta}_{2}\right)\text{}-\text{}\mathrm{cos}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\left(\frac{\delta {\tau}_{1}}{{M}_{2}{L}_{1}}\text{}-\text{}\delta {L}_{2}{\dot{\theta}}_{2}^{2}\mathrm{sin}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}g\mathrm{cos}\left({\theta}_{1}\right)\right)}{{L}_{2}\left(1\text{}-\text{}\delta {\mathrm{cos}}^{2}\left({\theta}_{1}\text{}-\text{}{\theta}_{2}\right)\right)}\text{.(4}\text{.14c)}$$

In order to solve for the angles ${\theta}_{1}$ and ${\theta}_{2}$, we need to solve the above second-order system of ordinary differential equations. To do this, we first reduce the system into an equivalent system of first-order ordinary differential equations.

Let us introduce four new variables

$${u}_{1}\text{}=\text{}{\theta}_{1},{u}_{2}\text{}=\text{}{\theta}_{2},{u}_{3}\text{}=\text{}{\dot{\theta}}_{1},{u}_{4}\text{}=\text{}{\dot{\theta}}_{2}.\text{(4}\text{.15)}$$

After differentiating, we have

$${\dot{u}}_{1}\text{}=\text{}{\dot{\theta}}_{1}\text{}=\text{}{u}_{3},\text{}{\dot{u}}_{2}\text{}=\text{}{\dot{\theta}}_{2}\text{}=\text{}{u}_{4},\text{}{\dot{u}}_{3}\text{}=\text{}{\ddot{\theta}}_{1}\text{}=\text{}{g}_{1}\left(t,{u}_{1},{u}_{2},{u}_{3},{u}_{4}\right),\text{}{\dot{u}}_{4}\text{}=\text{}{\ddot{\theta}}_{2}\text{}=\text{}{g}_{2}\left(t,{u}_{1},{u}_{2},{u}_{3},{u}_{4}\right)$$

Thus, we obtain a system of first-order nonlinear differential equations of the form

$$\frac{dU}{dt}\text{=}S\left(t,U\right),\text{}U\left(0\right)\text{=}{U}_{0},\text{(4}\text{.16a)}$$

Where $U\text{=}{\left[{u}_{1},{u}_{2},{u}_{3},{u}_{4}\right]}^{t}$ and $S\text{=}{\left[{s}_{1},{s}_{2},{s}_{3},{s}_{4}\right]}^{t}$ with

$${s}_{1}\text{}=\text{}{u}_{3},\text{}{s}_{2}\text{}=\text{}{u}_{4},\text{}{s}_{3}\text{}=\text{}{g}_{1}\left(t,{u}_{1},{u}_{2},{u}_{3},{u}_{4}\right),\text{}{s}_{4}\text{}=\text{}{g}_{2}\left(t,{u}_{1},{u}_{2},{u}_{3},{u}_{4}\right)$$

The initial conditions are given by

$${U}_{0}\text{=}{\left[{u}_{1}\left(0\right),\text{}{u}_{2}\left(0\right),{u}_{3}\left(0\right),{u}_{4}\left(0\right),\right]}^{t},\text{(4}\text{.16b)}$$

Where,

$${u}_{1}\left(0\right)\text{}=\text{}{\theta}_{1}\left(0\right),\text{}{u}_{2}\left(0\right)\text{}=\text{}{\theta}_{2}\left(0\right),\text{}{u}_{3}\left(0\right)\text{}=\text{}{\dot{\theta}}_{1}\left(0\right),\text{}{u}_{4}\left(0\right)\text{}=\text{}{\dot{\theta}}_{2}\left(0\right)$$

The system (4.16a) subject to the initial condition (4.16b) can be solved for the unknown vector *U*, using, for example, the **ode45** command defined in MATLAB to solve the system of ordinary differential equations numerically. This command is based on the fourth-order Runge-Kutta method. For more details consult [2,11].

## PID Controller Design

Robotic manipulators are generally difficult to control. In particular, it is a challenging task to stabilize a robot manipulator at a fixed, accurate position. In this section, we focus mainly on control of the robot manipulator to get the desired position using computed torque control method. After deriving the equation of motion, control simulation is represented using MATLAB.

We define control as the ability to hold the system of two links in a particular position on the *xy*-plane. Having control gives us the ability to hold each link at a particular angle ${\theta}_{i}$ with respect to the positive *x*-axis. The proportional-integral-derivative (PID) controller is a common control algorithm. The "P" in PID stands for Proportional control, the "I" stands for Integral control, and the "D" stands for Derivative control. This algorithm works by defining an error variable *V _{error}* =

*V*-

_{set}*V*that takes the position we want to go (

_{sensor}*V*) minus the position we are actually at (

_{set}*V*). We get the proportional part of the PID control by taking a constant defined as

_{sensor}*K*and multiplying it by the error. The

_{P}**I**comes from taking a constant

*K*and multiplying it by the integral of the error with respect to time. Derivative control is defined as a constant

_{I}*K*multiplied by the derivative of the error with respect to time. Many industrial processes are controlled using PID controllers. Below is a table describing PID control Table 1.

_{D}The equations of motion (4.12) can be written compactly as

$$M\left(\theta \right)\ddot{\theta}\text{+}c\left(\theta ,\dot{\theta}\right)\text{+}G\left(\theta \right)\text{=}F,\text{(5}\text{.1)}$$

where,

$$\theta \text{=}\left[\begin{array}{c}{\theta}_{1}\\ {\theta}_{2}\end{array}\right],M\left(\theta \right)\text{=}\left[\begin{array}{cc}\left({M}_{1}\text{+}{M}_{2}\right){L}_{1}^{2}& {M}_{2}{L}_{1}{L}_{2}\mathrm{cos}\left({\theta}_{1}\text{-}{\theta}_{2}\right)\\ {M}_{2}{L}_{1}{L}_{2}\mathrm{cos}\left({\theta}_{1}\text{-}{\theta}_{2}\right)& {M}_{2}{L}_{2}^{2}\end{array}\right],$$

$$c\left(\theta ,\dot{\theta}\right)\text{=}\left[\begin{array}{c}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{2}^{2}\mathrm{sin}\left({\theta}_{1}\text{-}{\theta}_{2}\right)\\ \text{-}{M}_{2}{L}_{1}{L}_{2}{\dot{\theta}}_{1}^{2}\mathrm{sin}\left({\theta}_{1}\text{-}{\theta}_{2}\right)\end{array}\right],\text{}G\left(\theta \right)\text{=}\left[\begin{array}{c}\left({M}_{1}\text{+}{M}_{2}\right)g{L}_{1}\mathrm{cos}\left({\theta}_{1}\right)\\ {M}_{2}g{L}_{2}\mathrm{cos}\left({\theta}_{2}\right)\end{array}\right],F\text{=}\left[\begin{array}{c}{\tau}_{1}\\ {\tau}_{2}\end{array}\right]$$

We can solve for some theoretical values of forces given certain initial inputs. Solving for $\ddot{\theta}$ we get

$$\ddot{\theta}\text{=}\text{-}{M}^{-\text{1}}\left(\theta \right)\left[c\left(\theta ,\dot{\theta}\right)\text{+}G\left(\theta \right)\right]\text{+}\widehat{F},\text{(5}\text{.2)}$$

Where

$$\widehat{F}\text{=}{M}^{-\text{1}}\left(\theta \right)F$$

Thus, we decoupled the system to have the new input

$$\widehat{F}\text{=}\left[\begin{array}{c}{f}_{1}\\ {f}_{2}\end{array}\right]$$

However, the physical torque inputs to the system arė

$$F\text{=}\left[\begin{array}{c}{\tau}_{1}\\ {\tau}_{2}\end{array}\right]\text{=}M\left(\theta \right)\left[\begin{array}{c}{f}_{1}\\ {f}_{2}\end{array}\right]\text{(5}\text{.3)}$$

Let us denote the error signals by

$$e\left({\theta}_{1}\right)\text{=}{\theta}_{1f}\text{-}{\theta}_{1},\text{}e\left({\theta}_{2}\right)\text{=}{\theta}_{2f}\text{-}{\theta}_{2},$$

Where the target positions of *M _{1}* and

*M*are given by the angles ${\theta}_{1f}$ and ${\theta}_{2f}$, respectively.

_{2}We assume that the system has initial positions

$${\theta}_{0}=\left[\begin{array}{c}{\theta}_{1}\left(0\right)\\ {\theta}_{2}\left(0\right)\end{array}\right]$$

A common technique for controlling a system with input is to use the following general structure of PID controller

$$f={K}_{P}e\text{}+\text{}{K}_{D}\dot{e}\text{}+\text{}{K}_{1}{\displaystyle \int edt}.\text{(5}\text{.4)}$$

In our situation, the technique for controlling the double pendulum system with inputs *f _{1}* and

*f*

_{2}is to employ two independent controllers, one for each link, as follows

$${f}_{1}={K}_{{P}_{1}}{e}_{1}\left({\theta}_{1}\right)\text{}+\text{}{K}_{{D}_{1}}{\dot{e}}_{1}\left({\theta}_{1}\right)\text{}+\text{}{K}_{{I}_{1}}{\displaystyle \int e\left({\theta}_{1}\right)}dt={K}_{{P}_{1}}\left({\theta}_{1f}\text{}-\text{}{\theta}_{1}\right)\text{}-\text{}{K}_{{D}_{1}}{\dot{\theta}}_{1}\text{}+\text{}{K}_{{I}_{1}}{\displaystyle \int \left({\theta}_{1f}\text{}-\text{}{\theta}_{1}\right)}dt,$$

$${f}_{2}={K}_{{P}_{2}}{e}_{2}\left({\theta}_{2}\right)\text{}+\text{}{K}_{{D}_{2}}{\dot{e}}_{2}\left({\theta}_{2}\right)\text{}+\text{}{K}_{{I}_{2}}{\displaystyle \int e\left({\theta}_{21}\right)}dt={K}_{{P}_{2}}\left({\theta}_{2f}\text{}-\text{}{\theta}_{2}\right)\text{}-\text{}{K}_{{D}_{2}}{\dot{\theta}}_{2}\text{}+\text{}{K}_{{I}_{2}}{\displaystyle \int \left({\theta}_{2f}\text{}-\text{}{\theta}_{2}\right)}dt,$$

Where ${\theta}_{1f}$ and ${\theta}_{2f}$ are given constants.

The complete system of equations with control is then

$$\ddot{\theta}\text{=}-\text{}{M}^{-\text{1}}\left(\theta \right)\left[c\left(\theta ,\dot{\theta}\right)\text{+}G\left(\theta \right)\right]\text{+}\widehat{F},\text{(5}\text{.5)}$$

Where

$$\widehat{F}\text{=}\left[\begin{array}{c}{f}_{1}\\ {f}_{2}\end{array}\right]\text{=}\left[\begin{array}{c}{K}_{{P}_{1}}\left({\theta}_{1f}\text{-}{\theta}_{1}\right)-\text{}{K}_{{D}_{1}}{\dot{\theta}}_{1}\text{+}{K}_{{I}_{1}}{\displaystyle \int \left({\theta}_{1f}\text{-}{\theta}_{1}\right)}dt\\ {K}_{{P}_{2}}\left({\theta}_{2f}\text{-}{\theta}_{2}\right)-\text{}{K}_{{D}_{2}}{\dot{\theta}}_{2}\text{+}{K}_{{I}_{2}}{\displaystyle \int \left({\theta}_{2f}\text{-}{\theta}_{2}\right)}dt\end{array}\right]$$

We would like to emphasize that the actual physical torques are

$$\left[\begin{array}{c}{\tau}_{1}\\ {\tau}_{2}\end{array}\right]\text{=}M\left(\theta \right)\left[\begin{array}{c}{f}_{1}\\ {f}_{2}\end{array}\right]$$

To implement the PID controller, we introduce the following new states

$${x}_{1}={\displaystyle \int e\left({\theta}_{1}\right)}dt,\text{}{x}_{2}={\displaystyle \int e\left({\theta}_{2}\right)}dt$$

Differentiating with respect to *t* gives

$${\dot{x}}_{1}=e\left({\theta}_{1}\right)={\theta}_{1f}\text{}-\text{}{\theta}_{1},\text{}{\dot{x}}_{2}=e\left({\theta}_{2}\right)={\theta}_{2f}\text{}-\text{}{\theta}_{2}$$

The complete equations are

$${\dot{x}}_{1}={\theta}_{1f}\text{}-\text{}{\theta}_{1},\text{(5}\text{.6)}$$

$${\dot{x}}_{2}={\theta}_{2f}\text{}-\text{}{\theta}_{2},\text{(5}\text{.7)}$$

$$\left[\begin{array}{c}{\ddot{\theta}}_{1}\\ {\ddot{\theta}}_{2}\end{array}\right]\text{=-}{M}^{-\text{1}}\left(\theta \right)\left[c\left(\theta ,\dot{\theta}\right)\text{+}G\left(\theta \right)\right]\text{+}\left[\begin{array}{c}{K}_{{P}_{1}}\left({\theta}_{1f}\text{-}{\theta}_{1}\right)\text{-}{K}_{{D}_{1}}{\dot{\theta}}_{1}\text{+}{K}_{{I}_{1}}{x}_{1}\\ {K}_{{P}_{2}}\left({\theta}_{2f}\text{-}{\theta}_{2}\right)\text{-}{K}_{{D}_{2}}{\dot{\theta}}_{2}\text{+}{K}_{{I}_{2}}{x}_{2}\end{array}\right],\text{(5}\text{.8)}$$

$$\left[\begin{array}{c}{\tau}_{1}\\ {\tau}_{2}\end{array}\right]\text{=}M\left(\theta \right)\left[\begin{array}{c}{K}_{{P}_{1}}\left({\theta}_{1f}\text{-}{\theta}_{1}\right)\text{-}{K}_{{D}_{1}}{\dot{\theta}}_{1}\text{+}{K}_{{I}_{1}}{x}_{1}\\ {K}_{{P}_{2}}\left({\theta}_{2f}\text{-}{\theta}_{2}\right)\text{-}{K}_{{D}_{2}}{\dot{\theta}}_{2}\text{+}{K}_{{I}_{2}}{x}_{2}\end{array}\right]\text{(5}\text{.9)}$$

To discretize the above system of differential equations in time, we transform them into a system of first-order ordinary differential equations. To do this, we define six new variables as follows

$${u}_{1}\text{}=\text{}{x}_{1},\text{}{u}_{2}\text{}=\text{}{x}_{2},\text{}{u}_{3}\text{}=\text{}{\theta}_{1},\text{}{u}_{4}\text{}=\text{}{\theta}_{2},\text{}{u}_{5}\text{}=\text{}{\dot{\theta}}_{1},\text{}{u}_{6}\text{}=\text{}{\dot{\theta}}_{2},\text{(5}\text{.10)}$$

After differentiating, we have

$${\dot{u}}_{1}\text{}=\text{}{\dot{x}}_{1}\text{}=\text{}{\theta}_{1f}\text{}-\text{}{u}_{3},\text{}{\dot{u}}_{2}\text{}=\text{}{\dot{x}}_{2}\text{}=\text{}{\theta}_{2f}\text{}-\text{}{u}_{4},$$

$${\dot{u}}_{3}\text{}=\text{}{\dot{\theta}}_{1}\text{}=\text{}{u}_{5},\text{}{\dot{u}}_{4}\text{}=\text{}{\dot{\theta}}_{2}\text{}=\text{}{u}_{6},$$

${\ddot{u}}_{5}\text{}=\text{}{\ddot{\theta}}_{1}\text{}=\text{}\varphi \left(t,{u}_{1},{u}_{2},{u}_{3},{u}_{4},{u}_{5},{u}_{6}\right),\text{}{\ddot{u}}_{6}\text{}=\text{}{\ddot{\theta}}_{2}\text{}=\text{}\psi \left(t,{u}_{1},{u}_{2},{u}_{3},{u}_{4},{u}_{5},{u}_{6}\right)$,

were $\varphi $ and $\psi $ are expressed in terms of *u _{k}*,

*k*= 1-6, as

$$\left[\begin{array}{c}\varphi \\ \psi \end{array}\right]\text{=-}{M}^{-\text{1}}\left(\theta \right)\left[c\left(\theta ,\dot{\theta}\right)\text{+}G\left(\theta \right)\right]\text{+}\left[\begin{array}{c}{K}_{{P}_{1}}\left({\theta}_{1f}\text{-}{u}_{3}\right)\text{-}{K}_{{D}_{1}}{u}_{5}\text{+}{K}_{{I}_{1}}{u}_{1}\\ {K}_{{P}_{2}}\left({\theta}_{2f}\text{-}{u}_{4}\right)\text{-}{K}_{{D}_{2}}{u}_{6}\text{+}{K}_{{I}_{2}}{u}_{2}\end{array}\right],$$

and $\theta \text{=}\left[\begin{array}{c}{u}_{3}\\ {u}_{4}\end{array}\right]$.

A simple calculation shows that

$$\begin{array}{l}\varphi \text{}=\text{}\frac{-\text{}{M}_{2}{L}_{2}{u}_{6}^{2}\mathrm{sin}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\text{}-\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right)g\mathrm{cos}\left({u}_{3}\right)\text{}-\text{}{M}_{2}\mathrm{cos}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\left({L}_{1}{u}_{5}^{2}\mathrm{sin}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\text{}-\text{}g\mathrm{cos}\left({u}_{4}\right)\right)}{{L}_{1}\left({M}_{1}\text{}+\text{}{M}_{2}\text{}-\text{}{M}_{2}{\mathrm{cos}}^{2}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\right)}\\ \text{}+\text{}{K}_{{P}_{1}}\left({\theta}_{1f}\text{}-\text{}{u}_{3}\right)\text{}-\text{}{K}_{{D}_{1}}{u}_{5}\text{}+\text{}{K}_{{I}_{1}}{u}_{1},\end{array}$$

$$\begin{array}{l}\psi \text{}=\text{}\frac{\mathrm{cos}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\left({M}_{2}{L}_{2}{u}_{6}^{2}\mathrm{sin}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\text{}+\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right)g\mathrm{cos}\left({u}_{3}\right)\right)\text{}+\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right)\left({L}_{1}{u}_{5}^{2}\mathrm{sin}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\text{}-\text{}g\mathrm{cos}\left({u}_{4}\right)\right)}{{L}_{2}\left({M}_{1}\text{}+\text{}{M}_{2}\text{}-\text{}{M}_{2}{\mathrm{cos}}^{2}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\right)}\\ +\text{}{K}_{{P}_{2}}\left({\theta}_{2f}\text{}-\text{}{u}_{4}\right)\text{}-\text{}{K}_{{D}_{2}}{u}_{6}\text{}+\text{}{K}_{{I}_{2}}{u}_{2}\end{array}$$

Thus, we obtain a system of first-order nonlinear differential equations of the form

$$\frac{dU}{dt}\text{=}H\left(t,U\right),\text{}U\left(0\right)\text{=}{U}_{0},\text{(5}\text{.10)}$$

Where $U\text{=}{\left[{u}_{1},{u}_{2},{u}_{3},{u}_{4},{u}_{5},{u}_{6}\right]}^{t}$ and $H\text{=}{\left[{h}_{1},{h}_{2},{h}_{3},{h}_{4},{h}_{5},{h}_{6}\right]}^{t}$ with

$${h}_{1}\text{}=\text{}{\theta}_{1f}\text{}-\text{}{u}_{3},\text{}{h}_{2}\text{}=\text{}{\theta}_{2f}\text{}-\text{}{u}_{4},\text{}{h}_{3}\text{}=\text{}{u}_{5},\text{}{h}_{4}\text{}=\text{}{u}_{6},$$

$${h}_{5}\text{}=\text{}\varphi \left(t,{u}_{1},{u}_{2},{u}_{3},{u}_{4},{u}_{5},{u}_{6}\right),\text{}{h}_{6}\text{}=\text{}\psi \left(t,{u}_{1},{u}_{2},{u}_{3},{u}_{4},{u}_{5},{u}_{6}\right)$$

The initial conditions are given by

$${U}_{0}\text{=}{\left[{u}_{1}\left(0\right),\text{}{u}_{2}\left(0\right),\text{}{u}_{3}\left(0\right),\text{}{u}_{4}\left(0\right),\text{}{u}_{5}\left(0\right),\text{}{u}_{6}\left(0\right)\right]}^{t},$$

Where,

$${u}_{1}\left(0\right)\text{}=\text{}{x}_{1}\left(0\right),\text{}{x}_{2}\left(0\right)\text{}=\text{}{\theta}_{2}\left(0\right),\text{}{u}_{3}\left(0\right)\text{}=\text{}{\theta}_{1}\left(0\right),\text{}{u}_{4}\left(0\right)\text{}=\text{}{\theta}_{2}\left(0\right),\text{}{u}_{5}\left(0\right)\text{}=\text{}{\dot{\theta}}_{1}\left(0\right),\text{}{u}_{6}\left(0\right)\text{}=\text{}{\dot{\theta}}_{2}\left(0\right)$$

The system (3.10) can be solved for the unknown vector *U*, using, for example, the **ode45** command defined in MATLAB to solve the system of ordinary differential equations numerically. This command is based on the fourth-order Runge-Kutta method. For more details consult [2,11].

Once we solve for, we obtain to torques using $U\text{=}{\left({u}_{1},{u}_{2},{u}_{3},{u}_{4},{u}_{5},{u}_{6}\right)}^{t},$

$$\left[\begin{array}{c}{\tau}_{1}\\ {\tau}_{2}\end{array}\right]\text{}=\text{}M\left(\theta \right)\left[\begin{array}{c}{K}_{{P}_{1}}\left({\theta}_{1f}\text{}-\text{}{u}_{3}\right)\text{}-\text{}{K}_{{D}_{1}}{u}_{5}\text{}+\text{}{K}_{{I}_{1}}{u}_{1}\\ {K}_{{P}_{2}}\left({\theta}_{2f}\text{}-\text{}{u}_{4}\right)\text{}-\text{}{K}_{{D}_{2}}{u}_{6}\text{}+\text{}{K}_{{I}_{2}}{u}_{2}\end{array}\right],\text{(5}\text{.11)}$$

or equivalently,

$$\begin{array}{l}{\tau}_{1}\text{}=\text{}\left({M}_{1}\text{}+\text{}{M}_{2}\right){L}_{1}^{2}\left({K}_{{P}_{1}}\left({\theta}_{1f}\text{}-\text{}{u}_{3}\right)\text{}-\text{}{K}_{{D}_{1}}{u}_{5}\text{}+\text{}{K}_{{I}_{1}}{u}_{1}\right)\\ \text{}+\text{}{M}_{2}{L}_{1}{L}_{2}\mathrm{cos}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\left({K}_{{P}_{2}}\left({\theta}_{2f}\text{}-\text{}{u}_{4}\right)\text{}-\text{}{K}_{{D}_{2}}{u}_{6}\text{}+\text{}{K}_{{I}_{2}}{u}_{2}\right),\end{array}$$

$${\tau}_{2}\text{}=\text{}{M}_{2}{L}_{1}{L}_{2}\mathrm{cos}\left({u}_{3}\text{}-\text{}{u}_{4}\right)\left({K}_{{P}_{1}}\left({\theta}_{1f}\text{}-\text{}{u}_{3}\right)\text{}-\text{}{K}_{{D}_{1}}{u}_{5}\text{}+\text{}{K}_{{I}_{1}}{u}_{1}\right)\text{}+\text{}{M}_{2}{L}_{2}^{2}\left({K}_{{P}_{2}}\left({\theta}_{2f}\text{}-\text{}{u}_{4}\right)\text{}-\text{}{K}_{{D}_{2}}{u}_{6}\text{}+\text{}{K}_{{I}_{2}}z{u}_{2}\right)$$

## Simulations Results

The PID controller helps get the outputs, which are the final positions of *M _{1}* and

*M*determined by the angles ${\theta}_{1}$ and ${\theta}_{2}$, where we want it, in a short time, with minimal overshoot, and with little error. This will be demonstrated using the following examples.

_{2}
**Example 1.** We consider the simplified model of a two-link manipulator shown in Figure 1. In this experiment, we take the following parameters

$${M}_{1}\text{}=\text{}{M}_{2}\text{}=\text{}1,\text{}{L}_{2}\text{}=\text{}2,\text{}{L}_{2}\text{}=\text{}1\text{(6}\text{.1)}$$

The target positions (final positions) are $\left[\begin{array}{c}{\theta}_{1f}\\ {\theta}_{2f}\end{array}\right]\text{}=\text{}\left[\begin{array}{c}\pi /2\\ 0\end{array}\right]$.

The initial positions, initial angle velocities, and initial states are, respectively, taken as

$$\left[\begin{array}{c}{\theta}_{1}\left(0\right)\\ {\theta}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}\pi /2\\ \pi /2\end{array}\right],\text{}\left[\begin{array}{c}{\dot{\theta}}_{1}\left(0\right)\\ {\dot{\theta}}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}0\\ 0\end{array}\right],\text{}\left[\begin{array}{c}{x}_{1}\left(0\right)\\ {x}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}0\\ 0\end{array}\right]$$

The PID parameters for ${\theta}_{1}$ and ${\theta}_{2}$, are taken as

*KP _{1}* = 30,

*KD*= 15,

_{1}*KI*= 20,

_{1}
*KP _{2}* = 30,

*KD*= 10,

_{2}*KI*= 20.

_{2}
In Figure 2, we show the initial and target positions of the two-link manipulator. Next, we plot the positions ${\theta}_{1}$ and ${\theta}_{2}$ of *M _{1}* and

*M*versus time over the interval [0,30] in Figure 3.

_{2}
In Figure 4 we present the difference between where we want to go and where we are actually at *i.e*.,

$$e\left({\theta}_{1}\right)\text{}=\text{}{\theta}_{1f}\text{}-\text{}{\theta}_{1},\text{}e\left({\theta}_{2}\right)\text{}=\text{}{\theta}_{2f}\text{}-\text{}{\theta}_{2},$$

Where *θ _{1f}* and

*θ*are the target positions and

_{2f}*θ*

_{1}(t) and

*θ*

_{2}(t) are the numerical approximations obtained by solving the system of ODEs. These results indicate that the PID controller gets the final positions of

*M*and

_{1}*M*determined by the angles

_{2}*θ*

_{1}and

*θ*

_{2}, in a short time (almost 7 seconds) with very small error.

Finally, in Figure 5, we show the torques *f _{1}* and

*f*versus time

_{2}Note that the actual joints torques are

$$\left[\begin{array}{c}{\tau}_{1}\\ {\tau}_{2}\end{array}\right]\text{=}M\left(\theta \right)\left[\begin{array}{c}{f}_{1}\\ {f}_{2}\end{array}\right]$$

**Example 2**. We repeat the previous example with all parameters kept unchanged except for the final positions where we use

$$\left[\begin{array}{c}{\theta}_{1f}\\ {\theta}_{2f}\end{array}\right]\text{}=\text{}\left[\begin{array}{c}\pi /4\\ -\text{}\pi /4\end{array}\right]\text{(6}\text{.2)}$$

The initial and target positions of *M _{1}* and

*M*are shown in Figure 6. We present the positions

_{2}*θ*

_{1}and

*θ*

_{2}of

*M*and

_{1}*M*versus time in Figure 7. In Figure 8 we present the errors between the estimate positions and target positions. Finally, in Figure 9, we show the torques versus time. Once again, these results demonstrate that the PID controller gets the final positions of

_{2}*M*and

_{1}*M*in a short time (approximately 5 seconds).

_{2}
**Example 3**. In this example, we consider the two-link manipulator shown in Figure 1 with the following parameters

$${M}_{1}\text{}=\text{}{M}_{2}\text{}=\text{}1,\text{}{L}_{2}\text{}=\text{}2,\text{}{L}_{2}\text{}=\text{}1\text{(6}\text{.3)}$$

The initial positions, initial angle velocities, and initial states are, respectively, taken as

$$\left[\begin{array}{c}{\theta}_{1}\left(0\right)\\ {\theta}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}-\pi /2\\ \text{}\pi /2\end{array}\right]\text{,}\left[\begin{array}{c}{\dot{\theta}}_{1}\left(0\right)\\ {\dot{\theta}}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}0\\ 0\end{array}\right]\text{,}\left[\begin{array}{c}{x}_{1}\left(0\right)\\ {x}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}0\\ 0\end{array}\right].$$

The target positions (final positions) are $\left[\begin{array}{c}{\theta}_{1f}\\ {\theta}_{2f}\end{array}\right]\text{}=\text{}\left[\begin{array}{c}0\\ 0\end{array}\right]$.

The PID parameters for *θ*_{1} and *θ*_{2}, are taken as

*KP _{1}* = 30,

*KD*= 15,

_{1}*KI*= 20,

_{1}
*KP _{2}* = 30,

*KD*= 20,

_{2}*KI*= 20.

_{2}
The initial and target positions of the two-link manipulator are shown in Figure 10. In Figure 11 we present the positions *θ*_{1} and *θ*_{2} of *M _{1}* and

*M*versus time over the interval [0,30]. In Figure 12 we present the errors e(

_{2}*θ*

_{1}) and e(

*θ*

_{2}) between the target position and the estimate position found numerically. Again it takes only few seconds to get the target position. We would like to mention that the PID controller gets the final positions of

*M*and

_{1}*M*in a short time (approximately in seconds) with very small error. Finally, we show the torques

_{2}*f*and

_{1}*f*versus time in Figure 13.

_{2}
**Example 4**. Finally, we consider the two-link manipulator shown in Figure 1 with the following parameters

$${M}_{1}\text{}=\text{}{M}_{2}\text{}=\text{}1,\text{}{L}_{2}\text{}=\text{}2,\text{}{L}_{2}\text{}=\text{}1\text{(6}\text{.4)}$$

The initial positions, initial angle velocities, and initial states are, respectively, taken as

$\left[\begin{array}{c}{\theta}_{1}\left(0\right)\\ {\theta}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}-\text{}\pi /2\\ -\text{}\pi /2\end{array}\right]$ $\left[\begin{array}{c}{\theta}_{1}\left(0\right)\\ {\theta}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}\pi /2\\ \pi /2\end{array}\right]$$\left[\begin{array}{c}{x}_{1}\left(0\right)\\ {x}_{2}\left(0\right)\end{array}\right]\text{}=\text{}\left[\begin{array}{c}0\\ 0\end{array}\right]$

The target positions (final positions) are $\left[\begin{array}{c}{\theta}_{1f}\\ {\theta}_{2f}\end{array}\right]\text{}=\text{}\left[\begin{array}{c}0\\ 0\end{array}\right]$.

The PID parameters for *θ*_{1} and *θ*_{2}, are taken as

*KP _{1}* = 30,

*KD*= 15,

_{1}*KI*= 20,

_{1}
*KP _{2}* = 30,

*KD*= 20,

_{2}*KI*= 20.

_{2}
The initial and target positions of the two-link manipulator are shown in Figure 14. The positions *θ*_{1} and *θ*_{2} of *M _{1}* and

*M*versus time over the interval [0, 30] are shown in Figure 15. In Figure 16 we plot the errors e(

_{2}*θ*

_{1}) and e(

*θ*

_{2}) between the target position and the approximate position found numerically. As in the previous examples, it takes only few seconds to get the target position. Finally, we present the torques

*f*and

_{1}*f*versus time in Figure 17.

_{2}## Conclusion

In this paper, a two-link robotic manipulator was studied and its dynamics were modeled using Lagrange mechanics. First, we derived the dynamical equation of the two-link robot manipulators using Euler-Lagrange method and then a simple and efficient control scheme was developed. More specifically, a robust Proportional-Integral-Derivative (PID) controller was introduced to control the motion of the robot at a specific position. In particular, we described how a PID controller can be used to keep the links in a desired position. The efficiency of the PID controller is verified by the simulation results. The proposed research can be used to design and code control algorithms for a mobile robot. These algorithms allow us to balance upside-down pendulums on a mobile robot. There could be many solutions for coding this PID control depending on what sensors are used to find the angles of the links. In this study, we considered a planar robot having rotational joints. However, the PID controller presented in this paper can be extended for robots having prismatic joints. In the future, we are planning to consider complex joints such as a ball and socket joint.

## Acknowledgement

This project was funded by the Kerrigan Research Minigrant Program. The authors would like to thank the anonymous reviewer for the valuable comments and suggestions which improved the quality of the paper.

## Conflict of Interest

The Authors declare that there is no conflict of interest.