Giter Club home page Giter Club logo

beamngpy's Introduction

BeamNGpy

BeamNGpy is an official library providing a Python API to BeamNG.tech, the academia- and industry-oriented fork of the video game BeamNG.drive. BeamNGpy and BeamNG.tech are designed to go hand in hand, both being kept up to date to support each other's functions, meaning using the latest versions of both is recommended.

It allows remote control of the simulation, including vehicles contained in it. See Features or go through the Feature Overview Jupyter notebook.

Table of Contents

Features

BeamNGpy comes with a wide range of low-level functions to interact with the simulation and a few higher-level interfaces that make more complex actions easier. Some features to highlight are:

Remote Control of Vehicles

Each vehicle can be controlled individually and independently during the simulation. This includes basic steering inputs, but also controls over various lights (headlights, indicators, etc.) or gear shifting.

Throttle.Control.webm
Steering.Control.webm

AI-controlled Vehicles

Besides manual control, BeamNG.tech ships with its own AI to control vehicles. This AI can be configured and controlled from BeamNGpy. It can be used to make a vehicle drive to a certain waypoint, make it follow another vehicle, span the map, or follow a user-defined trajectory:

AI Trajectory

Dynamic Sensor Models

Vehicles and the environment can be equipped with various sensors that provide simulated sensor data. These sensors include:

  • Cameras
  • Color camera
  • Depth camera
  • Semantic and Instance annotations
  • Lidars
  • Inertial Measurement Units
  • Ultrasonic Distance Measurements

Multiple cameras Lidar

These sensors give perfect data from the simulation by default. Therefore, some of them, like the camera and lidar sensor, can be equipped to also simulate noisy data.

Access to Road Network & Scenario Objects

Geometry of roads in the currently-loaded level/scenario are made available via BeamNGpy. Objects and vehicles that are currently active in the scene are also exposed, allowing for analysis of the current simulation state.

Road Network

Multiple Clients

BeamNGpy interacts with BeamNG.tech as the client, with BeamNG.tech acting as the server. This allows for multiple BeamNGpy processes to connect to a running simulation and have each control the simulator, making it possible to, for example, run a scenario in which each vehicle is controlled by a separate client.

More

There is a healthy collection of usage examples in the examples/ folder of this repository. These highlight more features, but also serve as documentation, so be sure to check them out.

Prerequisites

Usage of BeamNGpy requires BeamNG.tech to be installed. For commercial use, contact us at [email protected]. Builds of BeamNG.tech are made available for research and academic use upon request using this form. Once downloaded, you can use the environment variable BNG_HOME to where BeamNG.tech can be run from, or provide a path to the BeamNGpy library during initialization.

Installation

The library itself is available on PyPI and can therefore be installed using common methods like pip:

pip install beamngpy

If you use Anaconda, you can install BeamNGpy from the conda-forge channel by:

conda install beamngpy -c conda-forge

To upgrade, use

pip install --upgrade beamngpy

if you installed BeamNGpy using pip or

conda update beamngpy -c conda-forge --no-pin

if you installed it using conda.

Usage

DISCLAIMER: If you are using an older version of beamngpy and BeamNG.tech, please follow the instructions of the corresponding README file (for example, 1.27.1 instructions). If you are using the latest version of BeamNGpy, continue following the instructions located in this README file.

The library can be imported using import beamngpy. A short usage example setting up a scenario with one vehicle in the West Coast USA map that spans the area is:

from beamngpy import BeamNGpy, Scenario, Vehicle

# Instantiate BeamNGpy instance running the simulator from the given path,
# communicating over localhost:64256
bng = BeamNGpy('localhost', 64256, home='/path/to/bng/tech', user='/path/to/bng/tech/userfolder')
# Launch BeamNG.tech
bng.open()
# Create a scenario in west_coast_usa called 'example'
scenario = Scenario('west_coast_usa', 'example')
# Create an ETK800 with the licence plate 'PYTHON'
vehicle = Vehicle('ego_vehicle', model='etk800', license='PYTHON')
# Add it to our scenario at this position and rotation
scenario.add_vehicle(vehicle, pos=(-717, 101, 118), rot_quat=(0, 0, 0.3826834, 0.9238795))
# Place files defining our scenario for the simulator to read
scenario.make(bng)

# Load and start our scenario
bng.scenario.load(scenario)
bng.scenario.start()
# Make the vehicle's AI span the map
vehicle.ai.set_mode('span')
input('Hit enter when done...')

We have a guide helping you getting started and navigating our collection of examples and the documentation of the library is available here.

Compatibility

BeamNG.tech is not a finished product but is still under development. Thus frequent changes on the simulation side are to be expected. While the BeamNGpy library maintains compatibility between minor versions for the user, this doesn't extend to the BeamNG.tech side. Not all BeamNGpy versions are compatible with all BeamNG.tech versions. Below is a list of compatible BeamNG.tech and BeamNGpy versions. However we do not maintain minor versions: bug fixes and new features will only be available for the newest BeamNG.tech and BeamNGpy releases.

BeamNG.tech version BeamNGpy version
0.32 1.29
0.31 1.28
0.30 1.27.1
0.28, 0.29 1.26.1
0.27 1.25.1
0.26 1.24
0.25 1.23.1
0.24 1.22
0.23 1.21.1
0.22 1.20
0.21 1.19.1

Troubleshooting

This section lists common issues with BeamNGpy in particular. Since this library is closely tied to BeamNG.tech and thus BeamNG.drive, it is also recommended to consult the documentation on BeamNG.drive here:

https://documentation.beamng.com/

BeamNGpy cannot establish a connection

  • Be sure to complete the initial set up step described in the Usage section and to repeat it with every newly released BeamNG.tech version.
  • Make sure BeamNG.tech and Python are allowed to connect to your current network in Windows Firewall.

BeamNG.tech quietly fails to launch

  • There is a known issue where BeamNG.tech quietly crashes when there is a space in the configured userpath. Until this issue is fixed, it is recommended to either switch to a path that does not contain a space or change the userpath directly in the "startup.ini" file located in the directory of your BeamNG.tech installation.

Contributions

We always welcome user contributions, be sure to check out our contribution guidelines first, before starting your work.

beamngpy's People

Contributors

abdelrahmanelsaidelsawy avatar aivora-beamng avatar alessiogambi avatar asionville avatar bleedobsidian avatar cpap-beamng avatar danamador avatar dependabot[bot] avatar dreace avatar dstark481 avatar palculator avatar pascale-commits avatar sedonas avatar simonegiacomelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

beamngpy's Issues

BeamNGpy should enable to force state of vehicles during experiments

During the experiments, especially to cut short on execution time, it would be ideal to have a way to force the state of the vehicles (assuming this is possible). For example, changing the position and rotation of the vehicles (Note: #10 enabled force positioning and rotation of vehicles, but this feature disappeared in some release after v0.4), or its speed/acceleration.

Customize Car Attributes

During the simulation, there might a need to change some attributes of the vehicles. For example, their color, their components (wheels, spoilers, etc). This can be used to create rich driving simulations while keeping the overall computational cost low (to some extent, the traffic plugin does this). As @pascale-commits says, while spawning a vehicle, color attributes can be defined on-the-fly, which is good; however, I wonder if there's the possibility to change some attributes of cars also without respawning them.

Why this might be important/relevant?

Because the user does not have to "recompute" or respawn the vehicle in the exact condition every time just to change
an attribute that does not impact the physics of the vehicle itself (i.e., color). Said in other words, the user should not do the work of the simulator and replace moving vehicles on the fly.

What attributes can be effectively (easily) changed of a vehicle?

I understand that color is one of such attributes, but what about skins, the color of wheels/rims, windshield, etc.? I assume that any other modification will impact somehow accurately simulating the physics (i.e., the aerodynamics of the car, type/size/material of the wheels, etc.).

BeamNG static objects in Scenario

BeamNG should provide a method (Programmatic way) to add a static object in the scenario. For instance, Traffic signals.

The ScenarioObject class exists but there is no example of it. It will be great if BeamNG provides the explanation of the parameters to ScenarioObject Class.

MultiShot Camera

When collecting data to train AI, one way to improve the data set is to collect images from a slightly different position of the camera and slightly different rotations. This might be achieved by declaring a number of Camera components, or maybe by pausing the simulation and taking all the screenshots with the same camera sensor (but under different configurations), however, a nice meta-sensor/sensor that gets a list of configuration might be easier to use? Such a sensor might be also configured to generate random pose/rotations of the camera while the camera points towards the same point?

Vehicle Headlights

Hi,

How to switch on the dip headlights of the vehicle automatically through code, I am not able to find any function in documentation.

BeamNG should allow for multiple connections

At the moment, only one BeamNGpy instance can be used to connect to a simulation. It would be ideal if, at least for vehicles, one can use multiple sockets/end-points, such that one BeamNG instance might be used to control the scenario while the others control the vehicles?

Polling any sensor should update the state of the vehicle

The vehicle state contains the physical properties of the car, which can be seen as the ground truth from the simulation. Some sensors read this state to compute their measurements, but not all of them. Therefore, polling those sensors does not update (or create) the state of the vehicle which is inaccurate.

The set of triples in the list does not work for poly-line.

The BeamNG throws an error when I provide the set of triples in the list for the vehicle.

`try:

    bng.load_scenario(scenario)
    bng.start_scenario()
    line = [(0,0,0.163609),(25,300, 0.163609)]
    vehicle.ai_set_line(line=line)
    vehicle.ai_set_speed(6.944, mode='set')
    vehicle.ai_drive_in_lane(True)
    input('Press enter when done...')
finally:
    bng.close()`

The sample output in the console is attached.

image

It will be great if you can correct me if I am doing something wrong.

Change camera settings

A programmatic way to configure how to grab the frames from BeamNG (camera position, FOV, etc) would be ideal.

Query interface

Would it be possible to query a running simulation from BeamNGpy? For example, getting how many (and which) cars are running, etc.

BeamNG Connection disconnects

When I try to connect to beamNG research, it connects for first time and then disconnect

here is the log

029.612|I|libbeamng.lua.V.ResearchVE|Trying to connect to: localhost:64257
031.627|I|libbeamng.lua.V.ResearchVE|Connected!
031.630|I|GELua.util_researchGE.ResearchGE|Setting engine flags!
031.662|D|GELua.scenario_scenarios.scenarios|changeState: running
031.663|D|GELua.core_camera.|Camera switched to "orbit"
031.712|E|GELua.core_levels.levels|info.json missing: /levels/garage/info.json
031.713|E|GELua.core_levels.levels|No entry point for level found: /levels/garage. Ignoring level.
031.714|E|GELua.core_levels.levels|info.json missing: /levels/GridMap/info.json
031.715|E|GELua.core_levels.levels|No entry point for level found: /levels/GridMap. Ignoring level.
031.819|E|GELua.ResearchCom|Error reading from socket: closed
031.874|E|libbeamng.lua.V.ResearchCom|Error reading from socket: closed

Procedural obstacles lack semantic annotation

In the annotation mode of the camera lanes, buildings, participants etc. can be vizualized with predefined colors whereas ProceduralMeshes like Cube, Cone and Cylinder can not.
This would be interesting the same way like annotating buildings.

Road Height Control in BeamNGpy

I am trying to create multiple layers of the road in BeamNGpy in the scenario. The asphalt road and lane marking lie on the same level (height). Hence, the lane marking is not visible in BeamNG scenario. The API should provide a method to control the road position vertically in GridMap.

Camera sensor should not show red light

Images collected using the camera sensor while the car is braking shows a red shadow, despite the camera is positioned in front on the car facing the road.

get vehicle bounding box

Hi guys,

I am not able to get vehicle bounding box by given bng.get_vehicle_bbox(vehicle2) after starting the scenario.

bng.load_scenario(scenario)
bng.start_scenario()
vehicle.ai_set_line(path1)
vehicle2.ai_set_line(path2)
vehicle3.ai_set_line(path3)
bng.get_vehicle_bbox(vehicle2)
# Following error occurs:

bbox = bng.get_vehicle_bbox(vehicle2)
  File "D:\Beamng_qazi_data\Thesis_final_code\venv\lib\site-packages\beamngpy\beamng.py", line 1130, in get_vehicle_bbox
    resp = self.recv()
  File "D:\Beamng_qazi_data\Thesis_final_code\venv\lib\site-packages\beamngpy\beamng.py", line 241, in recv
    return recv_msg(self.skt)
  File "D:\Beamng_qazi_data\Thesis_final_code\venv\lib\site-packages\beamngpy\beamngcommon.py", line 155, in recv_msg
    length = int(str(length, 'ascii'))

According to the function it should return:
near_bottom_left: Bottom left point of the near rectangle as an (x, y ,z) triplet
• near_bottom_right: Bottom right point of the near rectangle as an (x, y, z) triplet
• near_top_left: Top left point of the near rectangle as an (x, y, z) triplet
• near_top_right: Top right point of the near rectangle as an (x, y, z) triplet
• far_bottom_left: Bottom left point of the far rectangle as an (x, y, z) triplet
• far_bottom_right: Bottom right point of the far rectangle as an (x, y, z) triplet
• far_top_left: Top left point of the far rectangle as an (x, y, z) triplet
• far_top_right: Top right point of the far rectangle as an (x, y, z) triplet

AI Traffic creation from BeamNGpy

Hello!

Is it possible to create AI traffic from BeamNGpy which could be launched together with a player-controlled car?
Can you share a code example if it is possible?

Vehicle.ai_drive_in_lane(True) should not break AIControl HUD

Steps to reproduce:
- Start BeamNG with -console, load scenario
- visualize AIControl HUD, change AI mode to "Manual"
- set In Lane to "on"
- set target waypoint (NOTE it is important to set In Lane before the way point otherwise the car will NOT stay in the lane since the beginning)
- change AI mode to "Disabled"

Check that there's no error messages in BeamNG Console.

- Start BeamNG.py and  call:
    - vehicle.ai_set_mode("manual")
    - vehicle.ai_drive_in_lane(True) *I also tried with "on" and "'on'"
    - vehicle.ai_set_waypoint(<waypoint>)

Check that AI Control HUD does not update to reflect the manual mode

     - set In Lane to "on" or "off" 

Check in the BeamNG console that the following error message is printed:

056.717|E|libbeamng.lua.V|=============== Stack Traceback >> START >>
056.718|E|libbeamng.lua.V|(1) main chunk of [string "string"] at line 1
056.718|E|libbeamng.lua.V|--------------- << END <<
056.718|E|libbeamng.lua.V|*** while executing this line: ai.driveInLane("on")
056.719|E|libbeamng.lua.V|*** in chunk: string```
    
 

BeamNG.research Connection problem

I just downloaded (via SVN) the BeamNG.research repository.
https://projects.beamng.com/projects/research/files is empty. In a conda enviroment I installed BeamNGpy via pip install beamngpy.

When I try the example code with west_coast_usa, BeamNG starts but after a short time it threws the following error:

055.319|D|GELua.scenario_scenarios.scenarios|should run: false; state: running 055.322|E|GELua.core_levels.levels|info.json missing: /levels/garage/info.json 055.325|E|GELua.core_levels.levels|No entry point for level found: /levels/garage. Ignoring level. 055.442|E|GELua.ResearchCom|Error reading from socket: closed 055.472|E|GELua.core_levels.levels|info.json missing: /levels/garage/info.json 055.473|E|GELua.core_levels.levels|No entry point for level found: /levels/garage. Ignoring level. 055.613|E|libbeamng.lua.V.ResearchCom|Error reading from socket: closed 057.143|I|libbeamng.lua.V.ResearchVE|Trying to connect to: localhost:64257 059.355|I|libbeamng.lua.V.ResearchVE|Could not connect... 060.001|I|GELua.util_researchGE.ResearchGE|Trying to connect to: localhost:64256 062.317|I|GELua.util_researchGE.ResearchGE|Could not connect... 063.386|I|libbeamng.lua.V.ResearchVE|Trying to connect to: localhost:64257 065.533|I|libbeamng.lua.V.ResearchVE|Could not connect... 065.735|I|GELua.util_researchGE.ResearchGE|Trying to connect to: localhost:64256 067.760|I|GELua.util_researchGE.ResearchGE|Could not connect... 074.911|I|GELua.util_researchGE.ResearchGE|Trying to connect to: localhost:64256

What could be the problem?

Extend Semantic Annotations

If I am not mistaken, the semantic annotations provided by BeamNG uses the same color/label for each type of object. This makes it difficult to distinguish cars when they are close to each other (or one occludes the other) and tracking the movement of objects. Maybe we can have each object a different label and some additional metadata attached to the image. For example, color X, element Y, type=car, model=Z, etc. ?

Export data to CSV table

Hi there!
I found that BeamNG could fit well for my research. Now I'm looking for a way to collect data from the game.
In the youtube demonstration from Engineering psychology I found a great example of what i need (1:30-1:35):
image

I want to export at least:

position
speed
wheel angle
collision between cars (if the car is damaged)

Is there a simple option to export such data to csv?

Set AI Path should not teleport the vehicle

In some situations calling the following code:

self.vehicle.ai_set_script(self.script)```
results in teleporting the car, which is somehow an unexpected behavior. This might be something related to the "current speed" of the car which is zero at the beginning or it might be something else.

Compute car heading angle

It would be nice to have the heading angle of the vehicle with respect to the road it is traveling on

BeamNGpy and BeamNG.research version mismatch

BeamNGpy is the latest from PyPI (1.14.1) and BeamNG.research is the latest one from subversion. However, this is the warning message I get:

BeamNGpy and BeamNG.* version mismatch: BeamNGpy v1.12, BeamNG.* v1.9
Make sure both this library and BeamNG.* are up to date.
Operation will proceed, but some features might not work.
<beamngpy.beamng.BeamNGpy object at 0x000002B1B6F94048>

Is there a newer version of BeamNG.research somewhere else?

Loading and staring existing scenarios does not work

I am trying to load and start existing scenarios so I do:

  • Start beamng:
    beamng = BeamNGpy('localhost', 64256)
    bng = beamng.open(launch=True)

  • Define and (find) the existing scenario:
    scenario1.bng = bng
    scenario1.find(bng)

  • Load the scenario:
    bng.load_scenario(scenario1)

  • Start the scenario:
    bng.start_scenario()

However, after calling load scenario (and I can see that the scenario is loaded), start scenario blocks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.