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:
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.