How do you program a 6 motor drivetrain

We have been wanting to implement a 6 motor drivetrain for a long time but have been lacking the knowledge to carry it out. Normally we would just set up the drivetrain by using the configuration tab but there is no base configuration for a six motor drivetrain.

(All edits are for grammar corrections and inserting images)
For VEXcodeV5 PRO you have to make all the motors present in the side tab. For it to go one speed do something like

function Drive_Forwards {
Motor1.spin(forwards)
Motor2. spin(forwards)
Motor3. spin(forwards)
Motor4. spin(forwards)
Motor5. spin(forwards)
Motor6. spin(forwards)
}
Function Stop_Drive {
stop.(Motor1)
stop.(Motor2)
stop.(Motor3)
stop.(Motor4)
stop.(Motor5)
stop.(Motor6)
}
If (joystick-value2>=30) {
Drive_forwards ()
}
Else () {
Stop_Drive ()
}
To go backwards, revert the 30 to a -30
For multiple speeds, that takes a while and using functions takes more time then direct coding.
I can give a demonstration picture in like 2 hours (I did that all from memory)
also DO NOT COPY THIS CODE it probably wont work, its just for the idea. Good luck, more to come in 2 hours

If programming in VEXcode Blocks, you’re out of luck – there is no way to set up a drivetrain object with more than 2 motors on each side.

But in text (either in VEXcode or VEXcode Pro), you can initialize a drivetrain object with as many motors as you want on each side by first creating a motor_group for each side of the drive – for example:

const int wheelTravel = 320;
const int trackWidth = 320;
const int wheelBase = 130;
motor_group driveL(Motor1, Motor2, Motor3);
motor_group driveR(Motor4, Motor5, Motor6);
drivetrain myDrivetrain(driveL, driveR, wheelTravel, trackWidth, wheelBase, mm);
14 Likes

Looks like I’ve been doing it the hard way

1 Like

@holbrook does this setting have more than 3 speeds? I need to know if I should switch or not

I’m not sure what you mean by “more than 3 speeds” but the snippet above is initializing the same drivetrain object that you can get in the graphical setup menu.

After setting up the drivetrain, is there a good way to control it with a controller?

The general approach is to have an infinite loop in the usercontrol function which reads the values of several joystick axes, does some math to them, and applies the desired power level to the motors (or in this case, the motor groups) accordingly.

If you search on the fourm for terms like “tank drive” and “arcade drive”, you’ll get lots of threads with code examples.

4 Likes

In addition, the Examples and Tutorials in VexCode Pro include Tank and Arcade drive examples for a clawbot, which demonstrate the control-loop approach. On the internet:

https://kb.vex.com/hc/en-us/articles/360035593152-Arcade-Control-VEX-C-

I have seen teams wire up to the Controller’s Axis’ changed event. While one could award bonus points for thinking in event terms, this is generally not an appropriate case for using them.

3 Likes

Lord’s of the forums your help has been legendary and my gratitude is sincere.

1 Like

By “more then 3 speeds” I mean does the joystick control the speed at intervals (and if so how many) or is it smooth (wherever you put the joystick that’s the speed the motors will go)

I’m honestly shocked vex hasn’t added a 6 motor drive yet, they had tons of requests for the 4m drive when v5 was introduced but they later added that, where’s the 6m? I’ve seen tons of people that want it and many that have done it, I don’t see why they wouldn’t as it has many benefits.

I was at a couple events this past week and competed in vex, I saw one or two bots that had 6m drive and they just didn’t really work all that well as they were jerky and too fast because of poor coding. Adding an option for 6m would make it much easier to do and make it more accessible to the teams that might not know how to use text code.

I really would like to see an option for 6 motor drive at some point, possibly mecanum or holonomic too? I think more options for drivetrains makes the games more interesting and fun and prevents bot design from getting too stale.

1 Like

The drivetrain class is not limited to 4 motors. The motorgroup class can handle max 15 motors, so theoretically you could have a 30 motor drive, although obviously the V5 brain cannot handle that. many. Graphical configuration only supports 2 and 4 motor drivetrains, but it’s trivial to setup a 6 motor drivetrain in code (assuming you are using text and, in my opinion at least, most VRC teams should not be using blocks unless they are complete beginners).

This is all it takes.

motor leftMotorA(PORT1, ratio18_1, false);
motor leftMotorB(PORT2, ratio18_1, false);
motor leftMotorC(PORT3, ratio18_1, false);
motor_group LeftDriveSmart(leftMotorA, leftMotorB, leftMotorC);

motor rightMotorA(PORT8, ratio18_1, true);
motor rightMotorB(PORT9, ratio18_1, true);
motor rightMotorC(PORT10, ratio18_1, true);
motor_group RightDriveSmart(rightMotorA, rightMotorB, rightMotorC);

inertial TurnGyroSmart(PORT20);

smartdrive Drivetrain(LeftDriveSmart, RightDriveSmart, TurnGyroSmart, 319.19, 320, 40, mm, 1);
8 Likes

Yeah I was mostly referring to graphical coding I knew it was possible with text but we don’t have anyone on our team at the moment that knows how to code so we were left with blocks. I think adding more drive options to the graphical version would be really nice for the teams like ours that are left in a spot where they want do something but their only limitation is not knowing how to code it.

Thank you for the advice though, I have really been wanting to learn how to do more text coding and I think it is a definite requirement if I want to move up in vex but I don’t have that much knowledge of it. I only know a little bit of python from a class I took in middleschool many years ago.

For the code you sent, where would that go? I know when you input a 4m drive from the robot configuration tab it goes into a separate file that is linked with the main one, should that code go in the same one or just the main file under “while driver control”? sorry if that seems really dumb, again I’m not really that familiar with C++.

One would expect that teams building more advanced robots would also be programming at a more advanced level. I would not hold my breath for advanced features in the graphical languages, as they are are generally used for younger kids and beginners. In our organization, we try to transition our students to text-based between MS and early HS. Our most advanced teams (HS and U-Team) use PROS.

2 Likes

In VexCodePro you can Enable Expert Robot Configuration by clicking on the project title and then check the Enable Expert box.

Once you do this you can no longer use the Configuration on the right

image

5 Likes

Thank you so much for the help, would it be possible for you to send your whole configuration file so I can see how you did it? That would help a lot, I don’t know how to set up the drivetrain control stuff in text code.

File: RobotConfig.h

using namespace vex;

extern brain Brain;

// VEXcode devices
extern controller Controller1;
extern smartdrive Drivetrain;
extern motor_group LeftDriveGroup;
extern motor_group RightDriveGroup;

void  vexcodeInit( void );

File: RobotConfig.cpp

#include "vex.h"

using namespace vex;
using signature = vision::signature;
using code = vision::code;

brain  Brain;
controller Controller1 = controller(primary);

// Left Motors and motor group
motor leftMotorA = motor(PORT1, ratio18_1, false);
motor leftMotorB = motor(PORT2, ratio18_1, false);
motor leftMotorC = motor(PORT3, ratio18_1, false);
motor_group LeftDriveGroup = motor_group(leftMotorA, leftMotorB, leftMotorC);

// Right Motors and motor group
motor rightMotorA = motor(PORT11, ratio18_1, true);
motor rightMotorB = motor(PORT12, ratio18_1, true);
motor rightMotorC = motor(PORT13, ratio18_1, true);
motor_group RightDriveGroup = motor_group(rightMotorA, rightMotorB, rightMotorC);

// Drivetrain control
distanceUnits units = distanceUnits::in;  //Imperial measurements - inches.
double wheelTravel = 4 * M_PI;  //Circumference of the drive wheels (4" x PI)
double trackWidth = 18;         //Distance between the left and right center of wheel. 
double wheelBase = 15;          //Distince between the center of the front and back axle. 
double gearRatio = 1;           //Ratio of motor rotations to wheel rotations if using gears.


//Drivetrain code if using an Inertial Sensor
inertial DrivetrainInertial = inertial(PORT21);
smartdrive Drivetrain = smartdrive(LeftDriveGroup, RightDriveGroup, DrivetrainInertial, wheelTravel, gearRatio);

//Use the following Drivetrain code if NOT using an Inertial Sensor
//drivetrain robotDrive(LeftDriveGroup, RightDriveGroup, wheelTravel, trackWidth, wheelBase, distanceUnits::in );


void vexcodeInit( void ) {
  Brain.Screen.print("Device initialization...");
  Brain.Screen.setCursor(2, 1);
  // calibrate the drivetrain gyro
  wait(200, msec);
  DrivetrainInertial.startCalibration(1);
  Brain.Screen.print("Calibrating Gyro for Drivetrain");
  // wait for the gyro calibration process to finish
  while (DrivetrainInertial.isCalibrating()) {
    wait(25, msec);
  }
  // reset the screen now that the calibration is complete
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1,1);
  wait(50, msec);
  Brain.Screen.clearScreen();
}

File: main.cpp

#include "vex.h"

using namespace vex;
using signature = vision::signature;
using code = vision::code;

brain  Brain;
controller Controller1 = controller(primary);

// Left Motors and motor group
motor leftMotorA = motor(PORT1, ratio18_1, false);
motor leftMotorB = motor(PORT2, ratio18_1, false);
motor leftMotorC = motor(PORT3, ratio18_1, false);
motor_group LeftDriveGroup = motor_group(leftMotorA, leftMotorB, leftMotorC);

// Right Motors and motor group
motor rightMotorA = motor(PORT11, ratio18_1, true);
motor rightMotorB = motor(PORT12, ratio18_1, true);
motor rightMotorC = motor(PORT13, ratio18_1, true);
motor_group RightDriveGroup = motor_group(rightMotorA, rightMotorB, rightMotorC);

// Drivetrain control
distanceUnits units = distanceUnits::in;  //Imperial measurements - inches.
double wheelTravel = 4 * M_PI;  //Circumference of the drive wheels (4" x PI)
double trackWidth = 18;         //Distance between the left and right center of wheel. 
double wheelBase = 15;          //Distince between the center of the front and back axle. 
double gearRatio = 1;           //Ratio of motor rotations to wheel rotations if using gears.


//Drivetrain code if using an Inertial Sensor
inertial DrivetrainInertial = inertial(PORT21);
smartdrive Drivetrain = smartdrive(LeftDriveGroup, RightDriveGroup, DrivetrainInertial, wheelTravel, gearRatio);

//Use the following Drivetrain code if NOT using an Inertial Sensor
//drivetrain robotDrive(LeftDriveGroup, RightDriveGroup, wheelTravel, trackWidth, wheelBase, distanceUnits::in );


void vexcodeInit( void ) {
  Brain.Screen.print("Device initialization...");
  Brain.Screen.setCursor(2, 1);
  // calibrate the drivetrain gyro
  wait(200, msec);
  DrivetrainInertial.startCalibration(1);
  Brain.Screen.print("Calibrating Gyro for Drivetrain");
  // wait for the gyro calibration process to finish
  while (DrivetrainInertial.isCalibrating()) {
    wait(25, msec);
  }
  // reset the screen now that the calibration is complete
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1,1);
  wait(50, msec);
  Brain.Screen.clearScreen();
}
5 Likes

Alright thank you so much!

1 Like

It is possible to program a six motor drive in VEXcode blocks, my team did it. You have to program the whole drive train manually with the blocks instead. It may take some time to get right, but for those who can’t use vex code pro you can get it to work well.