![V-REP與MATLAB進行通訊的方法_第1頁](http://file4.renrendoc.com/view/f5d958c0102ae8f869e1628fde4a72bf/f5d958c0102ae8f869e1628fde4a72bf1.gif)
![V-REP與MATLAB進行通訊的方法_第2頁](http://file4.renrendoc.com/view/f5d958c0102ae8f869e1628fde4a72bf/f5d958c0102ae8f869e1628fde4a72bf2.gif)
![V-REP與MATLAB進行通訊的方法_第3頁](http://file4.renrendoc.com/view/f5d958c0102ae8f869e1628fde4a72bf/f5d958c0102ae8f869e1628fde4a72bf3.gif)
![V-REP與MATLAB進行通訊的方法_第4頁](http://file4.renrendoc.com/view/f5d958c0102ae8f869e1628fde4a72bf/f5d958c0102ae8f869e1628fde4a72bf4.gif)
![V-REP與MATLAB進行通訊的方法_第5頁](http://file4.renrendoc.com/view/f5d958c0102ae8f869e1628fde4a72bf/f5d958c0102ae8f869e1628fde4a72bf5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
V-REP是一款多功能的機器人仿真器,1.具有4種物理引擎((ODE,Bullet,Vortex,Newton));2.支持Windows,Linux,MacOS三種操作系統(tǒng);3.支持六種編程方法;4.七種編程語言(
(C/C++、Python、Java、Lua、Matlab、Octave、和Urbi))。本文將簡單地介紹如何將MATLAB與V-REP進行通訊,分別實現(xiàn)簡單的讀取機器人關(guān)節(jié)角,傳送機器人關(guān)節(jié)角這兩種功能。一.所需的m文件在路徑...\V-REP3\V-REP_PRO_EDU\programming\remoteApiBindings\matlab\matlab中將所有的m文件復(fù)制到項目文件夾中。二.關(guān)鍵的語句V-REP端:
simExtRemoteApiStart(19999)MATLAB端:vrep=remApi('remoteApi');%usingtheprototypefile(remoteApiProto.m)
vrep.simxFinish(-1);%justincase,closeallopenedconnections
clientID=vrep.simxStart('',19999,true,true,5000,5);三.具體做法1.在V-REP中新建一個空白的場景,并從模型瀏覽器(ModleBrowser)填加一個Baxter機器人。(此時運行仿真,機器人會運動。我們的目標就是把各個關(guān)節(jié)角變化的情況記錄下來)2.點擊控制右臂的相應(yīng)代碼,在開頭增加一句:simExtRemoteApiStart(19999)3.新建一個matlab函數(shù),其代碼如下:functionbaxter_read()
disp('Programstarted');
%vrep=remApi('remoteApi','extApi.h');%usingtheheader(requiresacompiler)
vrep=remApi('remoteApi');%usingtheprototypefile(remoteApiProto.m)
vrep.simxFinish(-1);%justincase,closeallopenedconnections
clientID=vrep.simxStart('',19999,true,true,5000,5);
r1=[];
r2=[];
r3=[];
r4=[];
r5=[];
r6=[];
r7=[];
k=0;
if(clientID>-1)
disp('ConnectedtoremoteAPIserver');
%gethandleforBaxter_rightArm_joint1
[res,handle_rigArmjoint1]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint1',vrep.simx_opmode_oneshot_wait);
[res,handle_rigArmjoint2]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint2',vrep.simx_opmode_oneshot_wait);
[res,handle_rigArmjoint3]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint3',vrep.simx_opmode_oneshot_wait);
[res,handle_rigArmjoint4]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint4',vrep.simx_opmode_oneshot_wait);
[res,handle_rigArmjoint5]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint5',vrep.simx_opmode_oneshot_wait);
[res,handle_rigArmjoint6]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint6',vrep.simx_opmode_oneshot_wait);
[res,handle_rigArmjoint7]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint7',vrep.simx_opmode_oneshot_wait);
while(vrep.simxGetConnectionId(clientID)~=-1),%whilev-repconnectionisstillactive
t=vrep.simxGetLastCmdTime(clientID)/1000.0;%getcurrentsimulationtime
if(t>1000)break;
end%stopaftert=1000seconds
[res,r1angle]=vrep.simxGetJointPosition(clientID,handle_rigArmjoint1,vrep.simx_opmode_oneshot_wait);
[res,r2angle]=vrep.simxGetJointPosition(clientID,handle_rigArmjoint2,vrep.simx_opmode_oneshot_wait);
[res,r3angle]=vrep.simxGetJointPosition(clientID,handle_rigArmjoint3,vrep.simx_opmode_oneshot_wait);
[res,r4angle]=vrep.simxGetJointPosition(clientID,handle_rigArmjoint4,vrep.simx_opmode_oneshot_wait);
[res,r5angle]=vrep.simxGetJointPosition(clientID,handle_rigArmjoint5,vrep.simx_opmode_oneshot_wait);
[res,r6angle]=vrep.simxGetJointPosition(clientID,handle_rigArmjoint6,vrep.simx_opmode_oneshot_wait);
[res,r7angle]=vrep.simxGetJointPosition(clientID,handle_rigArmjoint7,vrep.simx_opmode_oneshot_wait);
r1=[r1r1angle];
r2=[r2r2angle];
r3=[r3r3angle];
r4=[r4r4angle];
r5=[r5r5angle];
r6=[r6r6angle];
r7=[r7r7angle];
k=k+1%totest
end
r=[r1'r2'r3'r4'r5'r6'r7'];
fid=fopen('angle.txt','wt');
[m,n]=size(r);
fori=1:1:m
forj=1:1:n
ifj==n
fprintf(fid,'%g\n',r(i,j));
else
fprintf(fid,'%g\t',r(i,j));
end
end
end
fclose(fid);
%BeforeclosingtheconnectiontoV-REP,makesurethatthelastcommandsentouthadtimetoarrive.Youcanguaranteethiswith(forexample):
vrep.simxGetPingTime(clientID);
%NowclosetheconnectiontoV-REP:
vrep.simxFinish(clientID);
else
disp('FailedconnectingtoremoteAPIserver');
end
vrep.delete();%callthedestructor!
disp('Programended');
end
4.運行V-REP仿真,同時運行MATLAB。如果運行成功,會生成一個angle的txt文件,導(dǎo)入到MATLAB可以觀測到到Baxter機器人7個關(guān)節(jié)角的變化如圖所示:5.接下來嘗試將這組關(guān)節(jié)角輸入到V-REP中,控制機器人運動。首先是再建一個V-REP場景,添加Baxter機器人,把機器人右臂相關(guān)的代碼刪除,添加上下面一句:simExtRemoteApiStart(19999)6.新建一個MATLAB函數(shù),其代碼如下:
functionbaxter_write()
disp('Programstarted');
%vrep=remApi('remoteApi','extApi.h');%usingtheheader(requiresacompiler)
vrep=remApi('remoteApi');%usingtheprototypefile(remoteApiProto.m)
vrep.simxFinish(-1);%justincase,closeallopenedconnections
clientID=vrep.simxStart('',19999,true,true,5000,5);
%readthejointangledatafrom'angle.txt'
jointValue=load('angle.txt');%Amatrixof7x150.EachcolumnvectorrecordedthechangesofeachjointAngle
[mn]=size(jointValue);
if(clientID>-1)
disp('ConnectedtoremoteAPIserver');
%gethandleforBaxter_rightArm_joint1
[res,handle_rightArmjoint1]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint1',vrep.simx_opmode_oneshot_wait);
[res,handle_rightArmjoint2]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint2',vrep.simx_opmode_oneshot_wait);
[res,handle_rightArmjoint3]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint3',vrep.simx_opmode_oneshot_wait);
[res,handle_rightArmjoint4]=vrep.simxGetObjectHandle(clientID,'BaxterrightArm_joint4',vrep.simx_opmode_oneshot_wait);
[res,handle_rightArmjoint5]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint5',vrep.simx_opmode_oneshot_wait);
[res,handle_rightArmjoint6]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint6',vrep.simx_opmode_oneshot_wait);
[res,handle_rightArmjoint7]=vrep.simxGetObjectHandle(clientID,'Baxter_rightArm_joint7',vrep.simx_opmode_oneshot_wait);
%Setthepositionofeveryjoint
while(vrep.simxGetConnectionId(clientID)~=-1),%whilev-repconnectionisstillactive
fori=1:m
vrep.simxPauseCommunication(clientID,1);
vrep.simxSetJointTargetPosition(clientID,handle_rightArmjoint1,jointValue(i,1),vrep.simx_opmode_oneshot);
vrep.simxSetJointTargetPosition(clientID,handle_rightArmjoint2,jointValue(i,2),vrep.simx_opmode_oneshot);
vrep.simxSetJointTargetPosition(clientID,handle_rightArmjoint3,jointValue(i,3),vrep.simx_opmode_oneshot);
vrep.simxSetJointTargetPosition(clientID,handle_rightArmjoint4,jointValue(i,4),vrep.simx_opmode_oneshot);
vrep.simxSetJointTargetPosition(clientID,handle_rightArmjoint5,jointValue(i,5),vrep.simx_opmode_oneshot);
vrep.simxSetJointTargetPosition(clientID,handle_rightArmjoint6,jointValue(i,6),vrep.simx_opmode_oneshot);
vre
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國叉車制造市場運行動態(tài)及行業(yè)投資潛力預(yù)測報告
- 可穿戴外骨骼變剛度肘關(guān)節(jié)的動力學(xué)建模分析與人機交互實驗研究
- 基于橈動脈入路HAIC序貫栓塞與傳統(tǒng)TACE對中晚期HCC治療的臨床研究
- HIIT訓(xùn)練對12-15歲青少年健康體適能影響的實驗研究
- “重復(fù)構(gòu)成”在工筆花鳥畫《萬物》系列中的應(yīng)用研究
- FPGA代碼級精準逆向關(guān)鍵技術(shù)研究
- 血清中IL-36、NR4A1、NR4A2與老年急性冠脈綜合征的相關(guān)分析
- 干木貨架項目可行性研究報告模板范文(立項備案項目申請)
- 未來十年移動支付的五大發(fā)展趨勢預(yù)測
- 轉(zhuǎn)班申請書范文
- 安全生產(chǎn)技術(shù)規(guī)范 第25部分:城鎮(zhèn)天然氣經(jīng)營企業(yè)DB50-T 867.25-2021
- 現(xiàn)代企業(yè)管理 (全套完整課件)
- 走進本土項目化設(shè)計-讀《PBL項目化學(xué)習(xí)設(shè)計》有感
- 《網(wǎng)店運營與管理》整本書電子教案全套教學(xué)教案
- 教師信息技術(shù)能力提升培訓(xùn)課件希沃的課件
- 高端公寓住宅項目營銷策劃方案(項目定位 發(fā)展建議)
- 執(zhí)業(yè)獸醫(yī)師聘用協(xié)議(合同)書
- 第1本書出體旅程journeys out of the body精教版2003版
- [英語考試]同等學(xué)力英語新大綱全部詞匯
- 2022年肝動脈化療栓塞術(shù)(TACE)
- 形式發(fā)票格式2 INVOICE
評論
0/150
提交評論