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'); % using the prototype file (remoteApiProto.m)
vrep.simxFinish(-1); % just in case, close all opened connections
clientID=vrep.simxStart('127.0.0.1',19999,true,true,5000,5);
三.具体做法
1.在V-REP中新建一个空白的场景,并从模型浏览器(Modle Browser)填加一个Baxter机器人。
(此时运行仿真,机器人会运动。我们的目标就是把各个关节角变化的情况记录下来)
2.点击控制右臂的相应代码,在开头增加一句:
simExtRemoteApiStart(19999)
3.新建一个matlab函数,其代码如下:
function baxter_read()
disp('Program started');
% vrep=remApi('remoteApi','extApi.h'); % using the header (requires a compiler)
vrep=remApi('remoteApi'); % using the prototype file (remoteApiProto.m)
vrep.simxFinish(-1); % just in case, close all opened connections
clientID=vrep.simxStart('127.0.0.1',19999,true,true,5000,5);
r1=[];
r2=[];
r3=[];
r4=[];
r5=