Hello! Our coder this year has been coding for 2 years and this is their third. They never had issues with what i’m about to ask you, but cannot figure this out.
Basically, our intake and wall stake mech (Bound to L1 and L2, and R1 and R2 respectively) are spasming whenever going backwards (L2 and R2). They are using a simple if, else if, else loop.
// INTAKE
INTAKE.setVelocity(90, percent);
INTAKE.setMaxTorque(100, percent);
if (Controller1.ButtonL1.pressing()){
INTAKE.spin(forward);
}
else if (Controller1.ButtonL2.pressing()){
INTAKE.spin(reverse);
}
else {
INTAKE.stop();
]
// WALLMECH
WALLSTAKE.setVelocity(90, percent);
WALLSTAKE.setMaxTorque(100, percent);
if (Controller1.ButtonR1.pressing()){
WALLSTAKE.spin(forward);
}
else if (Controller1.Button2.pressing()){
WALLSTAKE.spin(reverse);
}
else {
WALLSTAKE.stop();
}
A couple things to know before answering our question:
We are using VEXcode V5 (Not Visual Studio/PROS)
We are NOT using the auto device set up, as we are using a 6 motor drive and auto device set up doesn’t like it.
We have checked every other forum we could find that related to our problem, so please, if you’re going to refer us to another thread, i would rather you just copy the solution into this thread.
Any spelling errors in the code are my bad, I had to manually type that.
Every other function runs fine, and it downloads, no error messages or warnings.
We have tried using While true loops and callbacks/functions. I probably missed some too (I’m not the coder)
We use C++, this isn’t translated block. We won’t be able to understand any block or python solutions.
Thank you so much for any help!
When the motors are “spasming,” are they going between spinning backwards and spinning forwards or are they going between spinning backwards and being stopped?
In the case of the latter, your controller buttons might not consistently be registering as pressed, sending an output flickering between pressed and not pressed. To test if this is the case, you can make a simple program that constantly displays whether or not each of the buttons you need to troubleshoot (L2 and R2) are pressed. If the program shows that the button is flickering between pressed and not pressed when the controller button is actually pressed, it is the controller that is causing your robot’s issue. To fix this, you could try a different controller or have a function in the program that makes it so that when a button is pressed, the robot doesn’t immediately react, rather waiting (something like 0.1 sec.) and checking if the button is still pressed before actually reacting to the button being pressed.
Don’t do this as part of the loop (I assume that code is inside a loop). If motors are already spinning, using setVelocity will change the velocity immediately, so if going in reverse it would try and make the motor go forwards as sign is positive.
This post is a different situation, but reflects my view on setVelocity.
It appears that they are going back and forth. It will go backwards a bit, stop for a miniscule amount of time, jerk forward, then move backwards again.
Good info, it pretty much confirms what jpearman said the issue was:
Every time the code gets to the “set velocity” part, it starts spinning the motors at that (positive 90%) velocity, meaning forwards with a speed of 90. It then reaches the part of the code that spins the motors backwards with a button press, reverting back to the backwards direction, and so on.
As for the solution to this problem, it was already mentioned by the very same jpearman, move the “set velocity” code outside of the loop which encompasses the “if _ button pressed, do _” code, so that the velocity would be set to 90% before the loop of what to when buttons are pressed starts.