X Drive problem when driving

So I recently built an X drive for the first time and took a while programming it, but here are some problems I have

  1. Whenever driving forward, it drives backward (I don’t know how to fix it)

  2. I don’t know how to program it to drive it diagonally and rotate (I’m trying to rotate using the right joy stick that moves left or right to rotate)

  3. The motors are off by one, but if I changed the ports by one, the names wouldn’t be correct (like front right would be back right, and bottom right would be top right)

Video of it: Holonomic Drive problem - Album on Imgur

my code:

If you could correct my code and give me some advice, I would appreciate it
my questions:

  1. what value does the right joystick return and how can I use that value to rotate the robot left or right?

2.How do I rebind the motor ports to make it straight?

  1. Are macros allowed in FRC matches, so like if I were to press a button on my controller, can it automatically go to a coordinate on the field without input from the driver?

I will answer question with your pfp being the sole reason.

Just change all the reverses to forwards. The code’s axis additions are correct but that assumes all the motor to be in forward directions.

To do this we can take a look at the top view of an x drive.


As you can see, to turn clockwise, the top left and bottom left motor spins forward while the top right and bottom right motor spins backward. You can incorporate turning by adding another turn component into your original code like this:

void xArcade(double xPower, double yPower, double turnPower){
    // Motor powers, / 127 * 100 to scale from controller pwm to percent
    double TL = (yPower + xPower + turnPower) / 127 * 100;
    double TR = (yPower - xPower - turnPower) / 127 * 100;
    double BR = (yPower + xPower - turnPower) / 127 * 100;
    double BL = (yPower - xPower + turnPower) / 127 * 100;
    double maxPower = std::max({TL, TR, BR, BL});

    // normalizes output
    if(maxPower > 100){
        TL /= maxPower;
        TR /= maxPower;
        BR /= maxPower;
        BL /= maPower; 
    }

    topLeft.spin(vex::directionType::fwd, TL, vex::velocityUnits::pct);
    topRight.spin(vex::directionType::fwd, TR, vex::velocityUnits::pct);
    bottomRight.spin(vex::directionType::fwd, BR, vex::velocityUnits::pct);
    bottomLeft.spin(vex::directionType::fwd, BL, vex::velocityUnits::pct);
}

void main(){
    while(true){
        xArcade(Controller.Axis4.value(), Controller.Axis3.value(), Controller.Axis1.value());
        wait(10, msec); // remember to add a delay
    }
}

Change the port number in the motor constructor.

axis.value() returns the value of the joystick axis between -127 and 127.

Change the port number in the motor’s constructor

Well this is VEX not FRC, but the answer is yes for both competitions.

5 Likes

when I switched all of it to fwd, it just makes the robot rotate right/ left when joystick is up and down.

I also see the arcade function you made and tried to incorperate it, but the std::max is shown as "no member named “max” in namespace “std”

For any question about the legality of something, we must turn to the game manual (or the Official Q&A). As you read the game manual (https://link.vex.com/docs/2022-2023/vrc-spin-up/GameManual ), keep in mind that the game manual tells you things that you must do, and things that you are prohibited from doing. It can’t tell you everything you might do, so if the game manual does not prohibit an action, then it is generally legal.

In regards to your question, what rule in the game manual make you think you cannot have a macro?

3 Likes

I have never seen one that drives the robot to a designated coordinate before in a match

update: I changed some some of the + and - signs and moved some ports around and now I can drive forward and backward but not side ways, but when I turn the joy stick left, I rotate left and when I turn the joystick right, it turns right.

before:

image

after:

image

But isn’t this not just a tank drive on one joystick?

well, no…“tank drive” is a very specific drive method which uses two single-axis control sticks, one for each non-steerable wheel/track set. It’s the most common industrial drive for tracked-vehicles (such as tanks and earth-moving vehicles) as well as small equipment (like a “bobcat” machine) where it is often called “skid steer.”

4 Likes

yeah i realized this was joystick lol

Ok so I managed to solve problem 1 and half of problem 2, by switching some + and = signs. The final problem I have is rotating while strafing or driving forward (I can include Inertial Sensor if needed) . What I’m trying to incorporate now, is a holonomic X-drive.

Search the forum and/or google for “field oriented control”, you may find that scheme makes it easier to make those sorts of movements.

1 Like