Skip to content

Modular Drive Train

BoredEngineer edited this page May 18, 2016 · 2 revisions

The purpose of Modular Drive Train is to model behavior of the elements such as engine, clutch, gear box and etc. both separately and when they are connected together. The idea behind making it modular, is to enable rapid replacement of individual components and assembly of arbitrary drive train without need to change more than few lines of code.

Small video to demonstrate some of the features: https://www.youtube.com/watch?v=IfURzYr2DiM

A lot of credit for this system goes to 0lento as it wouldn't be possible to implement this without his help!

Each component of the drive train is build to be used as replaceable module. The main motivation for this is rather simple - to avoid writing custom implementation for each configuration of the drive train. Let me show you what I mean by this. This is a typical configuration of the car's drive train: If you are building a car racing game, most likely you will be implementing such drive train in one way or another. When you start to add features, such as ability to stall engine, engine drag, locking collar of gear box to gears and etc. you might find yourselves re-writing quite a lot of code as each new feature might require different implementation of other features. Still, it's not too bad as long as general configuration of the drive train stays the same. For example, A_Tracked_Vehicle uses similar configuration with a bit of a trick to enable neutral turn. When configuration changes, you can get into a bit of the trouble as certain assumptions that were true before, such as integrating velocities only at wheels and engine, are not true anymore and integration of velocity have to be done in more places. This is the case with old British and Russian tanks: What they did, is installed clutch for each track in addition to main clutch between engine and gearbox. Driver would have two levers, one for each track, by pulling the lever half way he would control locking of the clutch. Un-clutched track would naturally slow down and tank will start rotating as other track is rotating with full power. By pulling lever even further, it would enable track brake and turn would happen even more rapidly. Mechanically, this wasn't very efficient but very simple system and was quite common on early tanks of WW2. To implement such configuration, we need to integrate velocities in multiple places. The main problem is that we can easily get into combination madness of levers position and how and where torque should be transmitted. To make it even worse, let's look at next exhibit: As far as I know, such system was used on quite a few tanks of WW2, as it was more energy efficient than clutch-brake system and provided driver with a combination of turning radii by switching each steering gearbox into a different position. This is the first practical system which allowed neutral steering where each track would rotate in different direction. Practically, you might not need more than a first configuration, unless you are building more of a simulator and want to highlight differences in vehicles performance and steering. But even in such case, you can have cars with automatic or manual gear box, 4WD or RWD, or even switchable between them as on many SUVs. Modular system will allow you to just change your components and don't bother with a custom logic for each configuration.


How it works?

Each component of the modular drive train needs to implement "DriveTrainModuleComm" interface which has 4 methods:

  • DTUpdateFromSourceToApplication
  • DTUpdateFromApplicationToSource
  • DTReceiveDataFromSourceSide
  • DTReceiveDataFromApplicationSide

"Source" means side of the drive train with the engine and "Application" means side with wheels/tracks.

The idea is that on each Tick (or physics sub-step Tick) each component is "updated" twice and each "update" ends with sending resulting data to next component up (or down) the chain:

So if engine is connected to a clutch and clutch is connected with gearbox. We start with updating engine using "DTUpdateFromSourceToApplication" function call, which sends data to the clutch using "DTReceiveDataFromSourceSide" function at the end of the update. Now as clutch received data from the engine, it does it's own update in "DTUpdateFromSourceToApplication" and sends data to gearbox. In this example, gearbox is the last component and there is no data to send further. As we reached the end of the chain, we start to update components in the backwards direction - gearbox->clutch->engine. For this we use "DTUpdateFromApplicationToSource" functions and "DTReceiveDataFromApplicationSide" to pass data. This way each drive train component can do it's own calculations as a "black box" and the rest don't need to know anything about it. For example, engine doesn't need to know if clutch is locked or not. When clutch is unlocked (completely released and not slipping) clutch will just pass back the same angular velocity to the engine as it received from the engine. When clutch is completely locked (not slipping) it will pass angular velocity received from the engine to the next component, which decides on it's own what should be done with it. The only other consideration is regarding components that can integrate velocity, meaning that they apply torque to change angular velocity on their update. Such components are engine, clutch, gearbox and track sprocket or wheel hub. Not all of them integrate velocity all the time, only when their logic requires to do so. For example, engine integrates velocity on every tick as final engine torque changes with RPM and throttle position. Clutch integrates velocity only when not completely locked as clutch plates will produce friction force. Gearbox integrates velocity when you shift gears and synchro produces friction force to match velocity of lay and drive shafts. Wheels or tracks, integrate velocity from the reaction force as the result of friction with the ground. The pattern is pretty clear: each component that creates or receives torque from outside of the drive train or can "disconnect" drive train - will integrate angular velocity. When components "disconnect" drive train, such as clutch or gear box, they integrate velocity on their "application" side of the shaft. The "source" shaft is considered as responsibility of the component previously in the chain.

Clone this wiki locally