I am a new user on VEX Forums and I am facing issues with my current code for competition template. The autonomous and driver control functions do not work when running the code and changes made to the motor’s direction (false/true parameter in the motor() function do not change the direction of the bot. Is there a reason as to why this is happening? Help is greatly appreciated.
main.cpp:
type or paste code here
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;
// define your global instances of motors and other devices here
/*---------------------------------------------------------------------------*/
/* Pre-Autonomous Functions */
/* */
/* You may want to perform some actions before the competition starts. */
/* Do them in the following function. You must return from this function */
/* or the autonomous and usercontrol tasks will not be started. This */
/* function is only called once after the V5 has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/
//VEXcode Device constructors
controller Controller1 = controller(primary);
motor leftMotorA = motor(PORT6, ratio6_1, false);
motor leftMotorB = motor(PORT10, ratio6_1, false);
// above is the lone topmost motor
motor leftMotorC = motor(PORT8, ratio6_1, true);
motor_group LeftDriveSmart = motor_group(leftMotorA, leftMotorB, leftMotorC);
motor rightMotorA = motor(PORT5, ratio6_1, false);
// above is the lone topmost motor
motor rightMotorB = motor(PORT2, ratio6_1, true);
motor rightMotorC = motor(PORT3, ratio6_1, true);
motor_group RightDriveSmart = motor_group(rightMotorA, rightMotorB, rightMotorC);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 295, 40, mm, 1);
motor Intake1 = motor(PORT15, ratio6_1, false);
motor Intake2 = motor(PORT14, ratio6_1, false);
motor_group IntakeGroup = motor_group(Intake1, Intake2);
digital_out DigitalOutA = digital_out(Brain.ThreeWirePort.A); //Pneumatics
inertial Inertial6 = inertial(PORT6);
//VEXcode generated functions
//define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
//define variables used for controlling motors based on controller inputs
bool DriveTrainLNeedsToBeStopped_Controller1 = true;
bool DriveTrainRNeedsToBeStopped_Controller1 = true;
bool Controller1LeftShoulderControlMotorsStopped = true;
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/*---------------------------------------------------------------------------*/
/* */
/* Autonomous Task */
/* */
/* This task is used to control your robot during the autonomous phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void Autonomous(void) {
IntakeGroup.spinFor(forward, 1000, rotationUnits::rev, false);
LeftDriveSmart.spinFor(forward, 2, rotationUnits::rev, false);
RightDriveSmart.spinFor(forward, 2, rotationUnits::rev);
}
/*---------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void usercontrol(void) {
// User control code here, inside the loop
while (1) {
// --- Drivetrain Control ---
// Calculate drivetrain motor velocity from controller joystick axis
int drivetrainLeftSpeed = Controller1.Axis1.position() + Controller1.Axis3.position();
int drivetrainRightSpeed = -1 * Controller1.Axis1.position() - -1 * Controller1.Axis3.position();
// Deadband check for left side
if (drivetrainLeftSpeed < 5 && drivetrainLeftSpeed > -5) {
if (DriveTrainLNeedsToBeStopped_Controller1) {
LeftDriveSmart.stop();
DriveTrainLNeedsToBeStopped_Controller1 = false;
}
} else {
DriveTrainLNeedsToBeStopped_Controller1 = true;
}
// Deadband check for right side
if (drivetrainRightSpeed < 5 && drivetrainRightSpeed > -5) {
if (DriveTrainRNeedsToBeStopped_Controller1) {
RightDriveSmart.stop();
DriveTrainRNeedsToBeStopped_Controller1 = false;
}
} else {
DriveTrainRNeedsToBeStopped_Controller1 = true;
}
// Spin left drive motors if outside deadband range
if (DriveTrainLNeedsToBeStopped_Controller1) {
LeftDriveSmart.setVelocity(drivetrainLeftSpeed, percent);
LeftDriveSmart.spin(forward);
}
// Spin right drive motors if outside deadband range
if (DriveTrainRNeedsToBeStopped_Controller1) {
RightDriveSmart.setVelocity(drivetrainRightSpeed, percent);
RightDriveSmart.spin(forward);
}
// --- Intake Control ---
// Check L1/L2 buttons to control intake motors
if (Controller1.ButtonL1.pressing()) {
IntakeGroup.spin(forward, 12.0, volt); // Spin intake forward
} else if (Controller1.ButtonL2.pressing()) {
IntakeGroup.spin(reverse, 12.0, volt); // Spin intake in reverse
} else {
IntakeGroup.stop(); // Stop intake motors when buttons are released
}
// --- Clamp ---
// Check R1/R2 buttons to control intake motors
if (Controller1.ButtonR1.pressing()) {
DigitalOutA.set(true);
} else if (Controller1.ButtonR2.pressing()) {
DigitalOutA.set(false);
}
}
// Wait for a short period to prevent overloading the CPU
wait(20, msec);
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
// Set up callbacks for autonomous and driver control periods.
// Competition.autonomous(Autonomous);
Competition.drivercontrol(usercontrol);
// Run the pre-autonomous function.
pre_auton();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}
P.s. There is nothing in robot-config.cpp, it is the same as a blank competition template.