Help with custom six motor drivtrain in C++

Hello, I’m having some problems trying to make a custom six-motor drivetrain with the ability to be able to be called upon the same way as a regular drivetrain.driveFor
in Vex V5 so help would be appreciated.

void customDriveFor(double distance, int velocity) {
    // Encoder is just the thing that lets me do .driveFor like with a normal drivetrain
    int target = distance * 360 / (4 * 3.14159); // Wheel diameter is 4 inches 

    // Reset count for all motors
    Motor1.setPosition(0, degrees);
    Motor20.setPosition(0, degrees);
    Motor11.setPosition(0, degrees);
    Motor4.setPosition(0, degrees);
    Motor5.setPosition(0, degrees);
    Motor10.setPosition(0, degrees);

    // Set motors velocity
    Motor1.setVelocity(70, percent);
    Motor20.setVelocity(70, percent);
    Motor11.setVelocity(70, percent);
    Motor4.setVelocity(70, percent);
    Motor5.setVelocity(70, percent);
    Motor10.setVelocity(70, percent);

    // Start motors
    Motor1.spin(forward);
    Motor20.spin(forward);
    Motor11.spin(forward);
    Motor4.spin(forward);
    Motor5.spin(forward);
    Motor10.spin(forward);

    // Checks if the encoder reached its target goal 
    while ((Motor1.position(degrees) + Motor20.position(degrees) + Motor11.position(degrees) +
            Motor4.position(degrees) + Motor5.position(degrees) + Motor10.position(degrees)) / 6 < target) {
        wait(10, msec);
    }
   // 20, 11 = left 5, 10 = right 
    // Stop motors
    Motor1.stop();
    Motor20.stop();
    Motor11.stop();
    Motor4.stop();
    Motor5.stop();
    Motor20.stop();
    //Ties the motors to the joysticks 
    int axis3Position = Controller1.Axis3.position();
    //int axis2Position = Controller1.Axis3.position();  
    if (axis3Position> 0.0) {
     Motor20.spin(forward);
    }
    else {
      Motor20.stop();
    }
   wait(20, msec); // Small delay to prevent the CPU from committing suicide
}  

edit: code tags added by mods, please remember to use them.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.