Drivetrain Won't Work

Hello, I have set up a drivetrain in my code, but when I run the program and try to steer/drive my robot, it doesn’t drive. All the other motors work. The drivetrain is 2 motors, with no servos. The left motor is port 1, and the right motor is port 2.

/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       C:\Users\lrhoda0178                                       */
/*    Created:      Sat Jan 23 2021                                           */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/

// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name]               [Type]        [Port(s)]
// Controller1          controller                    
// Elevator             motor         21              
// Mid_Intake           motor         20              
// Low_Intake_L         motor         19              
// Low_Intake_R         motor         18              
// High_Intake          motor         17              
// Drivetrain           drivetrain    1, 2            
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"
#include "robot-config.h"


using namespace vex;
/*
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();
  
}*/
// Include the V5 Library

  
// Allows for easier use of the VEX Library
using namespace vex;

float myVariable;

event message1 = event();
event why_am_i_here_______ = event();

//AUTONOMOUS CODE PATH
void autonomous(void){;
Low_Intake_L.rotateFor(vex::directionType::fwd, 2000 ,vex::rotationUnits::deg);
}

//DRIVETRAIN






// "when started" hat block
int whenStarted1() {
  // Set all motors to max speed
  Mid_Intake.setVelocity(100.0, percent);
  Low_Intake_R.setVelocity(100.0, percent);
  Low_Intake_L.setVelocity(100.0, percent);
  High_Intake.setVelocity(100.0, percent);
  Elevator.setVelocity(100.0, percent);
  Drivetrain.setDriveVelocity(100.0, percent);
  Drivetrain.setTurnVelocity(100.0, percent);
  return 0;
}
// "when started" hat block
//Spin intakes and elevator when A or B are pressed
int whenStarted2() {
  while (true) {
    if (Controller1.ButtonA.pressing()) {
      Elevator.spin(forward);
      High_Intake.spin(forward);
      Mid_Intake.spin(forward);
    }
    else {
      if (Controller1.ButtonB.pressing()) {
        Elevator.spin(reverse);
        High_Intake.spin(reverse);
        Mid_Intake.spin(reverse);
      }
      else {
        Elevator.stop();
        High_Intake.stop();
        Mid_Intake.stop();
      }
    }
  wait(5, msec);
  }
  return 0;
}

// "when started" hat block
//Spin lower left and right intakes when r1 or r2 are pressed
int whenStarted3() {
  while (true) {
    if (Controller1.ButtonR1.pressing()) {
      Low_Intake_R.spin(forward);
      Low_Intake_L.spin(forward);
    }
    else {
      if (Controller1.ButtonR2.pressing()) {
        Low_Intake_R.spin(reverse);
        Low_Intake_L.spin(reverse);
      }
      else {
        Low_Intake_R.stop();
        Low_Intake_L.stop();
      }
    }
  wait(5, msec);
  }
  return 0;
}



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

// A global instance of brain used for printing to the V5 Brain screen
brain  Brain;

// VEXcode device constructors
motor Mid_Intake = motor(PORT7, ratio18_1, false);
motor Low_Intake_R = motor(PORT5, ratio18_1, false);
motor Low_Intake_L = motor(PORT4, ratio18_1, true);
motor High_Intake = motor(PORT6, ratio18_1, true);
motor Elevator = motor(PORT8, ratio18_1, false);
controller Controller1 = controller(primary);
motor LeftDriveSmart = motor(PORT2, ratio18_1, true);
motor RightDriveSmart = motor(PORT1, ratio18_1, false);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 295, 40, mm, 1);

// VEXcode generated functions
// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
// define variables used for controlling motors based on controller inputs
bool Controller1RightShoulderControlMotorsStopped = true;
bool Controller1UpDownButtonsControlMotorsStopped = true;
bool Controller1XBButtonsControlMotorsStopped = true;

// define a task that will handle monitoring inputs from Controller1
int rc_auto_loop_function_Controller1() {
  // process the controller input every 20 milliseconds
  // update the motors based on the input values
  while(true) {
    if(RemoteControlCodeEnabled) {
      // check the ButtonR1/ButtonR2 status to control Elevator
      if (Controller1.ButtonR1.pressing()) {
        Elevator.spin(forward);
        Controller1RightShoulderControlMotorsStopped = false;
      } else if (Controller1.ButtonR2.pressing()) {
        Elevator.spin(reverse);
        Controller1RightShoulderControlMotorsStopped = false;
      } else if (!Controller1RightShoulderControlMotorsStopped) {
        Elevator.stop();
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1RightShoulderControlMotorsStopped = true;
      }
      // check the ButtonUp/ButtonDown status to control High_Intake
      if (Controller1.ButtonUp.pressing()) {
        High_Intake.spin(reverse);
        Controller1UpDownButtonsControlMotorsStopped = false;
      } else if (Controller1.ButtonDown.pressing()) {
        High_Intake.spin(forward);
        Controller1UpDownButtonsControlMotorsStopped = false;
      } else if (!Controller1UpDownButtonsControlMotorsStopped) {
        High_Intake.stop();
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1UpDownButtonsControlMotorsStopped = true;
      }
      // check the ButtonX/ButtonB status to control Mid_Intake
      if (Controller1.ButtonX.pressing()) {
        Mid_Intake.spin(reverse);
        Controller1XBButtonsControlMotorsStopped = false;
      } else if (Controller1.ButtonB.pressing()) {
        Mid_Intake.spin(forward);
        Controller1XBButtonsControlMotorsStopped = false;
      } else if (!Controller1XBButtonsControlMotorsStopped) {
        Mid_Intake.stop();
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1XBButtonsControlMotorsStopped = true;
      }
    }
    // wait before repeating the process
    wait(20, msec);
  }
  return 0;
}

/**
 * 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 ) {
  task rc_auto_loop_task_Controller1(rc_auto_loop_function_Controller1);
}
int main() {
  task rc_auto_loop_task_Controller1(rc_auto_loop_function_Controller1);

  // post event registration

  // set default print color to black
  printf("\033[30m");

  // wait for rotation sensor to fully initialize
  wait(30, msec);

  vex::task ws1(whenStarted2);
  vex::task ws2(whenStarted3);
  whenStarted1();
}

Can anybody give me information on why the Drivetrain isn’t working? I have it set up as left-stick driving in the same controller as the rest of the motors. I am new to coding, so it could just be a simple mistake.
Here’s a photo of the drivetrain:
Screenshot (3)
If you have any suggestions that might work, please tell me them, as we have a competition tomorrow, and we won’t be able to have a pre-game code without this.

Can I see how you set up your controller? It’s most likely due to the fact that you deleted the robot-config.cpp file. Also, it seems that you never have any of the callbacks for a tournament, so it wouldn’t work anyways. Like my earlier suggestion, just remake the code under the competition template.

2 Likes

I deleted the robot-config.ccp file and pasted it into this one, since, for some reason, the robot wasn’t including it, but the code would count things as an error if it had simply been copied and pas. ted while the robot.ccp file was still there, or if it wasn’t copied and pasted. The reason no other motors are set up to the controller is because multiple motors are binded to single buttons in the code, making it useless (I believe) To bind anything other than the drivetrain to the controller. Screenshot (4)
(The robot-config-ccp file keeps redownloading for some reason at times, so I have to make sure to delete it before uploading it, or else I’ll get a compiler error)

The robot config.cpp basically determines how your program will function if using the drivtrain object. Like I said, you should just recreate your program in the competition template. Alternatively, if this worked in vexcode v5 text(non pro), just stick to that.

2 Likes

I just added the motors, controller, and drivetrain, and
A) There’s quite a bit of errors
B) After I fixed the errors, the drivetrain still wouldn’t drive

Can you post your updated code?

Also, your current program would violate rule R28, as it says that for programming, you should use the competition template or a functional alternative. Based on what you see, the callbacks aren’t ever set up. Therefore, your program wouldn’t work in a competition.
@TaranMayer would I be correct in the assumption that @Pyro52718B would violate R28?

No? Absolutely not. The code won’t work, but it doesn’t break any rules. You’d have to try very hard to break the rules regarding programming and auton.

1 Like

Don’t use drivetrain. Drivetrain is bad. Instead, add in all of your drive motors individually. And yes, use the premade competition template that vexcode provides.

1 Like