首页 > 技术文章 > matlab-vrep程序控制方法

USTBlxq 2019-12-30 16:24 原文

matlab控制程序 .m文件控制vrep常常包括以下步骤:

1.引入模块

%  load api library
vrep=remApi('remoteApi');

 

2.建立连接,先关闭上一次连接

% close all the potential link
vrep.simxFinish(-1);

clientID=vrep.simxStart('127.0.0.1',19997,true,true,5000,5);

 

%设置仿真时间步长

tstep = 0.005; % 5ms per simulation pass
vrep.simxSetFloatingParameter(clientID,vrep.sim_floatparam_simulation_time_step,tstep,vrep.simx_opmode_oneshot);

根据需要,设置m文件和vrep环境时间一致:

% open the synchronous mode to control the objects in vrep
vrep.simxSynchronous(clientID,true);

 

3.开始仿真

%% Simulation Initialization
vrep.simxStartSimulation(clientID,vrep.simx_opmode_oneshot);

 

相应的,在主程序部分,往往是循环里头:

# make step forward

vrep.simxSynchronousTrigger(clientID);

 

4.主程序部分

 

5.结束仿真

 

 

6.断开连接

##### Close the connection to V-REP

vrep.simxFinish(-1); % close the link
vrep.delete(); % destroy the 'vrep' class

 

 

推荐阅读