Can't make a drivetrain through motor groups

I’m trying to combine 3 motors on both the left and the right side to make a drivetrain, but I can’t seem to get it to work. I have put my code below if anyone has any ideas what I am doing wrong.

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// lf motor 1
// lm motor 2
// lb motor 3
// rf motor 4
// rm motor 5
// rb motor 6
// ---- END VEXCODE CONFIGURED DEVICES ----

#include “vex.h”

using namespace vex;

// A global instance of competition
competition Competition;

// define your global instances of motors and other devices here

distanceUnits unit = distanceUnits::in;

double wheelTravel = 4 * 3.14;
double trackWidth = 18;
double wheelBase = 15;
double externalGearRatio = 1;

vex::motor_group l = motor_group(lf, lm, lb);
vex::motor_group r = motor_group(rf, rm, rb);

vex::drivetrain sixDrive(motor_group &l, motor_group &r, double wheelTravel, double trackWidth, double wheelBase, distanceUnits unit = distanceUnits::in, double externalGearRatio = 1.0);

void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();

// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, …
}

void autonomous(void) {
// …
// Insert autonomous user code here.
// …
sixDrive.driveFor(forward, 10, inches);

}

Welcome to the forum @alx12 ! And thanks for posting your complete program – that makes things go a lot faster.

In the future, when sharing code on the forum, please include triple backtics (```) before and after your code for formatting.

When you’re creating the drivetrain object you don’t need to include the type of each parameter you’re passing to the constructor, just the value or variable, just as you’re doing with the calls to the motor_group constructor above.

So that line should look like:

drivetrain sixDrive(l, r, wheelTravel, trackWidth, wheelBase, distanceUnits::in, externalGearRatio);

(you could also leave off the last two parameters since you are just setting them to their default values)

4 Likes

Thanks for the Solution!

1 Like

My code looks like this for 2, 3 motor, motor groups

const int wheelTravel = 305;
const int trackWidth = 377;
const int wheelBase = 330;
const double gearRatio = 1.5;
motor_group driveL (LF, LM, LB);
motor_group driveR (RF, RM, RB);
smartdrive myDrivetrain = smartdrive(driveL, driveR, seer, wheelTravel, trackWidth, wheelBase, mm, gearRatio);
1 Like

Thanks for your code! How do you get the numbers for the const ints, and then what units do you use for them? I currently am using random numbers.

1 Like

So wheelTravel is the circufrance of the wheels you are using (so for me it is 4"x pi).
TrackWidth is the width of the robot from the middle of the wheel to the middle of the other wheel (use a tape measurer).
WheelBase is the length of the robot from the axel in the wheel to the axel in the other wheel (use a tape measurer).
I use mm for all of these.
Gear Ratio is the gear ratio, so mine is a 72 tooth gear to a 48 tooth gear drivetrain gear ratio, which 72/48=1.5.
I use smartdrive so I can put an inertial in easily.

2 Likes