文档详情

V-REP与MATLAB进行通讯的方法.docx

发布:2025-06-10约6.89千字共7页下载文档
文本预览下载声明

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(127.0.0.1,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(127.0.0.1,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_joi

显示全部
相似文档