




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
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)簡單的讀取機器人關節(jié)角,傳送機器人關節(jié)角這兩種功能。一.所需的m文件在路徑...\V-REP3\V-REP_PRO_EDU\programming\remoteApiBindings\matlab\matlab中將所有的m文件復制到項目文件夾中。二.關鍵的語句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機器人。(此時運行仿真,機器人會運動。我們的目標就是把各個關節(jié)角變化的情況記錄下來)2.點擊控制右臂的相應代碼,在開頭增加一句: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文件,導入到MATLAB可以觀測到到Baxter機器人7個關節(jié)角的變化如圖所示:5.接下來嘗試將這組關節(jié)角輸入到V-REP中,控制機器人運動。首先是再建一個V-REP場景,添加Baxter機器人,把機器人右臂相關的代碼刪除,添加上下面一句: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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 互動教學在高中英語語法教學中應用現(xiàn)狀的調(diào)查研究
- 2025屆福建省莆田市高三下學期第二次教學質(zhì)量檢測歷史試題
- 預測特許金融分析師考試的常見考題與試題及答案
- 2024年特許金融分析師考試復習規(guī)劃指南與試題及答案
- CFA考試復習常見誤區(qū)試題及答案
- 汽車電氣設備構造與維修 教案 項目五 照明與信號系統(tǒng)檢修
- 2024年CFA考試技能提升試題及答案
- 2025年河南省青桐鳴高考英語模擬試卷(3月份)
- 2024年CFA高頻試題及答案
- 理解CFA考試的評估標準試題及答案
- Unit 9 Kids and Computers公開課一等獎省優(yōu)質(zhì)課大賽獲獎課件
- 重癥感染與抗生素的選擇課件
- 截流式合流制管道系統(tǒng)的特點與使用條件課件
- (站表2-1)施工單位工程項目主要管理人員備案表
- 中班美術《我心中的太陽》繪畫課件幼兒園優(yōu)質(zhì)課公開課
- 應急管理工作檢查記錄表
- 四年級下冊英語課件:Unit 4 There are seven days in a week-Lesson 19人教精通版
- 千分尺公開課教案
- 加油站承重罐區(qū)安全風險及管理
- 箱變施工安全文明保證措施
- 三體系管理手冊全文
評論
0/150
提交評論