




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
V-REP是一款多功能的机器人仿真器,1.具有4种物理引擎((ODE,Bullet,Vortex,Newton));2.支持Windows,Linux,MacOS三种操作系统;3.支持六种编程方法;4.七种编程语言(
(C/C++、Python、Java、Lua、Matlab、Octave、和Urbi))。本文将简单地介绍如何将MATLAB与V-REP进行通讯,分别实现简单的读取机器人关节角,传送机器人关节角这两种功能。一.所需的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机器人。(此时运行仿真,机器人会运动。我们的目标就是把各个关节角变化的情况记录下来)2.点击控制右臂的相应代码,在开头增加一句:simExtRemoteApiStart(19999)3.新建一个matlab函数,其代码如下: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个关节角的变化如图所示:5.接下来尝试将这组关节角输入到V-REP中,控制机器人运动。首先是再建一个V-REP场景,添加Baxter机器人,把机器人右臂相关的代码删除,添加上下面一句:simExtRemoteApiStart(19999)6.新建一个MATLAB函数,其代码如下:
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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年中国EVA鞋材数据监测报告
- 2025年中国2.9-二甲基喹吖啶酮数据监测研究报告
- 2025至2030年中国龙韵石砖市场分析及竞争策略研究报告
- 2025至2030年中国陶瓷棺市场分析及竞争策略研究报告
- 2025至2030年中国铅合金产品市场分析及竞争策略研究报告
- 2025至2030年中国花泥树脂市场分析及竞争策略研究报告
- 2025至2030年中国线控工程车市场分析及竞争策略研究报告
- 2025至2030年中国矫形胸托市场分析及竞争策略研究报告
- 2025至2030年中国瓦楞针市场分析及竞争策略研究报告
- 2025至2030年中国滑片泵市场分析及竞争策略研究报告
- 棉印染清洁生产审核报告
- 板鞋竞速竞赛规则
- GB 6722-2014爆破安全规程
- 校企合作项目立项申请表(模板)
- 六旋翼无人机的设计(毕业设计)
- 假货鉴定报告
- 艺术概论:第八章综合艺术
- 云南省临沧市各县区乡镇行政村村庄村名居民村民委员会明细及行政区划代码
- 新人教版九年级物理全册知识点总结(课堂笔记)
- DB13T 5519.7-2022 轨道交通AFC系统线网技术要求 第7部分:数据接口
- 驻戈壁某部队糖尿病流行病学调查
评论
0/150
提交评论