Coding problem with statements

Hello,

My team is having an issue right now with programming. Basically we recently transitioned from our Practice robot to our real robot. In the process I used phoenix tuner and imaged the robo Rio. What’s happening right now is before I could do a simple statement like

if (stick->GetRawButton(8))
{
allMotors(0.3);
}

And as long as I held the button it would go forward. If I let go it would stop. Noe if I press it, it will continue. Once I let go, it would continue. Even if I disabled and re-enabled it, it would still go. From advice from another user I did it where

if (stick->GetRawButton(8))
{
allMotors(0.3);
}
else
{
allMotors(0);
}

This works. But if I add another one of these at another speed. It would glitch out because it would not know whether to do the allMotors(0) or allMotors(0.3) so it would be like super stuttering. To make things worse now if I run an auto code and disable and go to teleop it does the auto again. I went back to shop bot and the problem doesn’t occur. Help would really helpful. Is it a roborio setting or smt

In order to make the logic work correctly, you have to use else if statements, like this:

if(stick->GetRawButton(8)) {
    allMotors(0.3);
}
else if(stick->GetRawButton(9)) {
    allMotors(0.6);
}
else {
    allMotors(0);
}

This means that when the roboRIO sees that button 8 is not pressed, instead of directly jumping to a conclusion and setting all motors to 0, it first checks if another button is pressed, and if there’s still nothing, then it stops the motors.

As for your auto code still running in Teleop, there could be a number of reasons. I’m assuming that you’re using command-based programming:

  • Your autonomous command was not cancelled when teleop starts.
  • You set the motors to run in auto, but did not stop it when autonomous ends

For the first one, make sure that in your teleopInit() you have something like autonomousCommand.cancel() that stops the auto command. For the second one, either make sure the motor is stopped when the autonomous command (or wherever you’re controlling motors from) ends, or add something like allMotors(0) in your teleopInit(), which should stop all motors first when teleop starts.

Thanks. But do you know how to change it back to how it was

If by that you mean changing the competition bot to be the same as the practice bot, then there is either some aspect of the code that you missed and did not copy over, or if you’re using say different motor controllers on the real bot vs practice bot.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.