matlab机器人工具箱matlabroboticstoolboxdemo.docx
- 文档编号:5730936
- 上传时间:2022-12-31
- 格式:DOCX
- 页数:32
- 大小:406.54KB
matlab机器人工具箱matlabroboticstoolboxdemo.docx
《matlab机器人工具箱matlabroboticstoolboxdemo.docx》由会员分享,可在线阅读,更多相关《matlab机器人工具箱matlabroboticstoolboxdemo.docx(32页珍藏版)》请在冰豆网上搜索。
matlab机器人工具箱matlabroboticstoolboxdemo
MATLABROBOTTOOL
rtdemo演示
一、rtdemo机器人工具箱演示
>>rtdemo
%
二、transfermations坐标转换
%Inthefieldofroboticstherearemanypossiblewaysofrepresenting
%positionsandorientations,butthehomogeneoustransformationiswell
%matchedtoMATLABspowerfultoolsformatrixmanipulation.
%
%HomogeneoustransformationsdescribetherelationshipsbetweenCartesian
%coordinateframesintermsoftranslationandorientation.
%Apuretranslationof0.5mintheXdirectionisrepresentedby
transl(0.5,0.0,0.0)
ans=
1.0000000.5000
01.000000
001.00000
0001.0000
%
%arotationof90degreesabouttheYaxisby
roty(pi/2)
ans=
0.000001.00000
01.000000
-1.000000.00000
0001.0000
%
%andarotationof-90degreesabouttheZaxisby
rotz(-pi/2)
ans=
0.00001.000000
-1.00000.000000
001.00000
0001.0000
%
%thesemaybeconcatenatedbymultiplication
t=transl(0.5,0.0,0.0)*roty(pi/2)*rotz(-pi/2)
t=
0.00000.00001.00000.5000
-1.00000.000000
-0.0000-1.00000.00000
0001.0000
%
%Ifthistransformationrepresentedtheoriginofanewcoordinateframewithrespect
%totheworldframeorigin(0,0,0),thatneworiginwouldbegivenby
t*[0001]'
ans=
0.5000
0
0
1.0000
pause%anykeytocontinue
%
%theorientationofthenewcoordinateframemaybeexpressedintermsof
%Eulerangles
tr2eul(t)
ans=
01.5708-1.5708
%
%orroll/pitch/yawangles
tr2rpy(t)
ans=
-1.57080.0000-1.5708
pause%anykeytocontinue
%
%Itisimportanttonotethattranformmultiplicationisingeneralnot
%commutativeasshownbythefollowingexample
rotx(pi/2)*rotz(-pi/8)
ans=
0.92390.382700
-0.00000.0000-1.00000
-0.38270.92390.00000
0001.0000
rotz(-pi/8)*rotx(pi/2)
ans=
0.92390.0000-0.38270
-0.38270.0000-0.92390
01.00000.00000
0001.0000
%
%
pause%anykeytocontinue
echooff
三、Trajectory齐次方程
%Thepathwillmovetherobotfromitszeroangleposetotheupright(or
%READY)pose.
%
%Firstcreateatimevector,completingthemotionin2secondswitha
%sampleintervalof56ms.
t=[0:
.056:
2];
pause%hitanykeytocontinue
%
%Apolynomialtrajectorybetweenthe2posesiscomputedusingjtraj()
%
q=jtraj(qz,qr,t);
pause%hitanykeytocontinue
%
%Forthisparticulartrajectorymostofthemotionisdonebyjoints2and3,
%andthiscanbeconvenientlyplottedusingstandardMATLABoperations
subplot(2,1,1)
plot(t,q(:
2))
title('Theta')
xlabel('Time(s)');
ylabel('Joint2(rad)')
subplot(2,1,2)
plot(t,q(:
3))
xlabel('Time(s)');
ylabel('Joint3(rad)')
pause%hitanykeytocontinue
%
%Wecanalsolookatthevelocityandaccelerationprofiles.Wecould
%differentiatetheangletrajectoryusingdiff(),butmoreaccurateresults
%canbeobtainedbyrequestingthatjtraj()returnangularvelocityand
%accelerationasfollows
[q,qd,qdd]=jtraj(qz,qr,t);
%
%whichcanthenbeplottedasbefore
subplot(2,1,1)
plot(t,qd(:
2))
title('Velocity')
xlabel('Time(s)');
ylabel('Joint2vel(rad/s)')
subplot(2,1,2)
plot(t,qd(:
3))
xlabel('Time(s)');
ylabel('Joint3vel(rad/s)')
pause
(2)
%andthejointaccelerationprofiles
subplot(2,1,1)
plot(t,qdd(:
2))
title('Acceleration')
xlabel('Time(s)');
ylabel('Joint2accel(rad/s2)')
subplot(2,1,2)
plot(t,qdd(:
3))
xlabel('Time(s)');
ylabel('Joint3accel(rad/s2)')
pause%anykeytocontinue
echooff
四、forwardkinematics运动学正解
%ForwardkinematicsistheproblemofsolvingtheCartesianpositionand
%orientationofamechanismgivenknowledgeofthekinematicstructureand
%thejointcoordinates.
%
%ConsiderthePuma560exampleagain,andthejointcoordinatesofzero,
%whicharedefinedbyqz
qz
qz=
000000
%
%Theforwardkinematicsmaybecomputedusingfkine()withanappropropriate
%kinematicdescription,inthiscase,thematrixp560whichdefines
%kinematicsforthe6-axisPuma560.
fkine(p560,qz)
ans=
1.0000000.4521
01.00000-0.1500
001.00000.4318
0001.0000
%
%returnsthehomogeneoustransformcorrespondingtothelastlinkofthe
%manipulator
pause%anykeytocontinue
%
%fkine()canalsobeusedwithatimesequenceofjointcoordinates,or
%trajectory,whichisgeneratedbyjtraj()
%
t=[0:
.056:
2];%generateatimevector
q=jtraj(qz,qr,t);%computethejointcoordinatetrajectory
%
%thenthehomogeneoustransformforeachsetofjointcoordinatesisgivenby
T=fkine(p560,q);
%
%whereTisa3-dimensionalmatrix,thefirsttwodimensionsarea4x4
%homogeneoustransformationandthethirddimensionistime.
%
%Forexample,thefirstpointis
T(:
:
1)
ans=
1.0000000.4521
01.00000-0.1500
001.00000.4318
0001.0000
%
%andthetenthpointis
T(:
:
10)
ans=
1.0000-0.000000.4455
-0.00001.00000-0.1500
001.00000.5068
0001.0000
pause%anykeytocontinue
%
%Elements(1:
3,4)correspondtotheX,YandZcoordinatesrespectively,and
%maybeplottedagainsttime
subplot(3,1,1)
plot(t,squeeze(T(1,4,:
)))
xlabel('Time(s)');
ylabel('X(m)')
subplot(3,1,2)
plot(t,squeeze(T(2,4,:
)))
xlabel('Time(s)');
ylabel('Y(m)')
subplot(3,1,3)
plot(t,squeeze(T(3,4,:
)))
xlabel('Time(s)');
ylabel('Z(m)')
pause%anykeytocontinue
%
%orwecouldplotXagainstZtogetsomeideaoftheCartesianpathfollowed
%bythemanipulator.
%
subplot(1,1,1)
plot(squeeze(T(1,4,:
)),squeeze(T(3,4,:
)));
xlabel('X(m)')
ylabel('Z(m)')
grid
pause%anykeytocontinue
echooff
四、Animation动画
clf
%
%Thetrajectorydemonstrationhasshownhowajointcoordinatetrajectory
%maybegenerated
t=[0:
.056:
2]';%generateatimevector
q=jtraj(qz,qr,t);%generatejointcoordinatetrajectory
%
%theoverloadedfunctionplot()animatesastickfigurerobotmoving
%alongatrajectory.
plot(p560,q);
%Thedrawnlinesegmentsdonotnecessarilycorrespondtorobotlinks,but
%jointheoriginsofsequentiallinkcoordinateframes.
%
%Asmallright-anglecoordinateframeisdrawnontheendoftherobottoshow
%thewristorientation.
%
%Ashadowappearsonthegroundwhichhelpstogivesomebetterideaofthe
%3Dobject.
pause%anykeytocontinue
%
%Wecanalsoplaceadditionalrobotsintoafigure.
%
%Let'smakeacloneofthePumarobot,butchangeitsnameandbaselocation
p560_2=p560;
p560_2.name='anotherPuma';
p560_2.base=transl(-0.5,0.5,0);
holdon
plot(p560_2,q);
pause%anykeytocontinue
%Wecanalsohavemultipleviewsofthesamerobot
clf
plot(p560,qr);
figure
plot(p560,qr);
view(40,50)
plot(p560,q)
pause%anykeytocontinue
%
%Sometimesit'susefultobeabletomanuallydrivetherobotaroundto
%getanunderstandingofhowitworks.
drivebot(p560)
%
%usethesliderstocontroltherobot(infactbothviews).Hittheredquit
%buttonwhenyouaredone.
echooff
五、InverseKinematics运动学逆解
%
%Inversekinematicsistheproblemoffindingtherobotjointcoordinates,
%givenahomogeneoustransformrepresentingthelastlinkofthemanipulator.
%ItisveryusefulwhenthepathisplannedinCartesianspace,forinstance
%astraightlinepathasshowninthetrajectorydemonstration.
%
%Firstgeneratethetransformcorrespondingtoaparticularjointcoordinate,
q=[0-pi/4-pi/40pi/80]
q=
0-0.7854-0.785400.39270
T=fkine(p560,q);
%
%Nowtheinversekinematicprocedureforanyspecificrobotcanbederived
%symbolicallyandingeneralanefficientclosed-formsolutioncanbe
%obtained.Howeverwearegivenonlyageneralizeddescriptionofthe
%manipulatorintermsofkinematicparameterssoaniterativesolutionwill
%beused.Theprocedureisslow,andthechoiceofstartingvalueaffects
%searchtimeandthesolutionfound,sinceingeneralamanipulatormay
%haveseveralposeswhichresultinthesametransformforthelast
%link.Thestartingpointforthefirstpointmaybespecified,orelseit
%defaultstozero(whichisnotaparticularlygoodchoiceinthiscase)
qi=ikine(p560,T);
qi'
ans=
-0.0000
-0.7854
-0.7854
-0.0000
0.3927
0.0000
%
%Comparedwiththeoriginalvalue
q
q=
0-0.7854-0.785400.39270
%
%Asolutionisnotalwayspossible,forinstanceifthespecifiedtransform
%describesapointoutofreachofthemanipulator.Asmentionedabove
%thesolutionsarenotnecessarilyunique,andtherearesingularities
%atwhichthemanipulatorlosesdegreesoffreedomandjointcoordinates
%becomelinearlydependent.
pause%anykeytocontinue
%
%Toexaminetheeffectatasingularityletsrepeatthelastexamplebutfora
%differentpose.Atthe`ready'positiontwoofthePuma'swristaxesare
%alignedresultinginthelossofonedegreeoffreedom.
T=fkine(p560,qr);
qi=ikine(p560,T);
qi'
ans=
-0.0000
1.5238
-1.4768
-0.0000
-0.0470
0.0000
%
%whichisnotthesameastheoriginaljointangle
qr
qr=
01.5708-1.5708000
pause%anykeytocontinue
%
%Howeverbothresultinthesameend-effectorposition
fkine(p560,qi)-fkine(p560,qr)
ans=
1.0e-015*
0-0.0000-0.0902-0.0694
0.00000-0.00000
0.09020.000000.1110
0000
pause%anykeytocontinue
%Inversekinematicsmayalsobecomputedforatrajectory.
%IfwetakeaCartesianstraightlinepath
t=[0:
.056:
2];%createatimevector
T1=transl(0.6,-0.5,0.0)%definethestartpoint
T1=
1.0000000.6000
01.00000-0.5000
001.00000
0001.0000
T2=transl(0.4,0.5,0.2)%anddestination
T
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 机器人 工具箱 matlabroboticstoolboxdemo
![提示](https://static.bdocx.com/images/bang_tan.gif)