V5 Drive Program Issues

Hey guys, I’ve had a very weird issue. I’ve been making a simple program that maps the motors of a drivetrain to joysticks, and then when a button is pressed, run one of the motors (very simple, I know).

The Joystick part would work fine, but when I would add in the button line, it either not work, or the joystick part would start bugging out (or not work entirely).

Any solutions? I’ve never experienced this before. Maybe a firmware update? Idk.

#include "robot-config.h"

int main() {

    while(true){ //while loop (infinite)
     //   maps the controller axis to each motor, tank control
            FrontRight.spin(directionType::fwd, 50, velocityUnits::pct);

You’re changing the speed and possibly direction on FrontRight very rapidly when the button is pressed. Generally this is not good practice.

Try something like:

If ButtonPressed
Do button motor stuff
Do joystick motor stuff
End if

Also, you should probably add a sleep at the end of the loop so the program isn’t hogging the CPU.

My problem is that no matter what motor I program it to, it still bugs out (i.e if I set it to my team’s arm, the same issue persists).

TLDR I can’t drive while using buttons for some weird reason

Read what goofnrox wrote again. There is a problem with control structure. This problem will follow whatever motor you put in that problematic control structure. You are trying to control a motor with a joystick and a button at the same time. One solution to this conflict is to only ever respect either the button or the joystick, which is what goofnrox suggested. Another solution would be to add some number to the joystick if the button was pressed.

What I think you may have done is changed it so it ignores ALL of your joysticks when the button is pressed, when goofnrox was only suggesting you have it ignore the conflicting joystick.