So I’ve recently had a very unusual problem occur with the v5 system. The reason I say this is because all the controls on the robot are inverted or not working. It’s such an unusual problem to describe, but in clearest terms, basically, whatever I programmed the robot to do, it doesn’t do.
For instance, the Y-axis on the controller is programmed to set the voltage of the chassis motors directly. The motors were initialized with consideration to what direction will make them move forward. I’ve triple checked this just to make sure and I even swapped it around in code to see if it would do anything but the results didn’t yield anything productive.
I also tried doing this across multiple IDE’s. Namely, PROS and then VCS. To debug the issue, I had the robot print the input values from the controller onto the brain screen and the controller works perfectly fine which leads me to believe that the issue is either with the code or with the v5 system itself. I’m straying away from code because I’ve had this triple checked from other teammates and I even had an entire conversation in the unofficial Vex discord about this. People don’t believe me when I say this issue is strange and seemingly my fault though they haven’t thoroughly reviewed my code.
Anyways, I’ll start with the PROS code and the file layout. I have a global hpp file dedicated to storing global variables and global objects. This is where I declared the drive motors. (*Note all my header files are included in the main.h file #ifdef __cplusplus
section and the main.h file is #include
in all my other files). Here’s the code for the global hpp file:
extern pros::Motor driveLeftFront;
extern pros::Motor driveLeftBack;
extern pros::Motor driveRightFront;
extern pros::Motor driveRightBack;
extern pros::Controller controller;
Then I instantiated these objects in their own respective global source file. Here’s the code:
pros::Motor driveLeftFront(11, pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveLeftBack(12, pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveRightFront(17, pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveRightBack(18, pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);
pros::Controller controller(pros::E_CONTROLLER_MASTER);
Then for the chassis, I created its own source file and independent functions for each component of the chassis. Here are the functions I’m using for opcontrol:
void setDrive(int left, int right){
driveLeftBack.move(left);
driveLeftFront.move(left);
driveRightFront.move(right);
driveRightBack.move(right);
}
//DRIVER CONTROL
void setDriveMotors(){
int leftJoystick = controller.get_analog(pros::E_CONTROLLER_ANALOG_LEFT_Y);
int rightJoystick = controller.get_analog(pros::E_CONTROLLER_ANALOG_RIGHT_Y);
//DEADZONE
if(abs(leftJoystick) < 10)
leftJoystick = 0;
else if (abs(rightJoystick) < 10)
rightJoystick = 0;
//PRINT JOYSTICK VALUE
pros::lcd::print(1, "Left Joystick Value: %d", leftJoystick);
pros::lcd::print(2, "Right Joystick Value: %d", rightJoystick);
//SET POWER
setDrive(leftJoystick, rightJoystick);
}
And this is what I have in opcontrol.
void opcontrol() {
while(1){
//CHASSIS CONTROL
setDriveMotors ();
//TILTER CONTROL
setTilterMotor();
//LIFT CONTROL
setLiftMotors();
//INTAKE CONTROL
setIntakeMotors();
pros::delay(10);
}
}
In opcontrol, ignore the other subsystem functions. Note, I’m on Mac and have been having many issues with PROS which may or may not have anything to do with this.
On VCS, this is the code I have:
void driverControl(){
RightDriveFront.spin(directionType::rev, Controller1.Axis2.value(), velocityUnits::pct);
RightDriveBack.spin(directionType::rev, Controller1.Axis2.value(), velocityUnits::pct);
LeftDriveFront.spin(directionType::fwd, Controller1.Axis3.value(), velocityUnits::pct);
LeftDriveBack.spin(directionType::fwd, Controller1.Axis3.value(), velocityUnits::pct);
}
and in the main function:
int main() {
while (1){
driverControl();
}
}
On VCS I just realized I might have deleted the delay at the end of the loop as it is not in my original code but that shouldn’t affect the controller values. Why is it that the controller doesn’t do what my code tells it to do?? On both programs, the controller will make the motors move backwards when pushed forward (which outputs a positive value). I ensured it wasn’t problematic with the motor setup as I reversed different combinations of the motors. And not only that but there is inconsistency with the controller input. Sometimes it will be inverted, and sometimes it will randomly work but only on one axis. The same is true for the buttons, sometimes it doesn’t even register my input even though the button is clearly being pressed and sometimes it will. Sometimes the wrong button will perform the action programmed for another button.
I’ve tried so many things to solve this issue but everything I’ve done to troubleshoot has been ineffective. I wouldn’t be bringing this to the forums otherwise. Am I missing something?? If anythign is unclear with my issue, let me know. I can even include videos if necessary because it’s bizarre. It can also be a careless error that me and my peers missed but I doubt it.