Converting a Non-Linear equation to canonical form
3 views (last 30 days)
Show older comments
I have an equation of Motion for a 2 link robotic arm such as:
EOM2 =
a2*(m2*lc2^2 + l1*m2*cos(q2)*lc2 + I2) - v2*(- (-l1*lc2*m2*sin(q2))*q_dot1 - (-l1*lc2*m2*sin(q2))*q_dot2) + a1*(m2*l1^2 + 2*m2*cos(q2)*l1*lc2 + m1*lc1^2 + m2*lc2^2 + I1 + I2) + g*m2*(lc2*cos(q1 + q2) + l1*cos(q1)) - q_dot2*v1*l1*lc2*m2*sin(q2) + g*lc1*m1*cos(q1)
I want to convert the EOM into a canonical form such that EOM = Y.θ where Y consists of symbolic variables like a,v and q. Here, a includes a1, and a2, v includes v1 and v2, and q includes q1, q2,, q_dot1, q_dot2, and any function that includes q like sin(q1) or sin(q1 +q2), cos(q2) and so on.
My approach was to first do it by hand and thus my Answer is:
% Y(a,v,q) Regressor matrix
Y1_Matrix = [a(1), cos(q(2))*a(1), cos(q(2))*a(2), a(1) + a(2), a(2), sin(q(2))*v(1)*q_dot(2),...
sin(q(2))*(q_dot(1)+q_dot(2))*v(2), cos(q(1)), cos(q(1)+q(2))];
Y2_Matrix = [0, 0, sin(q(2))*v(1)*q_dot(1)+a(1)*cos(q(2)), a(1) + a(2), a(1) + a(2), 0, 0, 0, cos(q(1)+q(2))];
Y_Matrix = [Y1_Matrix;Y2_Matrix]; % 2X9
% Theta is vector
Theta_Vector = [m2*l1^2 + m1*lc1^2 + I1 + I2;
2*m2*l1*lc2;
l1*m2*lc2;
m2*lc2^2;
I2;
-m2*l1*lc2;
-m2*l1*lc2;
g*m2*l1+g*lc1*m1;
g*m2*lc2]; % 9X1
EOM3 = Y_Matrix*Theta_Vector
I also found that there is a `collect()` function one could use to collect coefficients of variables such as:
collect(EOM2, [a(1), a(2), v(1), v(2), q(1), q(2), cos(q(1) + q(2)), cos(q(1)), sin(q(1)), cos(q(2)), sin(q(2))])
But the above approach becomes tedious when dealing with higher order robotic arm in future !!!
Questions:
- I wanted to see if there is a more elegant and faster approach to do so, specifically with anything related to q where I have to keep track of so many symbolic variables !!
- Also can I convert the collected coefficients directly into a Y.θ matrix*vector form without it reqriting myself ?
a2*(m2*lc2^2 + I2) + a1*(m2*lc2^2 + l1*m2*cos(q2)*lc2 + I2) + q_dot1*v1*l1*lc2*m2*sin(q2) + g*lc2*m2*cos(q1 + q2)
11 Comments
Walter Roberson
on 21 May 2020
Your Y for this example does not contain only symbolic variables in combination: it also contains 1. That was not a permitted option in your original formulation.
[theta, Y] = coeffs(EOM2, vars)
Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!