Custom Code Help

I am trying something that has not been done with vex iq. THIS IS NOT FOR COMPETION USE. I am doing a 4 motor drivetrain with mecanum wheels. That I would like to be able to strafe. Along with a 110 rpm pitching machine and ball intake. I need some help coding it. I did FTC in high school and I am trying to do what I did there but with the vex iq kit to see if it is even possible. I am using 7 motors.
Here is the layout of it:
Left Motor drivetrain ports- port 5 and 6
Right Motor drivetrain ports- port 11 and 12
Pitching Machine ports- ports 6 and 10
Intake port- port 2
If I could get some help with these that would be amazing. I am in college now and I know my mechanical stuff really well but I don’t know very much about coding. If I could get some help coding I would greatly appreciate it. I know this may not be possible but I would really love to see my FTC experiences finally come to life with vex iq to be able to share how FTC ideas can be accomplished with the vex iq kit.


For the mecanum drive:

Exactly how you set it up is down to personal preference, but let’s assume that A is forwards/backwards. B is strafe and C is rotate left and right (axis as they appear on the IQ controller labels)

The basics of each motor speed would be:

Front right motor = A - C - B
Back right motor = A - C + B
Front left motor = A + C + B
Back left motor = A + C - B

What programming environment are you using?

1 Like

I am planning on using vexcode iq just because I don’t have much coding experience. My thoughts for controlling would be using A for forwards and backwards. B for left and Right. C for strafing.

OK. Try making a start using the logic above then let us know how you get on. The program logic in blocks will be something like:

spin frontLeft motor forward
spin frontRight motor forward
spin rearLeft motor forward
spin rearRight motor forward
   set frontLeft velocity to (A + B + C)
  //will let you work out the others

So outside your loop, you’ll set all motors to go forward. Sounds illogical initially, but when your code gets inside the loop you’ll see that with the joysticks neutral, all motors will have a velocity of 0 so won’t move. As you move the joysticks, some will get positive values and some will get negative.

You need to be careful though, before you jump in trying holonomic code, write some code for a basic tank drive just to sanity check that all your motors go in the right direction. Use the sliders under each motor in the device menu if you need to reverse any.


So pretty much what you need is a button setup to control different motors to strafe.

if you’re using Expert Robot Config, here is the .h and .cpp files you need:

for .h :

using namespace vex;

extern brain Brain;

extern controller Controller1;

extern motor FL;

extern motor FR;

extern motor BL;

extern motor BR;

void vexcodeInit(void);

for .cpp :

#include “vex.h”

using namespace vex;

brain Brain;
controller Controller1;
vex::motor FL = vex::motor(vex::PORT5,vex::gearSetting::ratio18_1);
vex::motor FR = vex::motor(vex::PORT11,vex::gearSetting::ratio18_1);
vex::motor BL = vex::motor(vex::PORT6,vex::gearSetting::ratio18_1);
vex::motor BR = vex::motor(vex::PORT12,vex::gearSetting::ratio18_1);


  • Used to initialize code/tasks/devices added using tools in VEXcode Pro.
  • This should be called at the start of your int main function.
    void vexcodeInit(void) {
    // Nothing to initialize

And for the actual button press:

#include “vex.h”

using namespace vex;

int main() {

else if(Controller1.ButtonRight.pressing()){


and of course, you would put the button press inside you’re drive code in the while loop.

The OP stated that they are using VEX IQ. This example looks like it would be for V5.

My bad, I didn’t see that. But pretty much, to strafe left, you have the front left and bottom right motors moving reverse, and the front right and bottom left motors moving forward, and vice versa to strafe right.