Using the 4 Motor Drivetrain With Mecanums

So we are using vexcode and mecanum wheels on our robot. Our autonomous isn’t very reliable so I’m going to be adding an inertial sensor. I looked around and found this drivetrain thing that looks very easy to use and quite effective. The problem is that if I use a drivetrain then I am unable to use motors by themselves in the usercontrol to strafe like I have been doing. Is there a way I can control motors in a motorgroup seperate from the other in the group or is there a mecanum option somewhere in the drivetrain?

Thanks,
Jason

Not true in V5 text; after setting up a drivetrain in the graphical configurator, look in robot_config.cpp and you will see the individual motor objects there. You can address them individually just like you could if you hadn’t set up a drivetrain.

2 Likes

image

it does not appear to be that way…

is there a way to control that port?

I should have checked myself before I posted - turns out the auto-generated robot_config.h only declares the drivetrain object for use in other files, not the underlying motors.

So, you need to add a .h file with the following content:

extern motor leftMotorA;
extern motor leftMotorB;
extern motor rightMotorA;
extern motor rightMotorB;

and then #include that file in main.cpp - or just add those lines to robot_config.h if you have “Expert Robot Configuration” enabled.

edit: also add the following line:

extern inertial TurnGyroSmart;

if you want to access the inertial sensor from main.cpp as well

2 Likes

Ok, thanks. I’ll try that when I get home. Also, if I tell the drivetrain to move forward will It use the inertial sensor to keep a straight line?

nope, you have to code that yourself.

4 Likes

Got it. I got everything working it looks like, if I do something like Drivetrain.driveFor(forward, 50,inches); will it utilize the inertial sensor’s accelerometer to calculate how far it has driven?

99.9% positive It will use the Integrated motor encoders. The inertial sensor is only utilized for turns.

2 Likes

Yeah, makes sense. Thanks.