V5 Inverted Controls

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.

I just checked here on VEXcode (same internally more or less as VCS). Left motors move forward when joystick is pushed forwards, obviously the right motors move the other way as you specified directionType::rev.

How did you define the motors ? Did you reverse them when defining them in VCS ? sort of looks like you did in pros.

Oh sorry, just to clarify. The VCS code is old. The PROS one is technically correct. But for whatever reason, even if I change the direction of the motors they move the same way. Joystick pushed forward moves the motors backwards. Almost as if the change in direction does nothing to the motor output. Sometimes it randomly does work without change to the code, just restarting the program. It always invalidly registers buttons as well. For instance, though the code isn’t posted, the X button is set to move the tilter forward but instead, it does nothing and B moves the tilter forward.

I did in pros but not VCS. A unique thing about the problem on VCS is that the left joystick Y-axis moves both sides of the chassis and the right doesn’t do anything. Also, the robot moves forward in VCS when the joystick is pulled back. I will reverse directions tomorrow. But what confuses me is that the right joystick literally does nothing even though it’s set to move the right side of the chassis.

The left side of the chassis is geared in a way that both the motors spin in the same direction which is why “true” or “false”/ “rev” or “fwd” is the same for the respective side of the robot that those motors are on. I hope that made sense.

It’s a strange problem. In terms of code, for me, the logic checks out. Only one thing, in your PROS code setDriveMotor() is called within a while loop and keeps redeclaring leftJoytrick and rightJoystick, why could be problematic.

Ultimately, I don’t think that will cause the problem you see.

Oh I should probably put that outside of the function. But yeah, this doesn’t seem to be causing the problem. In general, I think if you guys keep asking me questions and give me better ideas on trouble shooting the problem, I will be better able to solve it.

NOTE: I also tried with a different controller. Also, the last time I updated the brain was in April but I don’t think that is a problem per se. Mainly because I’m not in a competition setting at the moment. Also, does PROS automatically update the brain because I have not seen any notifications to update like I have in VCS.

Well, the PROS code seems to do exactly what you are asking it. The motors are set to run reversed so when you push joystick forward they run in reverse.

1 Like

I don’t understand why it’s the other way around for me. The motors run backwards when I push the joystick forward and the other way around when I push it backwards. Then the buttons don’t fully register when I press them. Sometimes they work, other times they don’t do anything. Tomorrow I will retry setting up the motors. Here is a picture of the chassis just so you can see if my configuration is somehow wrong:
image
*Note this is an old image but the configuration is exactly the same. This is an image of the back of the chassis. So the intended forward direction is furthest away from the camera.

On VCS the left joystick controls both sides of the chassis even though I have it set up to control the chassis sides to the respective joystick. I can take a video tomorrow but I don’t really want to leek my robot so I’ll pm you.

yes, that’s what you are asking them to do, that’s what I said your code does for me as well.

this creates a motor instance with the motor direction reversed.

pros::Motor driveLeftFront(11, pros::E_MOTOR_GEARSET_18, true, pros::E_MOTOR_ENCODER_COUNTS);

Do you really mean the motors or the wheels ?
Are you referencing the motor direction to the arrow on the motor casing ?

Yes. The problem is that I changed the motor directions and nothing happened. And this still doesn’t explain why the buttons register only sometimes.

Also, technically speaking, the direction of the motor should turn the wheel the same way just because of the way it’s setup.

There’s nothing in your code above that references buttons so I can’t comment on that. Perhaps post the whole program or zip it up and add as an attachment.

Okay, here is the file zipped up. Vex TowerTakeover.zip (1.4 MB)

I hope this isn’t just some huge misunderstanding and I completely overlooked everything. But to be fair, I’ve tried troubleshooting this issue for weeks and nothing happens which leads me to believe that the problem may or may not be with my code or motor configuration. If it’s the former, sorry for wasting your time. If it’s the latter, I hope I can fix the issue asap because my driver needs practice.

I re-reversed the directions of the motors, I’ll download it first thing tomorrow and see if that changes anything.

so in that version you have

pros::Motor driveLeftFront(11, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveLeftBack(12, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveRightFront(17, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);
pros::Motor driveRightBack(18, pros::E_MOTOR_GEARSET_18, false, pros::E_MOTOR_ENCODER_COUNTS);

so motors are not reversed.

I ran the code (had to comment out the gyro.reset() call as that was an error) and the motors move forward as expected.

lift and intake motors respond to buttons ok, can’t test your tilter as that needs a pot for feedback.

when did you add gyro.reset() ? There is no function called reset() on a 3 wire analog input. Perhaps you have been downloading an old build to the robot.

Yes, I changed that right before I .zip the file. I will rebuild and download the project onto the brain but that still doesn’t explain the unresponsive buttons and the VCS controller axis problem. I am almost certain I already tried this configuration but just to be sure I will retry it.

Again, can’t comment without seeing the code. VCS is obsolete, switch over to VEXcode if you do any more tests with that.

The gyro should be ignored for now but it’s always been there, I just haven’t tested any code with the gyro as of now. Should I comment out all the gyro instances and declarations. Also, the lift and intake motors aren’t plugged into the brain, does that impact the code output? I have it pre-coded to avoid the hassle later on.

This is not the case because I always rebuild the project before uploading. Though I can’t guarentee I did that when I first encountered the problem because it was so long ago.

Okay, I have Vexcode downloaded I just never made a project on it because the VCS one was done before it became obsolete. I’ll try it with Vexcode tomorrow.

what I mean’t was, with gyro.reset() in the code it will not build. so any subsequent upload to the V5 would just upload an old binary.

Is this really the case? I don’t get any errors when I build the project. Does the compiler ignore it even though it’s not supposed to be there? If so, I’ll just delete it. What’s the proper way to set the gyro value to 0?

Oh another thing to add. I have a potentiometer sending the calibrated values to the screen. It was working but then randomly (or so I presume) it stopped sending values and remained at a constant value of 826 (or something around there. Can you double check to see if I messed that up? It was working earlier today but before I left it stopped updating or calibrating as well.