V-rep------python远程控制Baxter

  1. 打开仿真,添加baxter模型(Baxter.ttm)到仿真中
    V-rep------python远程控制Baxter_第1张图片

  2. 去除脚本文件中的Threaded child script(* * ),选中用delete删除,只保留Main script( * * )和Non-threaded child script( * *)
    V-rep------python远程控制Baxter_第2张图片

  3. 在Baxter脚本文件中的sysCall_init()函数下添加

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

V-rep------python远程控制Baxter_第3张图片

  1. 选中left/right arm的所有joints,其dynamics设置修改为: uncheck “control loop enabled”,然后“apply to selection”,启动仿真就可以看到Baxter左右臂自然下垂
    V-rep------python远程控制Baxter_第4张图片

  2. 现在来配合python端,简单来说,需要配置配置几个文件,安装一些外接的库,在Python的项目里面添加接口相关文件,这些文件可以在Vrep的安装文件夹中找到(我的是linux系统在: /home/peijiean/V-REP/programming/remoteApiBindings/lib/lib/Linux/64Bit),包括:

vrep.py
vrepConst.py
remoteApi.dll(win) remoteApi.dylib(mac) remoteApi.so(linux)(三选一)

V-rep------python远程控制Baxter_第5张图片

  1. 在项目里新建python文件,v-rep中启动仿真,pycharm中运行程序,看到Baxter关节运动指定角度
#python程序示例
import numpy as np
import vrep
import math


# V-REP 数据传输模式
WAIT = vrep.simx_opmode_oneshot_wait
ONESHOT = vrep.simx_opmode_oneshot
STREAMING = vrep.simx_opmode_streaming
BUFFER = vrep.simx_opmode_buffer
BLOCKING = vrep.simx_opmode_blocking

RAD2EDG = 180 / math.pi  # 弧度转度数

# 连接到vrep
clientID = vrep.simxStart('127.0.0.1', 19999, True, True, 5000, 5)
if clientID == -1:
    raise Exception('连接失败')
print("连接成功")
message = '连接成功'
vrep.simxAddStatusbarMessage(clientID, message, ONESHOT)

# 定义每个手臂7个关节
num_joints = 7
i = 0
rightArm = np.zeros(num_joints)
rightError = np.zeros(num_joints)
leftArm = np.zeros(num_joints)
leftError = np.zeros(num_joints)

# 初始化关节,得到关节句柄
for i in range(7):
    rightJointName = 'Baxter_rightArm_joint' + str(i + 1)
    leftJointName = 'Baxter_leftArm_joint' + str(i + 1)

    # 从vrep得到关节名
    rightError[i], rightArm[i] = vrep.simxGetObjectHandle(clientID, rightJointName, BLOCKING)
    leftError[i], leftArm[i] = vrep.simxGetObjectHandle(clientID, leftJointName, BLOCKING)
rightArm = rightArm.astype(int)
rightError = rightError.astype(int)
leftArm = leftArm.astype(int)
leftError = leftError.astype(int)
# print(rightArm)
# print(leftArm)
# 设置关节转动弧度
for i in range(num_joints):
    vrep.simxSetJointTargetPosition(clientID, rightArm[i], 130 / RAD2EDG, ONESHOT)
    vrep.simxSetJointTargetPosition(clientID, leftArm[i], 60 / RAD2EDG, ONESHOT)

# # 关闭仿真
# vrep.simxStopSimulation(clientID,STREAMING)

V-rep------python远程控制Baxter_第6张图片

你可能感兴趣的:(V-rep,baxter)