Skip to content

Wheel Encoders

Some of the new car models are equipped with wheel encoders, which work by detecting magnets placed in the rim of the car wheel through a Hall sensor. The latest electronics firmware (>= 2.4) is capable of detecting if the car model it is mounted on is equipped with such sensors. If the firmware detects motion of the wheels, it will send the frequency at which the wheels are rotating to CRS.

Data Pipeline

The time difference between two subsequent triggers of the Hall sensor is measured by an STM32 chip on the CRS PCB. The car firmware then converts these time differences into a rotational velocity of each wheel:

\[ \omega = \frac{f_\text{clk}}{\Delta n_\text{ticks}} \cdot \frac{2\pi}{n_\text{Magnets}} \]

where \(n_\text{Magnets}\) is the number of magnets placed on the rim of each tire (assuming they're evenly placed).

The wheel frequencies \(\omega_i, i = 1...4\) are sampled at 250Hz and published by the ros_wifi_com node upon receiving them from the vehicle PCBs. The published topic is /vehicle_namespace/wheel_speed and all measurements are in rad/s.

Measurement Function

The speed in each wheel frame is calculated as

\[ v_{wheel} = v_{car} + \dot \phi \times r_{b,wheel} \]

where \(r_{b,wheel}\) is the position of the wheel in the body frame and \(\dot \phi\) is the yaw rate of the car.
The back wheels align with the \(x\)-axis of the body frame so the wheel speed in wheel turn direction is the same as the car speed in \(x\)-direction.
The front wheels are turned by the steer angle so the wheel speed in wheel turn direction is

\[ cos(\alpha) \cdot v_{x,wheel} + sin(\alpha) \cdot v_{y,wheel} \]

where \(\alpha\) is the steer angle.

The lateral and longitudinal velocity of the front wheels in body frame are given as

\[ \begin{gathered} v_{x,fl} = v_x - 0.5 \cdot b_{car} \cdot \dot \phi \\ v_{x,fr} = v_x + 0.5 \cdot b_{car} \cdot \dot \phi \\ v_{y,fl} = v_y + l_{front} \cdot \dot \phi \\ v_{y,fr} = v_y + l_{front} \cdot \dot \phi \end{gathered} \]

where \(b_{car}\) refers to the car width, \(l_{front}\) is the length from the center of gravity (CoG) to the front axis and \(v_x\) is the velocity in longitudinal direction of the CoG.

The velocity of wheel in wheel-turn-direction, note the rear wheel velocity coincides with the car speed in longitudinal direction

\[ \begin{gathered} v_{x,wheel,fl} = v_{x,fl} \cdot cos(\alpha) + v_{y,fl} \cdot sin(\alpha) \\ v_{x,wheel,fr} = v_{x,fr} \cdot cos(\alpha) + v_{y,fr} \cdot sin(\alpha) \\ v_{x,wheel,rl} = v_x - 0.5 \cdot b_{car} \cdot \dot \phi = v_{x,fl} \\ v_{x,wheel,rr} = v_x + 0.5 \cdot b_{car} \cdot \dot \phi = v_{x,fr} \end{gathered} \]

The final measurement function is given as the map from the states to the rotational velocity of each wheel

\[ f(\begin{bmatrix} x & y & \phi & v_x & v_y & \dot \phi \end{bmatrix}) = \begin{bmatrix} \frac{v_{x,wheel,fl}}{r_{wheel}} & \frac{v_{x,wheel,fr}}{r_{wheel}} & \frac{v_{x,wheel,rl}}{r_{wheel}} & \frac{v_{x,wheel,rr}}{r_{wheel}} \end{bmatrix} \]

where \(r_{wheel}\) is the wheel radius.