X-Drive Code

Trying to get my code for X-drive movement to work, but the robot won’t move at all. The math behind the velocities for motor groups is all correct(I double-checked them), but my code is non-functional. Can someone take a look or maybe run it on their x-drive?

The robot won’t move at all… does this include the motors too? What happens when you lift the robot up, and then move the joysticks? Which ways do the motors spin (if at all)?

Are you sure about that? From what I can see, your X-drive has no way to turn since you have no part of the calculations considering Controller1’s Axis1. Additionally, your vela and velb calculations are a lot more complicated than they need to be; X-drive motor calculations typically consist of very simple arithmetic with only pluses and minuses. You do not need to account for the sqrt(2) increase in speed of the X-drive in your code unless you intentionally want it to go slower.


This code was on a different thread but I should work. Just change the name of the motors to the name of your motors and put it in driver control or user control. Also full credit to Mark_Finley

int main()
BackLeft.spin(directionType::fwd,Controller1.Axis3.value()-Controller1.Axis4.value()+Controller1.Axis1.value() , velocityUnits::pct);
FrontLeft.spin(directionType::fwd,Controller1.Axis3.value()+Controller1.Axis4.value()+Controller1.Axis1.value() , velocityUnits::pct);
BackRight.spin(directionType::rev,Controller1.Axis3.value()+Controller1.Axis4.value()-Controller1.Axis1.value() , velocityUnits::pct);
FrontRight.spin(directionType::rev,Controller1.Axis3.value()-Controller1.Axis4.value()-Controller1.Axis1.value() , velocityUnits::pct);

Ah. The question was worded a bit unclearly. The motors do not spin at all and as a result, the reboot doesn’t move.

I built a separate turning function using the other joystick.

The reason why vela and velb are a bit complicated was because I used vectors for my calculations.

Is there an explanation for the code?

That is actually not a good code. When u have joystick values all add up and feed it to motors, it’ll be higher than 100%. Your bot won’t follow the same movement as you intended. What u need to do is to check if any of the output is over 100%. And then take it as the denominator, in order to maintain the output ratio. It’s a bit hard to explain, so I will write a pseudo code here.

void drivebaseControl(){
        frontBack = axis1;
        rightLeft = axis2;
        orientation = axis3;

        if(!(frontBack == 0 && rightLeft == 0 && orientation == 0)){
            denominator = (fmax((fabs(frontBack)+fabs(rightLeft)+fabs(orientation)),1));
            rf = (frontBack - rightLeft - orientation) / denominator;
            lf =(frontBack - rightLeft + orientation) / denominator;
            rb =(frontBack + rightLeft - orientation) / denominator;
            lb =(frontBack + rightLeft + orientation) / denominator;
// and feed these to your motor. I am too lazy to type, It is too annoying that I can not use tab here

I hope someone does Cunningham’s Law on me.

I’d recommend watching this video. It helped me understand how x-drives work and how to make working code for it. Holonomic X-Drive Tutorial VEX #Robotics - YouTube

you need a delay inside your while loop.

it should be


So then it’ll wait 15 milliseconds between looping

1 Like