I´m working with BeamNG.research and communicating with it using Python3.6 and the client BeamNGPy.
The current application is able to:
- open BeamNG
- load a scenario
- control the spawned vehicle.
But I have problems retrieving the current vstate of the vehicle. As I discovered the vstate is properly requested and the put method of beamngs queue collecting the results of these requests is called but the queue stays empty and so I can not get the current 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')
EDIT:
I realized that the error occurrs in the a lua file of BeamNG.research.
More precisely <beamNG_basedir>/lua/ge/extensions/util/researchAdapter.lua
line 180.
The call to Engine.getColorBufferBase64(width, height)
fails with the following message.
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 <<