vrep连接python外部控制器——以对baxter进行力矩控制的配置为例

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huangdianye/article/details/80920631

本博客的目标是,利用python编写外部控制器,控制vrep中的baxter机器人。在利用python编写控制器之前,为了连接python和vrep,进行了以下环境配置:
【vrep 场景配置】
1. 打开vrep,ctrl+N创建新的场景,在model browser中找到baxter机器人,拖动至场景中。对去除leftArm和rightArm的threaded child scripts。在head的non-threaded脚本内部,调到init()函数内部的最后部分,添加语句如下:

   repeat until (simRemoteApi.start(19999,1300,false,true)~=-1)  -- external control

这里写图片描述
这里写图片描述
2. 对于left/right arm的所有joints,其dynamics设置修改为: uncheck “control loop enabled”,然后“apply to selection”
这里写图片描述
配置完毕后,点击运行场景,可以看到baxter两个手臂下垂的现象。
【连接python和vrep配置】
1. 找一个路径,如桌面,新建文件夹,该文件夹将会添加以下内容:1)vrep安装目录中与python方式下相关的remote Api文件;2)vrep场景文件,*.ttt;3)新建python的工程文件。
这里写图片描述
2. vrep中的文件包括:
-vrep.py
-vrepConst.py
-remoteApi.dll(windows系统), remoteApi.dylib(mac系统),remoteApi.so(linux系统) 根据电脑的系统选择一个对应的文件
-simpleTest.py 用于测试连接是否成功
文件的路径: Above files are located in V-REP’s installation directory, under programming/remoteApiBindings/python.
需要注意的一点是:
You might have to build the remoteApi shared library yourself (using remoteApiSharedLib.vcproj or makefile) if not already built. In that case, make sure you have defined NON_MATLAB_PARSING and MAX_EXT_API_CONNECTIONS=255 (and optionally DO_NOT_USE_SHARED_MEMORY) as a preprocessor definition.

Once you have above elements in a directory known to Python, call import vrep to load the library. To enable the remote API on the client side (i.e. your application), call vrep.simxStart. See the simpleTest.py script in the programming/remoteApiBindings/python directory for an example. This page lists and describes all supported Python remote API functions. V-REP remote API functions can easily be recognized from their “simx”-prefix.
【测试连接】
这里写图片描述
这里写图片描述
1. 先运行vrep中的场景
2. 再打开simpleTest.py文件,并运行该文件
3. 可以看到python的console中显示了鼠标x坐标的位置,且显示了5s钟后,自动断开了与vrep的连接。且断开后verp的status bar 中显示了Hello python!的字符串。
4. 出现了以上的现象表明,python与vrep连接正常,可以进行下一步对机器人的力矩控制,力矩控制的代码编写方式可以参考上一篇力矩控制的博文。

猜你喜欢

转载自blog.csdn.net/huangdianye/article/details/80920631
今日推荐