Streams

Streams

From BeamNG


The streams are data that comes out of the main game in order to be displayed by the UI. This page will attempt to document all streams and how to get them into your App.

There will also be an App to log all values available to the ui in a future release.

The examples are minimalistic and only are meant to show the specific code. For more on App-creation please look into the corresponding wikipage or take a look at the Apps provided with the game.

Using Streams

In your App.js you define which streams you would like to use by adding them to the StreamsManager service provided by the ui. Remember to remove them when your App gets removed from the screen by the user. This is important since leaving them there eventhough the App is not used may cause the ui to react slower than usual.

.directive('<dirName>', ['StreamsManager', function (StreamsManager) {
  'use strict';
  // ^ tell cef to use strict mode in this function 
  return {
    //...
    link: function (scope, element, attrs) {
        // Tell ui which streams you need: 
        var requiredStreams = ['electrics' /*, <stream two>, ...*/];
        StreamsManager.add(requiredStreams);

        // This is called when the App gets removed from the screen:
        scope.$on('$destroy', function () {
            StreamsManager.remove(requiredStreams);
        });

        // To receive the data listen to the streamsUpdate event:
        scope.$on('streamsUpdate', function (event, streams) {
          //Do something with the stream info here for example:
          console.log(streams.electrics.wheelspeed);
        });
        //...
    }
  };
}]);

Under the hood

Every Time you add a Stream in your App the StreamsManager increases a counter for that stream and decreases it if you remove the stream from your App.

This means that if you don't do this, the StreamsManager assumes the stream is still used, thus listening and broadcasting the stream-data. This means an unnecessary overhead for the ui.

But managing streams this way means not every App receives a copy of the data from the game, but the same data object is shared across all Apps.

This also means that an App receives Data from streams it never registered, but other Apps did.

Even deeper under the hood: this is why the object has to be read-only. Otherwise every App could change the data for all Apps. This is accomplished by deep freezing the data object before broadcasting it. Unfortunately in Javascript you won't get an error message when not using strict mode (just put 'use strict'; at the beginning of your Apps function). If you are using strict mode you will get an error in the CEF console.

How to check available streams

The 'Corresponding LUA names' column in the tables below are there for legacy reasons and are not actively checked for their correctness. To check the available streams for yourself open the console and switch to the "BeamNG Vehicle Lua" console. You are now able to debug the available streams ("dump(streams)").

Dump streams screen.png

The number behind the stream name represents how often the stream is needed by the gui (more infos:here). If you now want any further informations about a stream you can take a look into the "~Steam~\steamapps\common\BeamNG.drive\lua\vehicle\guistreams.lua" file. An advanced example: information about the "engineInfo"-stream.

Dump streams engineInfo screen.png

The "dump(controller.mainController.engineInfo)" command first looks into the "~Steam~\steamapps\common\BeamNG.drive\lua\vehicle\controller.lua" file (the first part of the command) and then gets the child "mainController" (the second part of the command) of the module table.

Controller lua mainController declaration.png

This entry refers to the "~Steam~\steamapps\common\BeamNG.drive\lua\vehicle\controller\vehicleController.lua" file. In this file you get the information by following the "engineInfo" (the thrid part of the command) table.

VehicleController lua engineInfo declaration.png

List of Streams

wheelInfo

This is an array of wheels, for each wheel this information is provided :

Name Corresponding LUA names Type Description
0[0] wd.name string Name of the wheel e.g. RR (Rear Right)
0[1] wd.radius float Radius of wheel (in Meters).
0[2] wd.wheelDir float Wheel direction
0[3] w.angularVelocity float Current AV of the wheel.
0[4] w.lastTorque float  ???
0[5] drivetrain.wheelInfo[wd.wheelID].lastSlip float  ???
0[6] wd.lastTorqueMode float  ???
0[7] drivetrain.wheelInfo[wd.wheelID].downForce float  ???
0[8]  ??? float  ???
0[9]  ??? float  ???

sensors

Name Corresponding LUA names Type Description
pitch  ??? float Current pitch value of vehicle
gz2  ??? float  ???
roll  ??? float Current roll value of vehicle
gxMax  ??? float  ???
gyMax  ??? float  ???
gravity  ??? float  ???
gy  ??? float  ???
position.y  ??? float Current vehicle y position
position.x  ??? float Current vehicle x position
position.z  ??? float Current vehicle z position
gyMin  ??? float  ???
gy2  ??? float  ???
yaw  ??? float Current rotation of vehicle in radians
gx2  ??? float  ???
gz  ??? float  ???
gx  ??? float  ???
gxMin  ??? float  ???
gzMax  ??? float  ???
ffb  ??? float  ???
gzMin  ??? float  ???
ffb2  ??? float  ???


electrics

The electrics stream gives you access to all the electrics.lua values.

Name Corresponding LUA names Type Description
lowfuel electronics.values.lowfuel int Low fuel indicator
esc electronics.values.esc int 0:Not present/inactive 1:Disabled Blink:Active
watertemp electronics.values.watertemp float Water temperature (Not implemented yet - always 0.4)
brake_input M.values.brake float Brake input
signal_right_input vals.signal_right_input int Right Signal State
throttle M.values.throttle float Current throttle pedal position
parking vals.parking int Parking lights on/off (Not implemented yet)
driveshaft driveshaft.electricsName float Driveshaft
wheelspeed M.values.wheelspeed float Current wheel speed
highbeam vals.highbeam int High-beams state
engineThrottle electronics.values.engineThrottle float Engine Throttle
signal_L vals.signal_L float Current state of left signal, 0.5 = halfway to full blink
signal_R vals.signal_R float Current state of right signal, 0.5 = halfway to full blink
reverse vals.reverse int Reverse gear state
gear_M electrics.values.gear_M float Gear selected in manual mode
ignition electronics.values.ignition int Engine state
fog vals.fog int Fog Light State
parkingbrake_input vals.parkingbrake_input int Is Parking Brake engaged?
lowbeam vals.lowbeam int Low-beams state
signal_left_input vals.signal_left_input int Left Signal State
steering M.values.steering float Current Steering wheel position
clutch_input M.values.clutch int Current Clutch input
lowhighbeam vals.lowhighbeam int State of Low High Beam
parkingbrake vals.parkingbrake float Parking brake state. 0.5 = halfway on
throttle_input electrics.values.throttle float Throttle input
gear_A electrics.values.gear_A float Gear selected in automatic mode
lowpressure beamstate.lowpressure int Low fuel pressure indicator
steering_input electrics.values.steering_input float Current original steering wheels position
lightbar vals.lightbar int Light bar state
rpm vals.rpm float Current Engine RPM
checkengine electrics.values.checkengine int Check engine light on/off
running electrics.values.running int Is the engine running?
axle axleBeamsWheel float Number of Axles(?)
fuel M.fuel float Percent of fuel
abs electrics.values.abs float ABS State
airspeed vals.airspeed float Current Airspeed
rpmspin vals.rpmspin float rpm spin(?)
clutch M.values.clutch float Current clutch pedal position
altitude vals.altitude float Z axis object position
brake M.values.brake float Current brake pedal position
hazard vals.hazard int Hazards state
lights vals.lights int State of lights, 1 = low, 2 = high
oiltemp vals.oil float Oil temperature (Not implemented yet - returns 0.3)
turnsignal vals.turnsignal float turn signal (-1 = Left, 1 = Right, gradually 'fades' between values) [use "signal_L" and "signal_R" for flashing indicator]
verticalVelocity vals.verticalVelocity float Movement on the Z-Axis
american_taillight_L  ??? bool On or Off
american_taillight_R  ??? bool On or Off
blinkPulse blinkPulse int Linked to turn signal flashes
signalLeftState vals.signal_left_input bool Left signal on/off
signalRightState vals.signal_right_input bool Right signal on/off
tcs electrics.values.tcs int 0:Not present/inactive 1:Disabled Blink:Active
turboBoost electrics.values.turboBoost float Turbo Boost Pressure
turboRpmRatio electrics.values.turboRpmRatio float Turbo RPM Ratio
beaconSpin electrics.values.beaconSpin int Rotational spin of Beacon
rudder electronics.values.rudder int Rudder input
disp_Na  ??? int  ???
disp_Ra  ??? int  ???
disp_P  ??? int  ???
disp_R  ??? int  ???
disp_N  ??? int  ???
disp_D  ??? int  ???
disp_L  ??? int  ???
disp_1  ??? int  ???
disp_2  ??? int  ???
disp_3  ??? int  ???
disp_4  ??? int  ???
disp_5  ??? int  ???
disp_6  ??? int  ???
disp_7  ??? int  ???
spoiler  ??? float  ???
auto_p  ??? int  ???
auto_neutral  ??? int  ???
auto_1st  ??? int  ???
4ws  ??? float  ???
auto_2nd  ??? int  ???
auto_drive  ??? int  ???
auto_sandwich  ??? int  ???
accz_x  ??? float  ???
jy_bl  ??? float  ???
accz  ??? float  ???
jy_fl  ??? float  ???
cust_yaw  ??? float  ???
jy_fr  ??? float  ???
vsi  ??? float  ???
cust_airspeed  ??? float  ???
custom_throttle  ??? float  ???
jy_br  ??? float  ???
accz_n  ??? float  ???

engineInfo

This has stuff to do with the drivetrain and some general physics current values and settings.

Name Corresponding LUA names Type Description
[0] v.data.engine.idleRPM int Engine Idle RPM
[1] v.data.engine.maxRPM int Engine Max RPM
[2] v.data.engine.shiftUpRPM int RPM where gearbox shifts up
[3] v.data.engine.shiftDownRPM int RPM where gearbox shifts down
[4] drivetrain.rpm float Engine RPM
[5] vdrivetrain.gear int Total Gears
[6] v.data.engine.fwdGearCount int Amount of Forward Gears
[7] v.data.engine.revGearCount int Amount of Reverse Gears
[8] drivetrain.torque float Engine Torque
[9] drivetrain.torqueTransmission float Wheel Torque
[10] obj:getVelocity():length() float Airspeed
[11] drivetrain.fuel float Fuel Remaining
[12] drivetrain.fuelCapacity int Total Fuel Capacity
[13] v.data.engine.transmissionType string Manual/Auto/DCT/CVT
[14] obj:getID() int Object ID
[15] drivetrain.brakeSpecificFuelConsumption int BSFC
[16] electrics.values.gearindex int Current Gear
[17] (engine.isStalled or engine.ignitionCoef <=0) int Ignition
[18] electrics.values.engineLoad int Engine Load

stats

The stats stream includes general node and beam structure statistics and information.

Note: While a number of the values are named "weight" they actually contain masses, in KG.

Name Corresponding LUA names Type Description
beams_total data.stats.beam_count int Total Beams in Vehicle
beams_deformed data.stats.beams_deformed int Deformed Beams
wheel_weight data.stats.wheel_weight float Weight of Wheels
total_weight data.stats.total_weight float Total Vehicle Weight
node_count data.stats.node_count int Number of Nodes
wheel_count data.stats.wheel_count int Number of Wheels
beams_broken data.stats.beams_broken int Number of Broken Beams
triCount data.stats.tri_count int Number of Triangles
collTriCount data.stats.collideable_tri_count int Number of Collidable Triangles

torqueCurve

The torque curve stream includes torque vs RPM and power vs RPM tables.

Name Corresponding LUA names Type Description
[0]  ??? float Torque table
[1]  ??? float Power table


tcsData

Information relating to Traction Control System Data

Name Corresponding LUA names Type Description
throttleFactor throttleFactor float Amount of Throttle input
wheelSlips.RR  ??? float  ???
wheelSlips.RL  ??? float  ???
wheelBrakeFactors.RR  ??? float  ???
wheelBrakeFactors.RL  ??? float  ???
slipThreshold  ??? float  ???
allWheelSlip  ??? float  ???
wheelSlips.FR  ??? float  ???
wheelSlips.FL  ??? float  ???
wheelBrakeFactors.FR  ??? float  ???
wheelBrakeFactors.FL  ??? float  ???

escData

Information relating to Electronic Stability Control Data

Name Corresponding LUA names Type Description
steeringAngle steeringAngle float Angle of the front wheels off center
desiredYawRate desiredYawRate float Ideal rotation speed of the Steering input
yawRate yawRate float Left >0 Right <0
speed electrics.values.wheelspeed float Speed of Vehicle
stepTime  ??? int  ???
desiredYawRateAcceleration desiredYawRateAcceleration float Ideal acceleration input for turning
difference yawdifference float Calculate the difference between expected and actual Yaw
desiredYawRateSteering desiredYawRateSteering float Ideal rotation speed for turning

forcedInductionInfo

Information relating to Turbochargers

Name Corresponding LUA names Type Description
rpm rpm float Speed of the Turbine blades
wastegateFactor wastegateFactor float Wastegate on turbo open or closed
throttle assignedEngine.throttle float Throttle input
inertia turboInertiaFactor int Resistance to change in state
bovEngage bovEngaged boolean Closed (0) or Open (10)
backpressure backpressure float Back pressure from compressing the air
coef assignedEngine.forcedInductionCoef float Efficiency Coefficient of the Turbocharger
boost turboPressure float Amount of Boost pressure produced