On our controller, buttons 3 and 4 aren’t working with the code that we have. When we test the code with the buttons, the code keeps saying “false” while not pressed but “true” while pressed but if we assign button 3 or 4 to that certain command it comes out “false” and just stops printing when the button is pressed. What do you think is happening and how can we resolve it?
Take a look at the USB section of the Driver Station program. If you select your joystick from the list, you should see a little section on the right that shows all the joystick buttons and axes. It could be that the button numbers on your joystick don’t actually match up with the numbers Driver Station sees.
The numbers do line up, our team checked it.
Well that definitely narrows it down to something in your code! Can you share the relevant part of your program where you try to use these joystick buttons?
system.out.println(oi.operator.getrawbutton(3));
So you say that it stops printing when the button is pressed? That doesn’t make sense, because getRawButton
returns a boolean, and if that line of code was executing, it would have to print something.
Is this print statement in a command, or some other part of the code that wouldn’t always execute? You may want to try doing that print statement in teleopPeriodic
just to guarantee that nothing else would be preventing it from running.
Yes, that statement is in teleopPeriodic, not surrounded by anything. Thats why this is confusing me.
Is the statement after your Scheduler.getInstance().run() line? I suspect that it is. My follow up guess is the command you added to the button is misbehaving and either causing the run() call to not return or throwing an exception that ends up uncaught. Either would cause your print to not appear.
Steve
The statement is before our Scheduler line.
Well, System.out prints are buffered. It could be that your print happened but is still buffered and then the command threw an exception. Are you seeing any errors in the Riolog? You should try attaching the debugger from VS Code and setting a breakpoint at the print line and in the initialize() of the command. This should help narrow things down quite a bit.
Steve
There are no relevant errors in the Riolog.
I would go the debugger route then. I suspect the command is failing to return to the scheduler and hanging things up. However, if that were the case, I would expect errors at the driver station about concerning the lack of response from the robot. This is quite strange.
Perhaps try a different command that doesn’t do anything except return true from isFinished(). If that works, my theory would be strengthened. If it still fails, we are entering some uncharted territory.
Steve
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.