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.

Streams

The 'Corresponding LUA names' column in the tables are there for legacy reasons and are not actively checked for their correctness.

These are the currently available 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  ???
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  ??? int Low fuel indicator
esc  ??? int 0:Not present/inactive 1:Disabled Blink:Active
watertemp  ??? float Water temperature (Not implemented yet - always 0.4)
brake_input  ??? float  ???
signal_right_input  ??? int  ???
throttle  ??? float Current throttle pedal position
parking  ??? int Parking lights on/off (Not implemented yet)
driveshaft  ??? float  ???
wheelspeed  ??? float  ???
highbeam  ??? int High-beams state
engineThrottle  ??? float  ???
signal_L  ??? float Current state of left signal, 0.5 = halfway to full blink
signal_R  ??? float Current state of right signal, 0.5 = halfway to full blink
reverse  ??? int Reverse gear state
gear_M  ??? float Gear selected in manual mode
ignition  ??? int Engine state
fog  ??? int  ???
parkingbrake_input  ??? int  ???
lowbeam  ??? int Low-beams state
signal_left_input  ??? int  ???
steering  ??? float Current Steering wheel position
clutch_input  ??? int  ???
lowhighbeam  ??? int  ???
parkingbrake  ??? float Parking brake state. 0.5 = halfway on
throttle_input  ??? float  ???
gear_A  ??? float Gear selected in automatic mode
lowpressure  ??? int Low fuel pressure indicator
steering_input  ??? float Current original steering wheels position
lightbar  ??? int  ???
rpm  ??? float  ???
checkengine  ??? int Check engine light on/off
running  ??? int  ???
axle  ??? float  ???
fuel  ??? float Percent of fuel
abs  ??? float ABS State
airspeed  ??? float  ???
rpmspin  ??? float  ???
clutch  ??? float Current clutch pedal position
altitude  ??? float  ???
brake  ??? float Current brake pedal position
hazard  ??? int Hazards state
lights  ??? int State of lights, 1 = low, 2 = high
oiltemp  ??? float Oil temperature (Not implemented yet - returns 0.3)
turnsignal  ??? float turn signal (-1 = Left, 1 = Right, gradually 'fades' between values) [use "signal_L" and "signal_R" for flashing indicator]
verticalVelocity  ??? float  ???
american_taillight_L  ??? bool  ???
american_taillight_R  ??? bool  ???
blinkPulse  ??? int  ???
disp_1  ???  ???  ???
disp_2  ???  ???  ???
disp_3  ???  ???  ???
disp_4  ???  ???  ???
disp_5  ???  ???  ???
disp_6  ???  ???  ???
disp_7  ???  ???  ???
disp_N  ???  ???  ???
disp_R  ???  ???  ???
signalLeftState  ??? bool Left signal on/off
signalRightState  ??? bool Right signal on/off
tcs  ??? int 0:Not present/inactive 1:Disabled Blink:Active
spoiler  ??? float  ???
disp_Ra  ??? int  ???
turboBoost  ??? float  ???
turboRpmRatio  ??? float  ???
disp_Na  ??? int  ???
disp_D  ??? int  ???
disp_P  ??? int  ???
disp_L  ??? int  ???
beaconSpin  ??? int  ???
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  ???
rudder  ??? int  ???
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  ???
[1] v.data.engine.maxRPM int  ???
[2] v.data.engine.shiftUpRPM int  ???
[3] v.data.engine.shiftDownRPM int  ???
[4] drivetrain.rpm float  ???
[5] vdrivetrain.gear int  ???
[6] v.data.engine.fwdGearCount int  ???
[7] v.data.engine.revGearCount int  ???
[8] drivetrain.torque float  ???
[9] drivetrain.torqueTransmission float  ???
[10] obj:getVelocity():length() float Airspeed
[11] drivetrain.fuel float  ???
[12] drivetrain.fuelCapacity int  ???
[13] v.data.engine.transmissionType string  ???
[14]  ??? int  ???
[15]  ???  ???  ???


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_deformed  ??? int  ???
beam_count  ??? int  ???
wheel_weight  ??? float  ???
total_weight  ??? float  ???
node_count  ??? int  ???
wheel_count  ??? int  ???
beams_broken  ??? int  ???


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  ??? float  ???
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  ??? float  ???
desiredYawRate  ??? float  ???
yawRate  ??? float  ???
speed  ??? float  ???
stepTime  ??? int  ???
desiredYawRateAcceleration  ??? float  ???
difference  ??? float  ???
desiredYawRateSteering  ??? float  ???

forcedInductionInfo

Information relating to Turbochargers

Name Corresponding LUA names Type Description
rpm  ??? float  ???
wastegateFactor  ??? float  ???
thr  ??? float  ???
inertia  ??? int  ???
bovEngage  ??? boolean  ???
backpressure  ??? float  ???
coef  ??? float  ???
boost  ??? float  ???