Streams

Streams

From BeamNG

Revision as of 20:39, 5 July 2019 by The Stig Is A Spy (talk | contribs) (Cleanup and alphabetization (small tables left un-alphabetized))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 use them in your UI App.

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

These examples are minimalistic and are only 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 file, you define which streams you would like to use by adding them to the StreamsManager utility provided by the UI. Remember to add code to remove them when your App is removed from the screen by the user. This is important, since leaving them there if the App is not used uses up computing resources and 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, resulting in an unnecessary overhead for the UI.

Managing streams this way, however, 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 that other Apps registered.

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. If you need any further information 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 (legacy) 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 (legacy) Type Description
ffb ??? float Primary force feedback value
ffb2 ??? float Secondary force feedback value
pitch ??? float Current pitch value of vehicle
position.y ??? float Current vehicle y position
position.x ??? float Current vehicle x position
position.z ??? float Current vehicle z position
roll ??? float Current roll value of vehicle
gravity ??? float ???
gx ??? float ???
gy ??? float ???
gz ??? float ???
gx2 ??? float ???
gy2 ??? float ???
gz2 ??? float ???
gxMax ??? float ???
gxMin ??? float ???
gyMax ??? float ???
gyMin ??? float ???
gzMax ??? float ???
gzMin ??? float ???
yaw ??? float Current rotation of vehicle in radians

electrics

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

Name Corresponding Lua names (legacy) Type Description
abs electrics.values.abs float ABS state
airspeed vals.airspeed float Airspeed
altitude vals.altitude float Z axis position
american_taillight_L ??? bool On or off
american_taillight_R ??? bool On or off
axle axleBeamsWheel float Number of axles(?)
beaconSpin electrics.values.beaconSpin int Rotation of beacon emergency lights
blinkPulse blinkPulse int Linked to turn signal flashes
brake M.values.brake float Brake value
brake_input M.values.brake float Brake input value
checkengine electrics.values.checkengine int Check engine light state
clutch M.values.clutch float Clutch value
clutch_input M.values.clutch int Clutch input value
driveshaft driveshaft.electricsName float Driveshaft
esc electronics.values.esc int ESC state. 0 = not present/inactive, 1 = disabled, Blink = active
engineThrottle electronics.values.engineThrottle float Engine throttle state
fog vals.fog int Fog light state
fuel M.fuel float Percentage of fuel remaining
gear_A electrics.values.gear_A float Gear selected in automatic mode
gear_M electrics.values.gear_M float Gear selected in manual mode
hazard vals.hazard int Hazard light state
highbeam vals.highbeam int High beam state
ignition electronics.values.ignition int Engine state
lightbar vals.lightbar int Lightbar state
lights vals.lights int General light state. 1 = low, 2 = high
lowbeam vals.lowbeam int Low beam state
lowfuel electronics.values.lowfuel int Low fuel indicator
lowhighbeam vals.lowhighbeam int Low-high beam state
lowpressure beamstate.lowpressure int Low fuel pressure indicator
oiltemp vals.oil float Oil temperature
parking vals.parking int Parking lights on/off (not implemented yet)
parkingbrake vals.parkingbrake float Parking brake state. 0.5 = halfway on
parkingbrake_input vals.parkingbrake_input int Parking brake input state
reverse vals.reverse int Reverse gear state
rpm vals.rpm float Engine RPM
rpmspin vals.rpmspin float RPM spin(?)
rudder electronics.values.rudder int Rudder input
running electrics.values.running int Engine running state
signal_L vals.signal_L float Left signal state. 0.5 = halfway to full blink
signal_R vals.signal_R float Right signal state. 0.5 = halfway to full blink
signal_left_input vals.signal_left_input int Left signal input state
signal_right_input vals.signal_right_input int Right signal input state
signalLeftState vals.signal_left_input bool Left signal state
signalRightState vals.signal_right_input bool Right signal state
spoiler electrics.values.spoiler float Active spoiler angle
steering M.values.steering float Steering state
steering_input electrics.values.steering_input float Steering input state
tcs electrics.values.tcs int TCS state. 0 = not present/inactive, 1 = disabled, Blink = active
throttle M.values.throttle float Throttle state
throttle_input electrics.values.throttle float Throttle input state
turboBoost electrics.values.turboBoost float Turbocharger boost pressure
turboRpmRatio electrics.values.turboRpmRatio float Turbo RPM ratio
turnsignal vals.turnsignal float Turn signal value. -1 = Left, 1 = Right, gradually 'fades' between values. Use "signal_L" and "signal_R" for flashing indicators.
verticalVelocity vals.verticalVelocity float Z axis velocity
watertemp electronics.values.watertemp float Water temperature
wheelspeed M.values.wheelspeed float Wheel speed
4ws ??? float ???
auto_1st ??? int ???
auto_2nd ??? int ???
auto_drive ??? int ???
auto_neutral ??? int ???
auto_p ??? int ???
auto_sandwich ??? int ???
accz ??? float ???
accz_n ??? float ???
accz_x ??? float ???
cust_airspeed ??? float ???
custom_throttle ??? float ???
cust_yaw ??? float ???
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 ???
jy_bl ??? float ???
jy_br ??? float ???
jy_fl ??? float ???
jy_fr ??? float ???
vsi ??? float ???

engineInfo

This is to do with the drivetrain and some general physics values and settings.

Name Corresponding Lua names (legacy) 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 (Currently not functional in the game)
[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 mass in kg.

Name Corresponding Lua names (legacy) Type Description
beams_total data.stats.beam_count int Total number of 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 noncollidable 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 (legacy) Type Description
[0] ??? float Torque table
[1] ??? float Power table


tcsData

Information relating to traction control system data.

Name Corresponding Lua names (legacy) Type Description
throttleFactor throttleFactor float Throttle threshold
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 (legacy) 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 Calculates the difference between expected and actual yaw
desiredYawRateSteering desiredYawRateSteering float Ideal rotation speed for turning

forcedInductionInfo

Information relating to turbochargers.

Name Corresponding Lua names (legacy) Type Description
backpressure backpressure float Backpressure from compressed air
boost turboPressure float Amount of boost pressure produced
bovEngage bovEngaged boolean Closed (0) or open (10)
coef assignedEngine.forcedInductionCoef float Efficiency coefficient of the turbocharger
inertia turboInertiaFactor int Turbine momentum; resistance to change in state
rpm rpm float RPM of the turbine
throttle assignedEngine.throttle float Throttle state
wastegateFactor wastegateFactor float Wastegate on turbo open or closed