仿真中用到的文件资源请访问Github:
https://github.com/zanebin/V-REP_Demo
-
Python可以用Pycharm与Spyder,推荐Spyder,可以用Ipython。随时可以观察到变量窗口,方便调试
-
新建Python文件夹,将vrep根目录V-REP_PRO_EDU_V3_5_0_Mac/programming/remoteApiBindings/python/文件拷贝进去
-
准备以下文件:
verp\programming\remoteApiBindings\python\python目录下的:
根据系统选择:“remoteApi.dll” (Windows), “remoteApi.dylib” (Mac) or “remoteApi.so” (Linux)
-
打开V-REP,new scene,拖入一个UR5机械臂(也可以用别的模型)
添加代码到lua中,保存修改
simExtRemoteApiStart(19999)
注意UR5模型有自带的Lua脚本,不影响通信例子
-
运行V-REP仿真,再运行python的simpleTest.py,如下界面表示通信正常
先运行V-REP仿真,再运行你的Python程序。
若程序正常运行,可看到V-REP的状态栏中有如下显示:“Hello V-REP”,Python控制台出现鼠标的位置,说明Python与V-REP正常通信。
V-REP 与 Python 通信的关键脚本代码如下:
% V-REP脚本:
simExtRemoteApiStart(19999)
% Python端:
vrep=remApi(‘remoteApi’)
vrep.simxFinish(-1)
clientID=vrep.simxStart(‘127.0.0.1’,19999,true,true,5000,5)
Reference:
User Manual: