Clutch Lockup Logic State Machine

Started by
1 comment, last by Alberth 6 years, 3 months ago

Hi fellow game devs,

With the help of  @CombatWombat in my previous post about clutch modeling, I now have a solid direction for the modeling the clutch. The way I'm doing it is having 2 clutch states: locked and unlocked. EngineRPM and torque will be calculated separately in each state. My problem right now is the logic and code for specifying locking and unlocking.

The condition for locking is when (engineSpeed - drivetrainSpeed) in previous update cross zero (different sign) with the current update (to determine if engineSpeed = drivetrainSpeed or not in-between updates) and engineTorque <= clutchTorque.

The condition for unlocking is when engineTorque > clutchTorque.

The diagram looks roughly like this (taken from matlab website with the similar implementation):

sldemo_clutch_figure2.png

 

However, the 2 conditions are triggers for switching states, not for determine the current state to be in, so in the end my clutch state just jumped around. I don't have a lot of experience in doing state machine, so can some one give me rough code of how to implement this? Below is my rough code:


speedError = engineSpeed - drivetrainSpeed;
if ((Math.Sign(speedError) != Math.Sign(deltaW) && currentTotalEngineTorque <= clutchReactTorque))
                {
                    clutchLocked = true;
                }
                else clutchLocked = false;

deltaW = speedError;

//end of update

I think the main struggle is the cross zero. Because cross zero is the "trigger condition" to check if the clutch should lock when it is slipping, not the condition for continuous locking, while the code I have above is the "continuous condition" saying "this condition is true then it is locked/unlocked". Another word, if the clutch is slipping, the condition above would decide if it's locked or not, but once it is locked, the cross zero condition is not true anymore (since speedError and deltaW have same sign as engineSpeed == drivetrainSpeed when clutch is locked). I'm sorry that I cannot explain this better as English is not my first language.

Advertisement

Never doen anything like this, but perhaps add an explicit state that you're in (eg a boolean 'locked'), and add some hysteresis such that, when you switch state, the switch back to the previous state will not trigger easily?

This topic is closed to new replies.

Advertisement