Okay, I’m in a bit of a pickle. I just finished a 2-motor drive chassis and am working on programming it. I used some code from last year’s competition robot because it worked well and allowed for variable speed driving. I changed it to work with two motors, but when I download and run the program, the robot will not move no matter what input is used. I checked the robot motors with the “Drive” function of the controller, and they’re working fine. What could be the issue? Is it my code? My code is attached.
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// Inertial3 inertial 3
// RightMotors motor 9
// LeftMotors motor 10
// ---- 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. */
/*---------------------------------------------------------------------------*/
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Controller1.rumble(rumbleLong);
Controller1.Screen.clearScreen();
Controller1.Screen.setCursor(0,0);
Controller1.Screen.print("WHS Vex Robotics");
Controller1.Screen.newLine();
Controller1.Screen.print("Clearing Encoders...");
RightMotors.resetRotation();
LeftMotors.resetRotation();
Controller1.Screen.newLine();
Controller1.Screen.print("Encoders Cleared");
Inertial3.calibrate();
wait(2,sec);
Controller1.Screen.clearLine();
Controller1.Screen.print("Gyro Calibrated");
// 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) {
// ..........................................................................
// Insert autonomous user code here.
// ..........................................................................
}
/*---------------------------------------------------------------------------*/
/* */
/* 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
int deadband=5;
while (true) {
if (Controller1.ButtonR1.pressing()) {
}
else if (Controller1.ButtonR2.pressing()) {
}
else {
}
// Get the velocity percentage of the left motor. (Axis3)
int leftMotorSpeed = Controller1.Axis3.position() * .85;
// Get the velocity percentage of the right motor. (Axis2)
int rightMotorSpeed = Controller1.Axis2.position() * .85;
// Set the speed of the left motor. If the value is less than the deadband,
// set it to zero.
if (abs(leftMotorSpeed) < deadband)
{
// Set the speed to zero.
LeftMotors.setVelocity(0,percent);
}
else
{
// Set the speed to leftMotorSpeed
LeftMotors.setVelocity(leftMotorSpeed,percent);
}
// Set the speed of the right motor. If the value is less than the deadband,
// set it to zero.
if (abs(rightMotorSpeed) < deadband) {
// Set the speed to zero
RightMotors.setVelocity(0,percent);
}
else {
// Set the speed to rightMotorSpeed
RightMotors.setVelocity(rightMotorSpeed,percent);// This is the main execution loop for the user control program.
// Each time through the loop your program should update motor + servo
// values based on feedback from the joysticks.
// ........................................................................
// Insert user code here. This is where you use the joystick values to
// update your motors, etc.
// ........................................................................
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}
}
}
//
// 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);
}
}
edit: code tags added by mods, please remember to use them.