




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 农业生产安全管理与控制措施指南
- 观光农业规划
- 供热项目可行性研究报告
- 区块链技术在数字版权保护中的应用指南
- 基础设施建设项目可研报告
- 云仓项目可行性研究报告
- 公司内部规章制度培训教程
- 三基训练护理复习试题有答案
- 企业营销自动化技术应用及效果评估报告
- 主管护师内科护理练习测试卷(一)
- GB 10133-2014食品安全国家标准水产调味品
- 讲题比赛游戏中的必胜策略问题-(取棋子游戏)课件
- 旅游学概论李天元版复习总结
- 人教版八年级上历史思维导图课件
- 重庆大学介绍课件
- 江苏省南京市2020年中考英语试题
- 《电气装配车间生产工序流程卡》中英文对译版
- 四年级下册英语课件:Unit 4 There are seven days in a week-Lesson 19人教精通版
- 千分尺公开课教案
- 加油站承重罐区安全风险及管理
- 拱涵计算书-6.0m-1m
评论
0/150
提交评论