I want to use a matrix and a function to then create another function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I currently have a matrix that has known values that I then want to use to create a second matrix using a function loop. The matrix within the function loop has four variables that coincide with the variables from the above matrix DH. How do I use each row of the DH matrix to be a value to then insert into the Ai matrix? (Colum 1 = theta, Column 2 = d, etc.) I need this to then output 6 different matrices A1,A2,etc.
clear
clc
close all
theta1 = -50;
theta2 = 30;
theta3 = 15;
theta4 = -75;
theta5 = -45;
theta6 = -60;
DH = [theta1, 486.5, 150, -90;...
theta2+90, 0, -700, 0;...
theta3, 0, 0, 90;...
theta4, 600, 0, -90;...
theta5, 0, 0, 90;...
theta6, 65, 0, 0];
function Ai = getHomogeneousTransform(theta, d, a, alpha)
Ai = [cos(theata), -sin(theta)*cos(theta), sin(theta)*sin(alpha),a*cos(theta);...
sin(theta),cos(theta)*cos(alpha),-cos(theta)*sin(alpha),a*sin(theta);...
0, sin(alpha), cos(alpha), d;...
0,0,0,1];
end
1 Kommentar
Stephen23
am 29 Nov. 2022
"How do I use each row of the DH matrix to be a value to then insert into the Ai matrix?"
Use a loop and indexing.
"I need this to then output 6 different matrices A1,A2,etc."
Numbering variable names like that forces you into writing slow, complex, inefficient, buggy code. Best avoided.
The simple and very efficient approach is to use indexing. You should use indexing.
Antworten (1)
Torsten
am 28 Nov. 2022
theta1 = -50;
theta2 = 30;
theta3 = 15;
theta4 = -75;
theta5 = -45;
theta6 = -60;
DH = [theta1, 486.5, 150, -90;...
theta2+90, 0, -700, 0;...
theta3, 0, 0, 90;...
theta4, 600, 0, -90;...
theta5, 0, 0, 90;...
theta6, 65, 0, 0];
A = cell(size(DH,1),1);
for i = 1:size(DH,1)
A{i} = getHomogeneousTransform(DH(i,1)*pi/180, DH(i,2), DH(i,3), DH(i,4)*pi/180);
A{i}
end
function Ai = getHomogeneousTransform(theta, d, a, alpha)
Ai = [cos(theta),-sin(theta)*cos(theta),sin(theta)*sin(alpha),a*cos(theta);...
sin(theta),cos(theta)*cos(alpha),-cos(theta)*sin(alpha),a*sin(theta);...
0,sin(alpha),cos(alpha),d;...
0,0,0,1];
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!