1

我正在使用 BeamNG.research 并使用 Python3.6 和客户端 BeamNGPy 与之通信。

当前的应用程序能够:

  • 打开 BeamNG
  • 加载场景
  • 控制生成的车辆。

但是我在检索车辆的当前 vstate 时遇到了问题。当我发现 vstate 被正确请求时,收集这些请求结果的 beamngs 队列的 put 方法被调用,但队列保持为空,因此我无法获得当前的 vstate。

import time
import beamngpy

BEAMNG_BASEDIR = '<BeamNG_basedir>'
BEAMNG_X64_BINARY = '<BeamNG_64bit_binary>'

with beamngpy.beamng.BeamNGPy('localhost', 64256, userpath='<BeamNGUserpath>',
                              binary=BEAMNG_X64_BINARY, console=True) as bpy:
    bpy.load_scenario('levels/west_coast_usa/scenarios/my_first_scenario.json')
    time.sleep(10)
    bpy.start_scenario()
    bpy.vcontrol({
        'throttle': 1.0,
        'steering': 0.5,
        'gear': 1
    })

    for _ in range(3):
        bpy.req_vstate(800, 600)
        time.sleep(1)
    for i, vstate in enumerate(bpy.poll_all()):
        vstate['img'].save(f'<outputPath>/{i:02}.png')

编辑:我意识到错误发生在 BeamNG.research 的 lua 文件中。更准确地说<beamNG_basedir>/lua/ge/extensions/util/researchAdapter.lua,第 180 行。调用Engine.getColorBufferBase64(width, height)失败并显示以下消息。

025.668|E|GameEngineLua:Exception|lua/ge/extensions//util/researchAdapter.lua:180: attempt to call field 'getColorBufferBase64' (a nil value)
=============== Stack Traceback >> START >>
(1) field C function 'getColorBufferBase64'
(2) Lua upvalue 'getVehicleState' at file 'lua/ge/extensions//util/researchAdapter.lua:180'
  Local variables:
  width = number: 800
  height = number: 600
  state = table: 0x01e121142160  {clutch:0, rot:-111.05878753658, steering:-0, vel:table: 0x01e1143b6920 (more...)}
  vdata = table: 0x01e120efaaf8  {vel:vec3(-0.000107339,9.26956e-05,-8.04267e-05), active:true, dirVecUp:vec3(-0.00877159,0.00343826,0.999956) (more...)}
  (*temporary) = nil
  (*temporary) = number: 1.02085e-311
  (*temporary) = number: 800
  (*temporary) = number: 600
  (*temporary) = number: -0.933169
  (*temporary) = number: -0.359309
  (*temporary) = number: 1.02085e-311
  (*temporary) = number: -0.359309
  (*temporary) = number: 0
  (*temporary) = number: -1
  (*temporary) = string: "attempt to call field 'getColorBufferBase64' (a nil value)"
(3) Lua local 'handler' at file 'lua/ge/extensions//util/researchAdapter.lua:220'
  Local variables:
  msg = table: 0x01e121049f10  {type:ReqVState, width:800, height:600}
  width = number: 800
  height = number: 600
(4) Lua upvalue 'handleSocketInput' at file 'lua/ge/extensions//util/researchAdapter.lua:289'
  Local variables:
  message = table: 0x01e121049f10  {type:ReqVState, width:800, height:600}
  msgType = string: "handleReqVState"
  handler = Lua function 'handleReqVState' (defined at line 210 of chunk lua/ge/extensions//util/researchAdapter.lua)
(5) Lua function 'onUpdate' at file 'lua/ge/extensions//util/researchAdapter.lua:310' (best guess)
  Local variables:
  dt = number: 0.0329248
(6) Lua field 'hook' at file 'lua/common/extensions.lua:454'
  Local variables:
  func = string: "onUpdate"
  funcList = table: 0x01e1211f8780  {1:function: 0x01e11437dc98, 2:function: 0x01e11434a720, 3:function: 0x01e11426daf8 (more...)}
  (for index) = number: 5
  (for limit) = number: 12
  (for step) = number: 1
  i = number: 5
(7) Lua function 'update' at file 'lua/ge/main.lua:362' (best guess)
  Local variables:
  dtReal = number: 0.0329248
  dtSim = number: 0.033
  dtRaw = number: 0.0329855
--------------- << END <<
4

0 回答 0