Encoder Setup and Understanding WHEEL_DISTANCE

Hello, I have two tracked vehicles I’ve built and I’m nearing completion of my projects, but the wheel encoders are driving me insane.

There are two drive motors (one for each track), I have quadruple checked the wiring.

WENC_CPR = 300
WENC_PINA = 61
WENC_PINB = 60
WENC_POS_X = 0
WENC_POS_Y = 0
WENC_POS_Z = 0
WENC_RADIUS = 0.16
WENC_TYPE = 1
WENC2_CPR = 300
WENC2_PINA = 58
WENC2_PINB = 59
WENC2_POS_X = 0
WENC2_POS_Y = 0
WENC2_POS_Z = 0
WENC2_RADIUS = 0.16
WENC2_TYPE = 1

SERVOX_FUNCTION=GPIO for all four inputs.

My issue:
When I monitor the MAVLINK WHEEL_DISTANCE values, the default starting point is: 0, 0, 0, 0, 0, …

-As I turn the left motor, the value in the first position changes as it should and counts up, and if I reverse it the value subtracts.

-As I turn the right motor motor, the value in the second position changes to an odd value (0.0010472), it flashes between that and 0.

Experiencing the same issue with both systems I’ve built, this is driving me mad. Tried moving the connectors to new positions, same issue.

1 Like

These can be the simple rules to follow and make life easy:

  • Motor 1 is left, motor 2 is right.

  • Forward distance is positive, and backwards distance is negative.

  • Easy assignment: lower number FC signals to motor 1, higher to 2.

  • WENCx_PINx signals are inputs (with interrupt capability on FC).

  • Output controls: for reverse capability you normally have DIRx/PWMx output signals, but also you can use a RC type pulse (ESC: >1500μs forward, <1500μs backwards) for saving FC pins. DIRx correspond to RELAYx and PWMx or RCx to SERVOx.

  • Wheel distances WENCx_POSx to vehicle center should be defined.

Think about pivoting for your case: the FC can go crazy.

For adjustment and checking I prefer to move the vehicle a fixed distance (say 10m), which can be done manually without slipping, and check distances of each wheel on MP (down to cm precision). You should see this:

(ideally straights if speed is constant).

For CCW pivoting (possible on balance bot or tank, difficult on car):

See that left wheel (red) distance is negative, and right wheel distance (green) is positive (opposite for CW pivoting). For correct results, wheel distances to center must be correct (with correct signs).

One of the sensors for the right motor is not configured or connected properly.

Do you have anything else configured to use pin 58 or 59?