Adaptive Controller
Quite often we don't know the exact physical parameters for the system we want to control. Adaptive controller is one way to solve the problem. It uses the following equations to solve it. I will be going through explanations what each equation does.
Manipulator Equation:
M,C,N matrix for Double Pendulum:
- mass1 - m1
- mass2 - m2
- angle1 -q1
- angle2 -q2
- arm_length1 -a1
- arm_length2 -a2
Now we try to rewrite the equation in terms of the unknown parameter. For us it is m1 and m2 as we don't know the pendulum masses.
Now to design the Adaptive Controller We write the equation for torque along with defining the error space:
Using equation 6 we derive the following equations:
From Equation 12
The above equation can be coded using Eigen library in C++. Even without Eigen it can be done using vectors and arrays. To have a walkthrough please check my github link: https://github.com/Shubhranshu153/AdaptiveControllerCpp
Now we want to pick a lyapunov candidate Function. There is no particular way to do it but it is really important that it is positive and globally decreasing:
To get P we solve the lyapunov Equation:
We have to solve this equation numerically for C++. Matlab has a neat function. A c++ implementation is in the previous github link. To implement it i have followed the literature from this link- https://people.kth.se/~eliasj/NLA/matrixeqs.pdf
Another property of the lyapunov function is that the derivative of V is negative.
To get it we first differentiate V with respect to time and then set the following.
Now all this set we have to integrate our state equation with respect to time to observe the behavior of the dynamical system with respect to time. I have used runge kutta integration technique to do it. It is fairly accurate and the solution is comparable to the output given by matlab.
RESULT
Prediction of Mass over time. Our initial prediction for mass 1 is 2Kg and for mass2 is 3 Kg:
Desired angular trajectory we want the controller to follow
Desired angular velocity trajectory we want the controller to follow