We are trying to transfer controller from C++ to MATLAB.
Then we realized subtract or multiplying of vector or matrix were not working on MATLAB.
For example, we'd like to calculate controlLaw based on feedback gains of kp and kv. The issue was vector matrix computation for controlLaw.
On the MATLAB, we cannot achieve this equation: controlLaw = -1. * KP*(q - q_des) - KV*(dq - dq_des);
Do you think there are any other better ways to do that on MATLAB? Or is it benefit of using C++ programming?
original C++ programming
Code: Select all
//definition variables
double q1, q2, dq1, dq2, q1_des, q2_des, dq1_des, dq2_des;
Vec2 controlLaw;
Vec2 q(q1, q2);
Vec2 dq(dq1, dq2);
Vec2 q_des(q1_des, q2_des);
Vec2 dq_des(dq1_des, dq2_des);
Mat22 KP, KV;
// inputs variables ... (SKIP HERE)
// Vector Matrix computation (THIS IS OUR POINT)
controlLaw = -KP*(q - q_des) - KV*(dq - dq_des);
Code: Select all
q1 = joint_1.getValue(s); dq1 = joint_1.getSpeedValue(s); q2 = joint_2.getValue(s); dq2 = joint_2.getSpeedValue(s);
q1_des = 80. * pi() / 180.; dq1_des = 0.0 * pi() / 180.; q2_des = -80. * pi() / 180.; dq2_des = 0.0 * pi() / 180.;
controlLaw = Vector( 2, 0.0 );
q = Vector( 2, 0.0 );
dq = Vector( 2, 0.0 );
q_des = Vector( 2, 0.0 );
dq_des = Vector( 2, 0.0 );
KP = Matrix( 2, 2, 0.0 ); KV = Matrix( 2, 2, 0.0 );
KP.set( 0, 0, kp ); KP.set( 1, 1, kp );
KV.set( 0, 0, kv ); KV.set( 1, 1, kv );
controlLaw = -1. * KP*(q - q_des) - KV*(dq - dq_des);
Thank you,
Hide