# X-Drive with Encoders

I was wondering if the encoder programming is any different for an X-drive? Our robot goes at a slight angle so we added encoders to the back two wheels, but since the wheels are at an angle doesnt this effect how they are programmed?

Thank you and I hope everyone is having a great thanksgiving!
Cassidy

It shouldn’t matter if you’re just comparing the encoders to keep travelling straight. However, I noticed that on our x drive, even though it was compensating for turning, it would still drift left or right (strafing). You may experience problems with drift if you only use these encoders. I solved this by using a gyro to measure turning, then the dual encoders measured whether it should strafe to compensate for drift.

Just keep in mind that the wheels go root(2) unit for 1 unit forward.

One really easy way to convert this, like Cody Said, is just to do this:

``````
SensorValue[leftEncoder]*sqrt(2) = leftEncoderCount;
SensorValue[rightEncoder]*sqrt(2) = rightEncoderCount;
``````

One tip about X-Drives, though. Always view the motors and their speeds as vectors (Speed being magnitude and the direction of the motor being the direction and angle of the vector). Once you do that, it is really simple to find ways to move in any direction when you have an X-Drive. Its a great thing!

If you’re trying to PID a holo with 2 encoders, It won’t work, sadly :C Because the front motors will freak out if they don’t have encoders.

What do you mean?

We have an X drive with two encoders on the back, and the robot has been perfectly calm.

The only restriction of not having them on all four is that you can’t measure how much you are turning or curving while strafing sideways, something that we decided is really pointless for saving 4 ports and a lot of room.

Sorry, this is what I meant. I only bring this up because my autonomous recorder requires all 4 motors to have encoders for the accuracy.

You can do it with just two (plus a gyro). But using four is more accurate. We found that the two of get averaged together mostly so just two overall would technically work.

Field based holonomic works wonderfully but you need to use the gyro angle all the time instead of assuming 45 degrees (sqrt of 2 part)

I have 4 IEMs on each wheel of the xdrive. How do I compensate for the strafing issue? I do not want to use a gyro. Is there an equation to figure out this issue?

A gyro is much easier, but you asked…

We will assume a rigid robot that does not flex.

You can figure out the rotation you just did from the last time by looking at the change in all the encoders in one direction or the other. If you are trying to go straight, this is your rotational error in IME ticks. That value is also the arc length of the circle you just rotated. The arc length divided by the radius is the rotation in radians you just went. What you rotated gives you what your new pointing direction looks like too in case you are really trying to turn.

If you want to get rid of rotation, then compensate back for the rotation you have seen by all the ticks on all four encoders.

http://www.themathpage.com/atrig/arc-length.htm

What is left on the encoders since the last reading is the movement of either X and Y directions for each wheel. I would look at the robot on a 45 degree offset from the front of the robot so the two sets of wheels give each axis easily. You can now plot the change from the last position in each axis. You went so far on the X and so far on the Y since the last time around.

You can now rotationally translate the whole thing back to the front face coordinates view if you want now that you know how far you went. You can also go figure out the edges of your robot and where it may collide with things like the walls or where to expect a line follower to get a hit.