Matlab 符号运算 机器人正运动学DH 代公式
通常算DH的時(shí)候需要先列DH參數(shù)表,再依次依據(jù)公式求T01,T12,T23,然后T03=T01*T12*T23
但是這最后一步T03=T01*T12*T23 非常麻煩,代公式容易代錯(cuò),算4*4的矩陣相乘也非常容易算錯(cuò),幸好matlab具有符號(hào)運(yùn)算功能
可以在B站搜索 Matlab公式推導(dǎo)? ?會(huì)有很多教授相關(guān)函數(shù)的視頻
照視頻重點(diǎn)學(xué)習(xí)syms,subs,simplify函數(shù)
也可以直接搜matlab官網(wǎng)函數(shù)的用法??
?
以這道題為例,求末端坐標(biāo)系3相對(duì)于坐標(biāo)系0的描述
T03=T01*T12*T23
編寫(xiě)代碼如下:
clear
clc
%========================================每次調(diào)用先復(fù)制這段函數(shù)
syms alpha ?a d ?theta
y=[cos(theta) ? ? ? ? ? ? ? ? ? ? -sin(theta) ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? a;?
? ? sin(theta)*cos(alpha) ?cos(theta)*cos(alpha) ? -sin(alpha) ?-sin(alpha)*d;
? ? sin(theta)*sin(alpha) ?cos(theta)*sin(alpha) ? ?cos(alpha) ? cos(alpha)*d;
? ? ?0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0 ? ? ? ? ? ? ? ? ? ? ? ?1];
%====================================================
?syms theta1 ?theta2 ? theta3 ? L1 ?L2 ?%寫(xiě)出所有用到的變量,這是定義
?T1=subs(y,[alpha ?a d ?theta],[0 0 0 theta1])%這一段是功能代碼照著DH表寫(xiě)
?T2=subs(y,[alpha ?a d ?theta],[0 L1 0 theta2])%仔細(xì)觀察這里,就是照著DH表填
?T3=subs(y,[alpha ?a d ?theta],[0 L2 0 theta3])
?
?T=T1*T2*T3%矩陣合成,生成的是sym類(lèi)型的矩陣
?T=simplify(T)%化簡(jiǎn)
%==========一句一句輸入以下代碼有助于理解(多嘗試,對(duì)照這自己的手算更容易理解)
edit%打開(kāi)編輯窗口
?T1
T2
T3
T1*T2
simplify(T1*T2)
?
T1*T2*T3
simplify(T1*T2*T3)
?%=========================================以下是我的edit窗口的顯示
>> T1
?
T1 =
?
[ cos(theta1), -sin(theta1), 0, 0]
[ sin(theta1), ?cos(theta1), 0, 0]
[ ? ? ? ? ? 0, ? ? ? ? ? ?0, 1, 0]
[ ? ? ? ? ? 0, ? ? ? ? ? ?0, 0, 1]
?
>> T2
?
T2 =
?
[ cos(theta2), -sin(theta2), 0, L1]
[ sin(theta2), ?cos(theta2), 0, ?0]
[ ? ? ? ? ? 0, ? ? ? ? ? ?0, 1, ?0]
[ ? ? ? ? ? 0, ? ? ? ? ? ?0, 0, ?1]
?
>> T3
?
T3 =
?
[ cos(theta3), -sin(theta3), 0, L2]
[ sin(theta3), ?cos(theta3), 0, ?0]
[ ? ? ? ? ? 0, ? ? ? ? ? ?0, 1, ?0]
[ ? ? ? ? ? 0, ? ? ? ? ? ?0, 0, ?1]
?
>> T1*T2
?
ans =
?
[ cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2), - cos(theta1)*sin(theta2) - cos(theta2)*sin(theta1), 0, L1*cos(theta1)]
[ cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1), ? cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2), 0, L1*sin(theta1)]
[ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, 1, ? ? ? ? ? ? ?0]
[ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, 0, ? ? ? ? ? ? ?1]
?
>> simplify(T1*T2)
?
ans =
?
[ cos(theta1 + theta2), -sin(theta1 + theta2), 0, L1*cos(theta1)]
[ sin(theta1 + theta2), ?cos(theta1 + theta2), 0, L1*sin(theta1)]
[ ? ? ? ? ? ? ? ? ? ?0, ? ? ? ? ? ? ? ? ? ? 0, 1, ? ? ? ? ? ? ?0]
[ ? ? ? ? ? ? ? ? ? ?0, ? ? ? ? ? ? ? ? ? ? 0, 0, ? ? ? ? ? ? ?1]
?
>> T1*T2*T3
?
ans =
?
[ cos(theta3)*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2)) - sin(theta3)*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1)), - cos(theta3)*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1)) - sin(theta3)*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2)), 0, L2*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2)) + L1*cos(theta1)]
[ cos(theta3)*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1)) + sin(theta3)*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2)), ? cos(theta3)*(cos(theta1)*cos(theta2) - sin(theta1)*sin(theta2)) - sin(theta3)*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1)), 0, L2*(cos(theta1)*sin(theta2) + cos(theta2)*sin(theta1)) + L1*sin(theta1)]
[ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, 1, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0]
[ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 1]
?
>> simplify(T1*T2*T3)
?
ans =
?
[ cos(theta1 + theta2 + theta3), -sin(theta1 + theta2 + theta3), 0, L2*cos(theta1 + theta2) + L1*cos(theta1)]
[ sin(theta1 + theta2 + theta3), ?cos(theta1 + theta2 + theta3), 0, L2*sin(theta1 + theta2) + L1*sin(theta1)]
[ ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0, 1, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0]
[ ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0, 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1]
?
總結(jié)
以上是生活随笔為你收集整理的Matlab 符号运算 机器人正运动学DH 代公式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 20+ 创意Flash网站设计欣赏
- 下一篇: PDF怎么转换成TXT文本?这2个方法简