1 Introduction

Robotic systems are extensively used in various complex engineering applications, where the demand for productivity, performance and safety during the operation is very high. Therefore, two-legged robots are used in non-industrial environments such as assisting doctors in hospitals and performing various tasks in hotels and industrial environments such as nuclear reactors, boilers clean-up, and space applications. A two-legged robot can walk on numerous surfaces such as flat, staircases, sloped surfaces, surfaces with ditches and roads made of sand and small stones in a real environment. However, it is challenging to make the two-legged robot accomplish the aforementioned tasks in a systematic manner on various terrains. In such situations, the controller plays a key role in enhancing the balance of the two-legged robot. On the other hand, tuning the gains of the proportional-integral-derivative (PID) controller in the field of control systems poses many problems, because the process is laborious and time consuming. In general, control system must be studied theoretically in the virtual domain by utilizing fewer assumptions and simplistic process. It is significant to note that the control problem related to the dynamic walking of the biped robot is more complicated than the static walking problem (Cheng and Lin 2000). In dynamic walking, the walking patterns are followed with a higher walking speed. Among all the above categories of walking patterns, the problem related to dynamically balanced walking is the most crucial and should be solved with a high degree of reliability. Finally, this question has motivated the formulation of several dynamically balanced criteria for obtaining balanced biped walk. The concept of zero moment point (ZMP) (Vukobratovic and Borovac 2004) was used by many researchers to obtain a dynamically balanced gait for a two-legged robot. To introduce more natural and stable walking pattern for a two-legged robot, Nguyen et al. (2016) proposed a novel gait generation method by using differential evaluation and artificial neural network algorithms. The authors had concluded that the developed method was easy and did not require much mathematical computations when compared with the conventional methods that used the concept of zero moment point. In Zang et al. (2016), the authors had developed a novel pneumatic musculoskeletal two-legged robot and proposed a suitable PID controller. There, the joints of lower limbs of the two-legged robot were driven by the muscles. This helped them to achieve the desired position for all joints. Further, to achieve the real-time stable walk for the two-legged robot, Kajita (2017) had proposed concept of inverted pendulum and its control by using a suitable feedback system.

PID controller tuning is an important process for autonomous robotic systems to complete the task assigned to them. Previously, many researchers focused on controlling robots by using a proportional and derivative controller (Slotine and Li 1991; Chu et al. 2008), PID controller (Shamna et al. 2017), computed torque controller (Kelly et al. 2005), energy efficient support vector machine learning controller (Wang 2013), adaptive controller (Yoo et al. 2007), fuzzy network (Hojati and Gazor 2002), neural network (NN) (Juang 2001), and fuzzy NN controller (Wai and Muthusamy 2013). Subsequently, a recurrent NN was used to compensate for the control signal of a seven-link two-legged robot (Wu et al. 2007). Furthermore, a novel foot force and body posture controllers were developed for a 42-DOF biped robot (Kajita 2010). The legged robotic system was considered as a humble linear inverted pendulum to solve the control problem. Moreover, a predictive-based PID controller that imitated the calculated time with reduced complexity to generate smooth and efficient walking was developed (Bouhajar et al. 2015). Note that some research was conducted on the dynamic balance of a two-legged robot by utilizing a ZMP-based regulator. Jimenez et al. (2013) developed an angular-momentum-based controller that increased the walking stability of the robot by using the preview control method for the ZMP. Moreover, a fuzzy control policy (Wu and Hwang 2011) was developed for a two-legged robot to generate dynamically balanced gaits while walking. To maintain ground contact, the authors used a simplified inverted pendulum model instead of the spring or damper ground model. Finally, the proposed controller was compared with the PID controller by conducting simulations and in practical. Furthermore, in a study, the stability of a two-legged robot was controlled using the ZMP-based trajectory controller (Aghbali and Koma 2013a), that is, PID and fuzzy controller with and without external disturbances. Here, the included angle made by the joints was set by an offline method. Moreover, an adaptive neuro PID controller was implemented by Anh et al. (2014) to optimize the gain scheduling and PID parameters of the multilayer feed forward NN. The algorithm was tested on a full size humanoid robot, and the algorithm’s performance was observed to be better than that of the conventional PID controller. Koker et al. (2014) designed a neural network committee machine (NNCM) for solving the inverse kinematics of a robotic manipulator. The developed method had shown better performance when compared with the results obtained from the algebraic, iterative and geometric approaches. Furthermore, Londhe and Patre (2018) developed an adaptive fuzzy sliding mode control for an autonomous underwater vehicle to achieve the robust trajectory tracking. Initially, the rules of the fuzzy controller were derived by using the Lyapunov energy function, which was used to minimize the chattering of the control signal. Finally, to enhance the stability of the system, an adaptive control law was established to adapt the fuzzy consequent parameter of a fuzzy logic controller. Alongside, for fine-tuning of the PID controller still researchers are using artificial neural network (Malekabadi et al. 2018) whose weights are tuned with the help of genetic algorithms. Moreover, Satoh and Fujimoto (2018) proposed a torso and knee trajectory learning and state-transition estimation method for generating the gait for the robot. They used a novel technique to generate the optimal gaits and to avoid the foot-scuffing problem. Clever et al. (2018) discussed the gait generation method used for the humanoid robot to move in complex environments. This method was based on the concept of template models and the optimality principles learned from the human beings.

After a through literature review, the contributions made in this research work are listed as follows:

  • The ZMP-based PID controller used in most of the studies was replaced by a torque-based PID controller that helps in straight away reducing the error between the target and actual angular positions of various joints. However, the ZMP-based controller is not a direct method of regulating the motors. Moreover, there is no guarantee that the gaits produced by the ZMP-based PID controller are not going to exhibit the sequence-oriented gaits that fulfill the repeatability conditions.

  • Most of the research work on the design of controller for a two-legged robot is pertained to decide the optimal values of the gains that are accountable for a smooth execution of the gaits designed by a gait planner. Note that the magnitude of error between the target and actual angular displacement is not the same during the control. These demands variation in the gain values to quickly minimize the error. However, this minimization cannot be obtained by using the optimal controller, because the obtained gain values are fixed during the process. This problem is eliminated using the proposed adaptive controller, because the NN performs the task of providing adaptive gains that correspond to the change in the magnitude of the error signal received at its input node.

  • In the present study, a revised form of the invasive weed optimization procedure is proposed to train the NN’s architecture that predicts the gains of the controller in an adaptive manner. The modification is performed by introducing the cosine and chaotic variables in the spatial dispersal phase. These variables enable the algorithm to enhance the search space and diminish the likelihood of trapping their solutions in the local optimum. To avoid computational complexity, the adaptive controller design for the lower limbs of the biped robot, which plays a major role while moving on various terrains, is only considered.

The present paper is structured as follows: The introduction related to the dynamics of the two-legged robot is presented in Sect. 2. Section 3 describes the adaptive controller, that is, the MCIWO-NN algorithm. The results related to the simulations and experiments are presents in Sect. 4. Finally, the conclusions are specified in Sect. 5.

2 Two-legged robot dynamics

The physical structure of the real two-legged robot used in this research is shown in Fig. 1. The dynamics associated with the two-legged robot have been determined by utilizing Lagrange–Euler (L–E) formulation. These L–E formulation is used to decide the required torques at numerous joints of the two-legged robot as mentioned below.

$$ \tau_{i} = \sum\limits_{j = 1}^{n} {M_{ij} \left( q \right)\dot{q} + \sum\limits_{j = 1}^{n} {\sum\limits_{k = 1}^{n} {h_{ijk} \dot{q}_{j} \dot{q}_{k} + G_{i} } } } \;\;\;i,j,k = 1 \ldots n $$
(1)

where τi represents the torque required at joint i due to the motion of links, q denotes the movement (m) of the joint, \(\dot{q}_{j}\) indicates the velocity (m/sec) of the joint, and \(\dot{q}_{j}\) represents the acceleration (m/sec2) of the joint. Furthermore, the enlarged form of inertia term, Coriolis/centrifugal term and gravity term are discussed below.

$$ M_{ij} = \sum\limits_{{p = \max \left( {i,j} \right)}}^{n} {Tr\left[ {d_{pj} I_{p} d_{pi}^{T} } \right]} \;\;\;i,j,k = 1 \ldots n $$
(2)
$$ h_{ijk} = \sum\limits_{{p = \max \left( {i,j,k} \right)}}^{n} {Tr\left[ {\frac{{\partial \left( {d_{pk} } \right)}}{{\partial q_{p} }}I_{p} d_{pi}^{T} } \right]} \;\;\;i,j,k = 1 \ldots n $$
(3)
$$ G_{i} = - \sum\limits_{p = i}^{n} {m_{p} gd_{pi} {}_{e}^{p} \overline{r}_{p} } \;\;\;i,j,k = 1 \ldots n $$
(4)

where Ip and \({}_{e}^{p} \overline{r}_{p}\) denote the moment of inertia tensor (Kg·m/sec2) and mass center of the pth link (m), respectively, and ‘g’ indicates the acceleration due to gravity (m/sec2).

Fig. 1
figure 1

Motion of the two-legged robot on flat surface

3 Design of the PID controller

The controller has to play a main role on biped robots to maintain the dynamic balance. Moreover, the controller will supply the torque that is required by the individual joint to move from an initial position to final position. The main aim of the PID controller is to diminish the error between the actual process variable to the reference of the system. In the present research work, the authors developed a torque-based PID controller which will control all the joint motors individually. The required PID controller equation, which is helpful to control the joint motors individually, has been formulated after solving the dynamics of the two-legged robot and is given in Eq. 5.

$$ \tau_{{{\text{act}}}} = K_{p} e\left( t \right) + K_{p} \frac{{{\text{d}}e\left( t \right)}}{{{\text{d}}t}} + K_{i} \smallint e\left( t \right){\text{d}}t $$
(5)

where e(t) represents the error in the joint displacement and Kp, Kd, and Ki indicate the proportional, derivative, and integral gains of the controller. Further, the expanded form of Eq. (5) after inserting the meaning of e(t) is given in Eq. (6) and (7).

$$ e\left( {\theta_{i} } \right) = \theta_{if} - \theta_{is} $$
(6)
$$ \tau_{{i,{\text{act}}}} = K_{pi} \left( {\theta_{if} - \theta_{is} } \right) - K_{di} \dot{\theta }_{is} + K_{ii} \smallint e\left( {\theta_{is} } \right){\text{d}}t\;\;\;i = 1 \ldots n $$
(7)

where \(\tau_{{i,{\text{act}}}}\) denotes the actual torque supplied by the individual motor to the joints for moving from an initial angular position (\(\theta_{is} )\) to the final angular position (\(\theta_{if} )\). The final control equation (ref. Equation 8) which is used to perform the control action for all joints.

$$ \ddot{q}_{j} = \mathop \sum \limits_{j = 1}^{n} M_{ij} \left( q \right)^{ - 1} \left[ { - \mathop \sum \limits_{j = 1}^{n} \mathop \sum \limits_{k = 1}^{n} h_{ijk} \dot{q}_{j} \dot{q}_{k} - G_{i} } \right] + K_{pi} \left( {\theta_{if} - \theta_{is} } \right) - K_{di} \dot{\theta }_{is} + K_{ii} \smallint e\left( {\theta_{is} } \right){\text{d}}t $$
(8)

Moreover, the integral term in Eq. (8) should be replaced by its state variables and it is given in Eq. 9.

$$ x_{i} = \smallint e\left( {\theta_{is} } \right){\text{d}}t \cong \dot{x}_{i} = \theta_{if} - \theta_{is} \;\;\;i = 1 \ldots n $$
(9)

3.1 MCIWO-NN PID controller

The developed torque-based PID controller has been designed to achieve the stable walking of the biped robot on various terrains such as flat surface, ascending and descending the stair and sloping surfaces. Tuning of the PID controller using the manual process is a trial and error method, and it consumes more time. Further, the optimal PID controller provides only one set of optimal values for the proportional, integral, and derivative gains that are used by the controller to execute the gaits. To overcome these drawbacks, many researchers around the world are working on this problem. However, in the present research work, the authors present an adaptive controller (i.e. NN-based PID controller) that generates variable gains on the basis of the magnitude of the error signal. Moreover, to optimize the weights of the neural network structure, the authors used a novel optimization algorithm (i.e. MCIWO). The fitness of the NN can be enhanced by improving its structure by using MCIWO algorithm. Figure 2 displays the flowchart of operation of MCIWO-NN algorithm. The detailed description of the NN algorithm and MCIWO algorithm is discussed in the following subsections.

Fig. 2
figure 2

Flowchart of the developed MCIWO-NN approach

3.2 Neural network

The neural network consists of junctions which are connected with the help of simple processing units to process the data. The structure of the network (that is, shown in Fig. 3) consists of three layers, that is, input, hidden and output layers, and each layer consists of number of neurons. The weighted sum of the inputs and the bias values are added to each neuron, and the values are passed through transfer functions. The transfer functions, namely linear, log-sigmoid and tan-sigmoid functions, are assigned to the input, hidden and output layers, respectively. The error between the target and the actual angular displacement of various joints at different intervals is fed as inputs to the network (that is, ∆θ1, ∆θ2, ∆θ3, ∆θ4, ∆θ5, ∆θ6, ∆θ7, ∆θ8, ∆θ9, ∆θ10, ∆θ11, and ∆θ12). The gains of the PID controller, such as Kp, Kd, and Ki, for all the twelve controllers are considered as outputs of the network. The RMS deviation of the angular displacement between the end of each interval (∝ ijkf) and the beginning of each interval (∝ ijks) is considered as the fitness (f) of each population and is given below.

$$ f = \frac{1}{d} \mathop \sum \limits_{i = 1}^{d} \left[ {\frac{1}{b}\mathop \sum \limits_{j = 1}^{b} \sqrt {\frac{1}{2}\mathop \sum \limits_{k = 1}^{p} \left( {\alpha_{ijkf} - \alpha_{ijks} } \right)^{2} } } \right] $$
(10)

where ‘d’ is the number of training scenarios, ‘b’ is the number of intervals considered in one step, and ‘p’ is the number of joints for which the controllers are designed.

Fig. 3
figure 3

Working structure of the NN

3.3 Modified chaotic invasive weed optimization algorithm

The IWO is a nature inspired optimization algorithm introduced by Mehrabian and Lucas (2006), and it was motivated from the colonization phenomenon of invasive weeds in nature. Moreover, it is a powerful optimization algorithm which can be formed by mimicking the properties of invasive weeds. The weed colonization behavior in a cropping field is explained in Fig. 4.

Fig. 4
figure 4

Flowchart of the MCIWO algorithm operation

3.3.1 Initialization

Initially, a finite number of weeds are dispersed randomly in a D-dimensional space. In the present problem, the gains, i.e., Kp, Kd and Ki, are considered as weeds of the problem.

3.3.2 Reproduction

The dispersed weeds grow into flowering plants after using the unused resources and produce the new seeds. Further, the fitness of each plant will be evaluated based on the no. of seeds produced. In the present problem, the average angular positional error of the PID controllers is considered as the fitness. Once the fitness is evaluated, the process of reproduction starts to determine the number of seeds produced by the plant. The fitness of the weed is increased from the lower to higher in a linear manner on the basis of the number of seeds present in a weed (ref. Figure 5) (Naidu and Ojha 2015). A better fitness weed produces a high number of seeds, and the worst fitness weed produces the least number of seeds. The advantage of this algorithm is that all the weeds are participated in the solution space and to identify the weed with the less fitness value also it gives some useful information while in the evolution process (Affolter et al. 2016). Moreover, the number of produced seeds (S) which are generated by each weed is calculated using Eq. 11.

$$ S = {\text{Floor}}\left[ {S_{\min } + \frac{{f - f_{\min } }}{{f_{\max } - f_{\min } }} \times S_{\max } } \right] $$
(11)

where fmin and fmax represent the minimum and maximum fitness value in the colony, and Smin and Smax indicate the minimum and maximum production of each plant, respectively.

Fig. 5
figure 5

Reproduction process in a colony of weeds

3.3.3 Spatial dispersal

In this stage, the produced seeds are circulated over the solution space by using the normally distributed random number with mean zero and changing standard deviation values. Due to the change in the variance value, the new seeds are distributed around the parent weed. The standard deviation (\(\sigma_{{{\text{Gen}}}}\)) of the distribution at the end of each generation reduces nonlinearly over the generations and is given as below:

$$ \sigma_{{{\text{Gen}}}} = \frac{{\left( {{\text{Gen}}_{\max } - {\text{Gen}}} \right)^{n} }}{{({\text{Gen}}_{\max } )^{n} }} \times \left( {\sigma_{{{\text{initial}}}} - \sigma_{{{\text{final}}}} } \right) + \sigma_{{{\text{final}}}} $$
(12)

where \({\text{Gen}}_{\max }\) is the maximum number of generations; \(\sigma_{{{\text{Initial}}}}\) and \(\sigma_{{{\text{Final}}}}\) represent the initial and final standard deviation, respectively; and n represents the modulation index.

To improve the performance of the algorithm, two terms known as the chaotic variable (Mohamadreza and Hamed 2012; Mojtaba et al. 2014) and cosine variable (Aniruddha et al. 2010; Roy et al. 2011) are added during the spatial dispersal phase. In IWO, the seeds are dispersed after the normal distribution. However, in the present problem, the chaotic random number is employed to distribute the seeds. This reduces the number of chances of the solution to be trapped in the local optimum while conducting the search. The chaotic random number used in the present study is given in Eq. 13.

$$ X_{k + 1} = \cos \left( {k\,\cos^{ - 1} \left( {X_{k} } \right)} \right) $$
(13)

For exploring the search space in an improved manner, the cosine term is added. The main aim of introducing the cosine term which is responsible for to increase the search space in a way such that it will utilize less resources. Once the cosine term is introduced, Eq. 14 can be restructured into the following form.

$$ \sigma_{{{\text{Gen}}}} = \frac{{\left( {{\text{Gen}}_{\max } - {\text{Gen}}} \right)^{n} }}{{({\text{Gen}}_{\max } )^{n} }} \times \left| {\cos \left( {{\text{Gen}}} \right)} \right| \times \left( {\sigma_{{{\text{initial}}}} - \sigma_{{{\text{final}}}} } \right) + \sigma_{{{\text{final}}}} $$
(14)

3.3.4 Competitive exclusion

Finally, the developed seeds are grow into a flowering weed and are located in the weed colony along with the parent weeds and the elimination is performed based on the fitness value. Based on the fast reproduction of the seeds, the population size in the search space will cross its maximum limit (Pmax) after some generations. Once the maximum population (Pmax) is reached, the less fit weeds are excluded, and the weeds that have superior fitness are used for the subsequent generation. Further, the above procedure is repeated until the termination condition is reached.

4 Results and discussion

In the present research work, adaptive-based PID controllers are developed to control the motors mounted on the joints of the legs, that is, on both sagittal and frontal planes. To evaluate the performance of the proposed controller, simulation studies are conducted on the two-legged robot while moving on varying terrains—flat surface, ascending and descending the staircase, and sloped surface. Once the results of simulation are achieved, the gaits obtained by the adaptive controller are fed to the real two-legged robot to validate the results of simulation. The various parameters related to the two-legged robot are given in Table 1.

Table 1 Parameters related to the two-legged robot

4.1 Performance tests

The performance assessment of the developed MCIWO methodology is tested by utilizing SPSS software. The said tests are conducted on a set of 5 benchmark functions with the dimension size of 10 (see Table 2) that are available in the literature (Mirjalili and Hashim 2010), and one real-world problem related to the development of an adaptive controller for the two-legged robot.

Table 2 The benchmark functions used in the present work

The performance metrics related to the effectiveness, robustness and reliability of MCIWO are compared with IWO, PSO and DE (Mandava and Vundavilli 2018b) algorithms, respectively. The standard deviation and mean values of the said algorithms are given in Table 3. To compare the performance of the algorithms, the no. of iterations and average runs for which the algorithms need to run are kept fixed at 2000 and 30, respectively. It can be seen that the MCIWO approach is found to provide better values for standard deviation when compared to IWO, PSO and DE for the test functions 1, 3 and 4. But the test functions 2 and 5 are seen to provide slightly better value with the PSO algorithm when compared with the other two approaches. Moreover, the mean values of all the standard test problems of MCIWO approach are seen to outperform both the IWO and PSO methodologies.

Table 3 Performance test results of PSO, IWO and MCIWO

4.2 Normality Test

In addition to the above performance tests, a normality test has also been conducted for 5 benchmark functions that specify the absence/presence of test of normality in the examined statistics. In the current research study, the authors have conducted two types of tests of normality such as Shapiro–Wilk (S–W) and Kolmogorov–Smirnov (K–S) which are used to examine the normality. In the above case study, the significance value level is kept equal at 0.05. However, the p value is found to be higher than the significance value. Based on the above reason, only the condition of normality is said to be fulfilled.

Here, the functions that are not fulfilling the condition of normality are denoted by symbol “ + ” in superscript. Moreover, it has also been observed that the functions 2 and 3 in PSO, 2 in DE, 1 and 10 in IWO and 1, 4 and 5 in MCIWO methodologies are seen to fulfill the condition of normality for both S-W and K-S methods (Table 4).

Table 4 The results related to the normality tests

4.3 Parametric and nonparametric tests

In this research, the nonparametric and parametric tests, such as Wilcoxon and paired t-test, are conducted to check the pairwise statistical significance between MCIWO, IWO, DE and PSO algorithms. The significance level during these tests is taken as 0.05 for both the Wilcoxon and paired t-tests. Table 5 gives the results obtained during the above tests. The null hypothesis during the present study is kept fixed as follows: H0: There is no variation in the performance of the algorithms developed; however, the alternative hypothesis is defined as follows: H1: There is a variation in the performance of the algorithms developed in this study. More information related to this study is available in Derrac et al. (Derrac et al. 2011).

Table 5 The p values related to the paired t-test and Wilcoxon test

From Table 5, it can be observed that for test problems 1, 3, 4 and 5, the significance values are seen to be less than the value of p. From the above condition, it is concluded that the said test functions satisfy the signed rank test related to Wilcoxon test. Furthermore, for the function 2, the value of p is seen to be higher than the significance value and does not satisfy the Wilcoxon test.

In addition to the above study, paired t-test is also conducted on the said functions. The value of p for the test problems 1, 4 and 5 is realized to be smaller than the significance value for MCIWO with IWO. Moreover, the value of p for the test problems 1, 3, 4, 5 is less than the significance value for MCIWO and DE. Further, the paired t-test results between MCIWO and PSO for test problems 3, 4 and 5 show that their p values are realized to be smaller than the significance value. However, the values of p are less than 0.05 for function 5 in all the scenarios. Once the proposed MCIWO methodology is checked in terms of its convergence condition, the said approach is used to solve a real problem concerned with the tuning of PID controller of a two-legged robot while walking on a flat surface. Further, the results of this algorithm related to the two-legged robot have been compared with the help of the PSO based PID controller.

Once the controller is designed, PID controller gains are tuned for the two-legged robot while walking on various surfaces by using the MCIWO-NN algorithm. Note that the prediction capability of NN highly depends on its architecture. A study was conducted to decide the number of hidden neurons in the hidden layer. The number of hidden neurons that provide better fitness when compared with other structures is observed to be 16. The number of input and output neurons that correspond to the inputs and outputs of the process are observed to be 12 and 36, respectively. The number of connecting weights in the network is found to be equal to 768 (12 × 16 + 16 × 36). Moreover, two bias values one for the hidden and output layers each are introduced into the network. Therefore, the total number of variables required to optimize the structure of NN is 770. While solving the problem in the present study, the connecting weights are varied between 0.0 and 1.0, and the bias values are varied between 0.0 and 0.0001. In addition to the above variables, the coefficients of transfer functions, that is, linear, tan-sigmoid, and log-sigmoid that correspond to the input, hidden, and output layers, respectively, are also included in the string. A parametric study is conducted to determine the optimal parameters of the MCIWO algorithm that optimizes the structure of NN. While conducting a parametric study, the input parameters related to the proposed algorithm, that is, the initial population, final population, modulation index, maximum and minimum number of seeds, final and initial standard deviation, and number of generations, are kept fixed at 5, 15, 3, 5, 0, 0.00001, 3 and 20. The optimal parameters related to the MCIWO algorithm while the two-legged robot moving on various terrains are listed in Table 6.

Table 6 Optimal parameters related to the MCIWO algorithm while the two-legged robot is walking on various surfaces

Once the optimal structure for the MCIWO-NN-based PID controller was obtained, a comparative study was conducted for the two-legged robot in terms of the angular error, average torque required at various joints, ZMP, and dynamic balance margin of the two-legged robot while walking on various terrains.

The error magnitude corresponding to the various joints of the swing and stance legs of the two-legged robot is displayed in Fig. 6. For all the joints, the magnitude of error is very high initially and decreases slowly with time interval. The main aim of this research work is to minimize the error between the actual and desired torque. It can also be observed that the error is minimized in the range of ±0.07 for all the joints within 4 to 5 ms time interval. Moreover, the error generated at various successive joints of the two-legged robot while walking on a flat surface is less than that generated when the two-legged robot is ascending and descending on a staircase and sloped surface. This phenomenon may be due to the difference between the two subsequent angles of a two-legged robot’s joint is low while walking on a flat surface as compared with that between the two subsequent angles of a two-legged robot’s joint while walking on other surfaces.

Fig. 6
figure 6

Variation of the angular error at various joints: a joint 2, b joint 3, c joint 4, d joint 5, e joint 8, f joint 9, g joint 10, and h joint 11

Figure 7 displays the torque required at various joints of the two-legged robot while walking on various terrains. The average torque required is seen to be more while ascending the staircase and less while walking on a flat surface. This may be because the angular variation between the successive joints is more while ascending the staircase. Furthermore, the torque required at joint 3 is high when compared with the torque required at the other joints of the two-legged robot. The reason of this difference may be that joint 3 carries other links and joints of the two-legged robot while moving the swing leg from one position to another. It might have occurred due to the large angular displacement obtained at that joint. This assumption is verified from the error plots in which the convergence requires more time (Fig. 5b).

Fig. 7
figure 7

Variation of torque required at different joints

The variation of the ZMP location in the foot support polygon for the two-legged robot while walking on a flat surface, ascending and descending a staircase, and sloped surface are displayed in Fig. 8. The position of ZMP is observed to lie inside the foot support polygon for all the cases. Therefore, the motion of the two-legged robot is considered to be dynamically balanced in all the cases. The flat surface movement of the two-legged robot is observed to be more balanced as the location of the ZMP for the flat surface walk is closer to the center of the support foot as compared with the location of the ZMP for all other walks (that is, ascending and descending the staircase and sloped surface). The location of ZMP is slightly away from the center of the foot support polygon for the sloped surface walking compared with the location of ZMP for the flat surface and staircase walking. This might be due to the fact that in the case of the sloped surface, the projection of the foot support is considered instead of the length of the foot (that is, foot is along the slope surface) to determine the location of ZMP. Therefore, the location of ZMP for the sloped surface walking is pushed away from the center of the foot when compared with the flat surface and staircase walking. This fact has also been confirmed from Fig. 9, which shows the variation of DBM in the X and Y directions. The DBM is determined by the location of ZMP from the end of the foot support polygon. The flat surface gait provides high balance values for the X and Y directions when compared with that provided by other walking cases (that is, staircase and sloped surfaces). This observation matches with the natural walking behavior of human beings on the specified terrains. The reason for this is the same as the one explained above.

Fig. 8
figure 8

Variation of the ZMP in the X and Y directions

Fig. 9
figure 9

Average X and Y DBM on various terrains

After conducting the simulations and observing the performance of the adaptive controller, the gait angles generated by various joints of the two-legged robot are fed into the real two-legged robot to evaluate the practical performances. All the aforementioned gaits are dynamically balanced in nature. Moreover, Figs. 10, 11, 12, 13, and 14 display the two-legged robot walking on flat surface, ascending and descending the staircase, and sloped surfaces at various instances.

Fig. 10
figure 10

Two-legged robot walking on a flat surface

Fig. 11
figure 11

Two-legged robot ascending a staircase

Fig. 12
figure 12

Two-legged robot descending a staircase

Fig. 13
figure 13

Two-legged robot walking on ascending the sloping surface

Fig. 14
figure 14

Two-legged robot walking on a descending sloped surface

4.4 Comparison with previous studies

In the present study, the authors have conducted a quantitative and qualitative comparison with the works available in the literature. The results of quantitative comparison of the proposed algorithm with the algorithms available in the literature such as, PSO and MCIWO (Mandava and Vundavilli 2018a) are shown in Fig. 15. It can be observed that the MCIWO-NN-based adaptive controller is found to consume less amount of torque when compared with other algorithms namely, PSO, MCIWO (Mandava and Vundavilli 2018a) and PSO-NN algorithm on all terrain conditions.

Fig. 15
figure 15

Schematic diagram showing the comparison of average torque required for various algorithms

In the literature (Shih 1999; Huang et al. 2001; Chiang and Chiang 2013; Vundavilli and Pratihar 2011; Mousavi and Bagheri 2007; Ranjbar and Mayorga 2017; Bagheri et al. 2010), the researchers considered a 7-DOF two-legged robot for generating gaits on various surfaces, and they only used the analytical approach to solve the related problems. In this study, the authors not only considered the gait generation algorithm on various terrains but also designed an adaptive-based PID controller (that is, MCIWO-NN) that helps in gait execution in a smooth manner. In addition to the above statement, the investigators in Jimenez et al. (2013), Aghbali and Koma (2013b), Kajita et al. (2010), Park et al. (2009), Engelbrecht (2007) developed a ZMP-based PID controller, which is an indirect way of controlling the motors mounted on the joints of the two-legged robot. However, in the present study, the authors developed a torque-based PID controller, which directly caters to the error in the angular displacements of the motors. Moreover, in Yau et al. (2008), Hang et al. (2002), Fister et al. (2016), Varol and Bingul (2004), the researchers used an evolutionary algorithm that could provide only one set of gain values for the controller for tuning it. In the present research, the authors have developed an adaptive-torque-based PID controller that can produce variable gains based on the magnitude of the error signal at the controllers input.

5 Conclusions

The present paper has successfully developed an innovative MCIWO-NN-based adaptive PID controller for real-time applications for two-legged robot walking on various terrains. The results demonstrate that the proposed adaptive-based PID controller can learn the highly nonlinear and dynamic features of the two-legged robotics and quickly reduce the tracking error to zero when it is walking on a flat surface. Moreover, while ascending and descending a staircase and while walking on a sloped surface, the tracking error reduces to zero after a few milliseconds. The torque required, and dynamic balance margin of the two-legged robot is high while the robot ascends the staircase and moves on a flat surface, respectively. Moreover, the proposed MCIWO-NN-based PID controller is capable of modifying the PID parameters Kp, Kd, and Ki in real time, and the actual gait can be monitored. The results of the algorithm are validated on a real two-legged robot. Further, this work can also be extended to cross a ditch, avoiding obstacle, walking on a rough terrain filled with sand and stones. In the present work, no damping effect is considered between the foot–ground interactions of the biped robot while landing its swing foot. This may cause the vibrations to transmit into the body of the robot and may influence the dynamic balance of the biped robot. Therefore, in future attempts will be made to model the foot–ground interaction as a multi-DOF system to have a smooth walk of the biped robot on various terrains.