How to add sideways driving with X-Drive

We are driving with X-Drive and want to be able to drive sideways. We currently have tank drive but can not get a program that will also drive the robot sideways.

Below is our programming for tank drive

while (true){;

LeftFront.setVelocity(Controller1.Axis3.position(), percent);
RightFront.setVelocity(Controller1.Axis2.position(), percent);
LeftBack.setVelocity(Controller1.Axis3.position(), percent);
RightBack.setVelocity(Controller1.Axis2.position(), percent);

wait(5, msec);

If anyone could help us get a program to drive sideways, it would be much appreciated.

I have very little coding knowledge so I’m not sure how to do this but as a driver with 5+ years of experience I would not use tank drive for an X-drive. It can work fine, but from past experience, it is easier to drive and strafe if you have one joystick for Forwards-backwards and Left-Right, and then the other joystick for spinning left and right

I found this on the forum, I hope it is helpful


I agree this season I had an x drive, and the controls I found worked best for me were using one stick for strafing/forwards/backwards movement movement and the other for turning. while these controls can be a little confusing at first I quickly got the hang of it.

Secondly, it is important to understand how the x drive does this movement. The more commonly used term is strafing and it is done on a x drive by spinning motors that are opposite one another. So if we understand this we can understand how to do the same in our code. as such

lfPower = (power + turn + strafe);
lbPower = (power + turn - strafe);
rfPower = (power - turn - strafe);
rbPower = (power - turn + strafe);

this particular code above assigns power to each motor based on what turn, strafe and forward/backward values are input from the controller.


I’m not a very good programmer, could you help me change to the one stick driving/strafing and the other turning.

Here is how our team did it we used pros but the same concept will apply. Code Link

It’s normal back and forth like tank drive.

Think of an x drive as 2 tank drives mounted at 90 degree angles to each other.

In order to strafe, just get the x drive to drive sideways. (Think of the side as your new front)

Hope this tip helped


The first thing that is going to happen we are going to create new variables as such:

int power;
int strafe;
int turn; 

We are creating these variables as type int because the controller outputs only whole integers, and so there is no need for float point variables.

next you want to assign these variables a value and that value will come from the controller joystick axes. Mine are set to drive and turn from the right, while the left is for strafing. So if your on VEXcode it will look little something like such:

  power = Controller1.Axis2.value();
  turn = Controller1.Axis1.value();
  strafe = Controller1.Axis4.value();

You then add this these values to new variables which will become your motor output like such

*note you should instantiate this variables together and not as we go along I am theoretically instantiate them apart for the ease of explanation.

int lfPower, lbPower, rfPower, rbPower;

after that you utilize the code I gave above to to combine the variables to one value for motor output:

  lfPower = (power + turn + strafe) * (scaler);
  lbPower = (power + turn - strafe) * (scaler);
  rfPower = (power - turn - strafe) * (scaler);
  rbPower = (power - turn + strafe) * (scaler);

The scaler in the code above can be set to anything you like, or completely remove and will act like sensitivity.

The last step is output the code to the motors. again this is going to be used in the correct syntax for VEX code

  lf.spin(fwd, lfPower voltageUnits::volt);
  lb.spin(fwd, lbPower, voltageUnits::volt);
  rf.spin(fwd, rfPower voltageUnits::volt);
  rb.spin(fwd, rbPower, voltageUnits::volt);

This should leave you with working X-drive code. if you have any issues feel free to DM me or reply on the thread.

1 Like