How To Implement Multiple Motor To One Joystick

I wrote a program to implement a 6 motor drivetrain into 2 joysticks. The left joystick controls the left side motors and the right joystick controls the right side motors. But I run into the issue of my code not compiling even after looking at several forums. Can someone help me out with this?

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// LeftForwardMotor     motor         1               
// LeftMiddleMotor      motor         2               
// LeftRearMotor        motor         3               
// RightFrontMotor      motor         4               
// RightMiddleMotor     motor         5               
// RightRearMotor       motor         6               
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  const int wheelTravel = 320;
  const int trackWidth = 320;
  const int wheelBase = 130;
  
  motor_group leftMotors(LeftForwardMotor, LeftMiddleMotor, LeftRearMotor);
  motor_group rightMotors(RightFrontMotor, RightMiddleMotor, RightRearMotor);
  drivetrain myDrivetrain(leftMotors, rightMotors, wheelTravel, trackWidth, wheelBase, mm);

  motor[leftMotors] = vexRT[Controller1.Axis3];
  motor[rightMotors] = vexRT [Controller1.Axis2]

}

I believe you are mixing the ROBOTC language with VEXCode

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// LeftForwardMotor     motor         1               
// LeftMiddleMotor      motor         2               
// LeftRearMotor        motor         3               
// RightFrontMotor      motor         4               
// RightMiddleMotor     motor         5               
// RightRearMotor       motor         6               
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

motor_group leftMotors(LeftForwardMotor, LeftMiddleMotor, LeftRearMotor);
motor_group rightMotors(RightFrontMotor, RightMiddleMotor, RightRearMotor);

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
while(1){
  leftMotors.spin(fwd, Controller1.Axis3.Value(), percent);
rightMotors.spin(fwd, Controller1.Axis2.Value(), percent);
vex::task:sleep(10):
}

}

I think this should work, but I’m not quite sure. Haven’t used VEXCode’s motor groups before

3 Likes

Is this not how you configure motors and motor groups?

1 Like

Here is another option using .setVelocity

    int leftSpeed;
    int rightSpeed;

    while (true) {
        //Tank control
        leftSpeed  = Controller1.Axis3.position();
        rightSpeed = Controller1.Axis2.position();

        LeftDriveGroup.setVelocity(leftSpeed, percent);
        RightDriveGroup.setVelocity(rightSpeed, percent);

        wait(20, msec);
    }
1 Like

Can you elaborate a bit more on this? Where are you establishing the 6 motors and where is the ‘LeftDriveGroup’ and ‘RightDriveGroup’ variable coming from?

I made the assumption that you had already had the motor groups configured. Below is an example that should help in VexCode Pro.

1 Like