python联合vrep_python控制vrep代码实例

1.连接、开始仿真、断开、停止仿真

要通过python控制vrep中的模型,就要将python端与vrep端进行连接,然后控制vrep开始仿真,而连接、开始仿真、断开连接、停止连接的函数例程都是一样的,因此下面的程序可以直接进行复制粘贴(但是要注意所连接的端口号):

import time

import numpy as np

import vrep

import config

import math

# V-REP data transmission modes:

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

if config.wait_response:

MODE_INI = WAIT

MODE = WAIT

else:

MODE_INI = STREAMING

MODE = BUFFER

robotID = -1

ultraID = [-1] * config.n_ultra

rewardRefID = -1

goalID = -1

left_motorID = -1

right_motorID = -1

clientID = -1

left_collisionID = -1

right_collisionID = -1

distance = np.full(config.n_ultra, -1, dtype = np.float64) # distance from ultrasonic sensors

pos = np.full(3, -1, dtype = np.float64) # Pose 2d base: x(m), y(m), theta(rad)

reward_ref = np.full(1, -1, dtype = np.float64) # reward reference: distance between goal and robot

def show_msg(message):

""" send a message for printing in V-REP """

vrep.simxAddStatusbarMessage(clientID, message, WAIT)

return

def connect():

""" Connect to the simulator"""

ip = '127.0.0.1'

port = 19997

vrep.simxFinish(-1) # just in case, close all opened connections

global clientID

clientID = vrep.simxStart(ip, port, True, True, 3000, 5)

# Connect to V-REP

if clientID == -1:

imp

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值