6 motor drivetrain code for auton

Our team has switched the drivetrain from a 4 motor, 4 wheel drive to a 6 motor, 4 wheel drive. And I don’t know how to make the separate motors (lf, lm, lb, rf, rm, rb) in to one name called “drivetrain”. I’ve seen other posts about coding 6 motor drivetrains but I don’t know how to implement them into what I need.

I just want to know how I can add all 6 motors in to the name drivetrain to then add to auton
so I’m able to use the driveFor function.

These are the posts I’ve seen that are relevent

So far I’ve not been able to find a post that completely helps

2 Likes

If you look at the VEX API documentation for the drivetrain (drivetrain constructor) it shows that the first two arguments are motor groups named l and r. These correspond to your left and right drivetrain motors respectively.

Now, the motor group (motor_group constructor) is constructed through 2 (or more) motor arguments (the ... means an unlimited number of arguments can go there.)

So, what you need to do is create 2 motor groups, one with your three left motors and one with your three right motors. Afterwards, you can pass those into the drivetrain constructor along with all other needed parameters.

Hope this helps!

3 Likes

like this?

Looks correct to me! If it doesn’t work, come back to this thread and I’ll be glad to help.

2 Likes

If you look at the bottom of the screenshot it gives me an error when using the driveFor command. And when I used this on another program it works.

What’s the error? It might be because you don’t have the parameters.

myDrivetrain.driveFor(forward, 15, inches);
2 Likes

So that solved it but it acts weird, when I type rev it gives an error. However when I type fwd, Forward, or reverse it doesn’t give me an error. Thanks anyways.

It thinks that rev is referring to the rotation units rev which is short for revolutions. You need to either type out reverse or set it to forward and just make the number negative for it to work.

2 Likes

Okay Thanks for helping me :smile:

So I just tried make an auton and it starts to spin when I say drive forward

const int wheelTravel = 275;

const int trackWidth = 370;

const int wheelBase = 330;

motor_group driveL(lf, lm, lb);

motor_group driveR(rf, rm, rb);

drivetrain Drivetrain(driveL, driveR, wheelTravel, trackWidth, wheelBase, mm);




void autonomous(void) {

Drivetrain.setDriveVelocity(350, pct);

Drivetrain.driveFor(forward, 45, inches);

FrontClaw.set(true);

Drivetrain.driveFor(reverse, 30, inches);

BackClaw.set(true);

BackClaw.set(false);

lift.spin(fwd, 250, pct);

Drivetrain.turnFor(80, degrees);

Drivetrain.driveFor(reverse, 15, inches);

BackClaw.set(true);

Drivetrain.driveFor(forward, 13, inches);

lift.spin(reverse, 250, pct);

}

And as soon as it starts it spins, it doesn’t give me any error

We found the reason why it was spinning; it’s the left side moving first then the right is there a fix for this?

you could also do it a harder way like this

Left1.startRotateFor(vex::directionType::fwd, 846, vex::rotationUnits::deg);
Left2.startRotateFor(vex::directionType::fwd, 846, vex::rotationUnits::deg);
Left3.startRotateFor(vex::directionType::fwd, 846, vex::rotationUnits::deg);
Right1.startRotateFor(vex::directionType::fwd, 846, vex::rotationUnits::deg);
Right2.startRotateFor(vex::directionType::fwd, 846, vex::rotationUnits::deg);
Right3.rotateFor(vex::directionType::fwd, 846, vex::rotationUnits::deg);

as this also allows for swerve turns and is versatile

1 Like

I could try it

20char

When using the RotateTo functions, the default behavior is that the WaitForCompletion is set to true, which will cause the robot to go in circles or fight against itself (especially if you have brake mode set to hold).

You want to set the WaitForCompletion value to false for the first 5 motors, then you can set the sixth one to true.

R1.rotateTo(500, rotationUnits::deg, 100, velocityUnits::pct, false);
R2.rotateTo(500, rotationUnits::deg, 100, velocityUnits::pct, false);
R3.rotateTo(500, rotationUnits::deg, 100, velocityUnits::pct, false);
L1.rotateTo(500, rotationUnits::deg, 100, velocityUnits::pct, false);
L2.rotateTo(500, rotationUnits::deg, 100, velocityUnits::pct, false);
L3.rotateTo(500, rotationUnits::deg, 100, velocityUnits::pct, true);
2 Likes

I need the command to be spinFor with either time or distance; Is there any way to turn off the WaitForCompletion with the spinFor command?

It’s the same for spinFor. Just set all to false until the last motor.

1 Like

I tried but it gave me an error

Can you post the error? Our team uses spinFor as well. Here’s a snippet of what their spinFor code is. It’s a 4 motor drive, but the concept is the same.

RightFront.spinFor(forward, 1000, degrees, false);
RightRear.spinFor(forward, 1000, degrees, false);
LeftRear.spinFor(forward, 1000, degrees, false);
LeftFront.spinFor(forward, 1000, degrees, true);
2 Likes

In both distance and time I can’t usefalse

OK. spinFor does not have an overloaded method that accepts distance such as inches or mm. I don’t think any of the Spin methods accepts distance as a parameter. If you want distance, then you’ll have to convert distance to degrees or rotations.

For the spinFor using time it doesn’t have a WaitForCompletion parameter. So you can just have
lm.spinFor(forward, 2.5, sec);

3 Likes