Calculating the braking distance/time for car-prototype.

Place to post guides, observations, things related to modding that are not mods themselves.
Drakomir
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Aug 03, 2017 4:47 pm
Contact:

Calculating the braking distance/time for car-prototype.

Post by Drakomir »

Hello folks,

Can anyone tell the formula that Factorio uses to calculate the decelleration (meters / tick) of a car-prototype?
How does the Braking_Power, Friction and Weight apply here?
Are there any other variables I have to take in account, like surface wind speed and direction, terrain friction?

Eventually I want to calculate the time and distance it takes to come to stop (speed = 0) from any given speed.

Thanks in advance.

Kind regards,

Drakomir
Drakomir
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Aug 03, 2017 4:47 pm
Contact:

Re: Calculating the braking distance/time for car-prototype.

Post by Drakomir »

I think I found the formula I was looking for.

Given the following parameters:

A car-prototype with the following constants of interest:
  • weight (mass)
  • consumption
  • braking_power
  • friction (internal rolling resistance, applied regardless of riding_state.acceleration)
The terrain-friction-modifier is defined in the tile-prototype that car-entity is currently positioned on.
In Factorio 15.34 the following values apply:
  • Concrete=0.8
  • Stone=1.1
  • Dirt=1.4
  • Grass=1.6
  • Sand=1.8
Friction is calculated with the following equation: F = 1 - (car-friction + car-friction * terrain-friction-modifier).

The surface' wind-speed and wind-direction does not seem to affect the car-entity.

Kinect energy equation of the car-entity: E = 0.5 * mass * velocity * velocity.
Braking is expressed in Wattage, so by dividing this value by 60 (ticks / second), you have the amount of Joule you can subtract from the car-energy each tick (while braking).
Acceleration works in the opposite way as braking, by adding the consumption / 60 towards the energy level of the car each tick (while your car.energy (burner) > 0).

Note: car-enery = kinect momentum, car.energy is the energy provided by the burner.

The energy-level is a virtual value that defines the behavior of the car-entity, you can only derive it with your mod. But with it you can calculate the exact (rounding error's aside) the braking-distance or braking-time given a certain starting velocity.
The friction is the energy multiplier, if the car is coasting (not accellerating or braking) the new/next-tick energy-level will be E-next = E-current * F-current. F-current depends on the surface the car is coasting on.

Code: Select all

E = kinectic energy
F = friction
V = velocity

V-current = (2 * E-current / mass) ^ 0.5
V-next = (2 * E-current * F-current / mass) ^ 0.5
I hope this helps anyone who's looking for the same answers.
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Calculating the braking distance/time for car-prototype.

Post by darkfrei »

I've made some mode to get positions, speed and acceleration of the car.

The example of output (with a little bit of mathematics), x-axis: ticks; y-axis: speed, tiles/sec
With brake
With brake
2017-09-27 21_05_54.png (9.38 KiB) Viewed 2591 times
Without brake
Without brake
2017-09-27 21_32_07.png (8.62 KiB) Viewed 2589 times
You must make a new game for testing, not playable.
CarSpeed_0.0.1.zip
(97.9 KiB) Downloaded 112 times
Drakomir
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Aug 03, 2017 4:47 pm
Contact:

Re: Calculating the braking distance/time for car-prototype.

Post by Drakomir »

Thanks Darkfrei, the graph's seem to correspond with my own findings.
Post Reply

Return to “Modding discussion”