Automotive programming: Understanding slip ratio with Python

Modern vehicles monitor their dynamics at every fraction of time to maintain vehicle stability. For this, significant amount of data flows from every sensor into the ECUs and appropriate action, if a risky event takes place. Vehicle slip is one such event that can cause instability in vehicle and increases the chances of a potential accident.

To understand slip, consider this scenario where you start your vehicle and provide a sudden burst of power to the engine. The drive wheel rotates immediately at a high speed, resulting in a burnout. Similarly, when traveling at a certain speed, if you apply strong brakes, your vehicle results in a skid, which is quite unstable and can result in loss of control. This is what happens when the vehicle slip ratio is too high.

contemporary auto driving on asphalt road with smoke in air
Photo by Erik Mclean on Pexels.com

Modern vehicles are smart enough to realize this slip in individual tyres. The in-built program takes in different measurements from vehicle components and calculates slip in individual tyre. I thought of turning this application into an exercise in Python. Hence, we are going to build a simple Python application that takes in wheel velocity and vehicle velocity and returns the slip ratio.

What is Vehicle Slip Ratio?

Consider the scenario where you are traveling at 80 km/h per hour and you suddenly apply brakes. Assuming that the vehicle is not equipped with ABS, the wheels will get blocked suddenly while the vehicle continues to move in the forward direction. In terms of physics, the velocity of the wheel will be 0 while the vehicle will still have some velocity. This is the vehicle slip in practice.

To define the term, the vehicle slip ratio is the ratio of the difference of wheel velocity and the vehicle velocity to the vehicle velocity. Mathematically, it can be described as follows:

\(\text{Slip Ratio} = \frac{V_{wheel} – V_{vehicle}}{V_{vehicle}} * 100 %\)

It is important to note that the slip ratio is expressed in %. If the vehicle is skidding, the slip ratio will be negative as the wheels would be blocked and their velocity would be 0. On the other hand, in the case of dragging, the slip ratio will be positive as wheel velocity will be greater than that of the vehicle.

A slip ratio between 20-30% is considered to be suitable for the stability of the vehicle. More than that could result in losing control. The ratio depends on many factors like tyre quality, build of the vehicle, coefficient of friction between the tyre and road surface etc.

So now that we have a basic understanding of slip ratio, let us proceed to build a small application in Python.

Python Code

As I mentioned earlier, we will build a system to calculate the slip of all the tyres. The idea is to build a Wheel class that takes in certain parameters like tyre diameter and we will create 4 objects, 1 for each wheel.

import numpy as np

class Wheel:
  def __init__(self, diameter):
    self.diameter = diameter # in meters
  
  def get_slip(self, v_angular, v_vehicle):
    # converting angular velocity into linear velocity
    v_wheel = np.pi*self.diameter*v_angular
    slip_ratio = (v_wheel-v_vehicle)/v_vehicle
    return slip_ratio*100

The get_slip method takes the angular velocity of the wheel (in rpm) and the actual vehicle velocity as arguments. The first step in the function is the convert the angular velocity into linear velocity. This is done by multiplying the tyre circumference with the angular velocity.

Now that we have the class, we will go ahead and create the Wheel instances.

FrontRightWheel = Wheel(tyre_diameter=0.46)
FrontLeftWheel  = Wheel(tyre_diameter=0.46)
RearRightWheel  = Wheel(tyre_diameter=0.46)
RearRightWheel  = Wheel(tyre_diameter=0.46)

Now that we have our wheel instances, we will enter the vehicle velocity and angular velocity. Because this is only a Python exercise and not a practical application, we will manually input these data. The value of vehicle_velocity will be taken from the user, whereas the angular velocity will directly be passed to the method by us in the code.

while True:
    vehicle_velocity = int(input("Enter vehicle velocity in m/s: "))
    
    # manually entering angular velocity for each wheel in rpm
    fr_slip_ratio = FrontRightWheel.get_slip(7,vehicle_velocity=vehicle_velocity)
    fl_slip_ratio = FrontLeftWheel.get_slip(8,vehicle_velocity=vehicle_velocity)
    rr_slip_ratio = RearRightWheel.get_slip(7.3,vehicle_velocity=vehicle_velocity)
    rl_slip_ratio = RearLeftWheel.get_slip(8.5,vehicle_velocity=vehicle_velocity)
    
    print("Slip ratio at front right wheel: {}".format(fr_slip_ratio))
    print("Slip ratio at front left wheel: {}".format(fl_slip_ratio))
    print("Slip ratio at rear right wheel: {}".format(rr_slip_ratio))
    print("Slip ratio at rear left wheel: {}".format(rl_slip_ratio))

Notice that the angular velocity of the left wheels is relatively higher than the right ones. This happens when the left wheels are on a surface with less traction, for instance water or snow, and the right wheels, on the contrary, have more traction. This generates moment in the vehicle about the center of gravity and vehicle would spin as a result.

exercise for python programming

Executing the script will result in the following:

Python
Enter vehicle velocity in m/s: 11
Slip ratio at front right wheel: -8.037015049462424
Slip ratio at front left wheel: 5.10055422918581
Slip ratio at rear right wheel: -4.095744265867958
Slip ratio at rear left wheel: 11.669338868509918

When the wheels have less traction, their linear velocity will be more than that of the vehicle, hence will result into positive slip ratio. This is the case in left wheels as you see in the output. Contrarily, the right wheels, due to less linear velocity than the vehicle’s, have negative slip.

Conclusion

Automobile industry has numerous applications of Python programming and in this blog, we practiced one of them. The ESP in vehicles monitor wheel velocities all the time. In this article, we had a glimpse of implementing the system in Python.

One such other vehicle application that I had implemented in Python was measuring distance using ultrasonic sensors. This system is used in parking sensors to measure the vehicle’s distance against a wall or some hindrance. Can you think of any other system in vehicle that we can implement using Python? Mention in the comments or get in touch with me on social media and we can discuss on it. Maybe it could be the next blog 😉

If you want to stay updated on such interesting posts, subscribe to my *FREE* newsletter and you’ll receive monthly reminders on the posts you might have missed:

Leave a Reply