GetRawButton Problem

I was taking a look at last year’s code for FRC and I found out that the .getRawButton does not work in the 2020 version. Like in this line of code OI.getRawButton(RobotMap.intakeMotor) == false; There is a red line on getRawButton. Is there a new way to write this or something? Thank you

If you hover over the red line, does it give you any additional message? What do they say?

"The method getRawButton(int) is undefined for the type OI

It also gives me the option to create a method in the OI of the code, which is a quick fix and I do not think it is going to do something

I would search the WPILib docs and see if any of the methods there could work as a replacement.

Thanks

In 2019 and for several years prior. The OI class was part of your team’s code (along with Main, Robot, and RobotMap). It is not from wpilib. The getRawButton method would have been one that your team added.

That model can still work in 2020, however, there was a new model introduced in 2020 that does not have an OI class. It has Main, Robot, Constants and RobotContainer. Most of what was in OI was moved to RobotContainer.

You are seeing this error because either your 2020 code is using the new model and OI does not exist, or your 2020 code is using the old model, but nobody has added getRawButton to OI.

1 Like

Ok. So how do I add the getRawButton to the OI of my code?

I think what you were looking for is Joystick.getRawButton(int num). So you have to construct a joystick before you can get a button.

1 Like

Where would I do that, in the OI or in the RobotMap?

OI.java. What exactly are you trying to do though?

Im trying to complete a command, in where when the button of the robot intake is no longer pressed, then it would stop spinning the motor.

Instead of doing it manually, you could make a JoystickButton by passing in the Joystick object, and then the button # to the JoystickButton constructor. After that, you make a command that spins the motor in execute(), and stops it in end(). Then you can bind that command to the button using whileHeld().

For example, in OI.java

public class OI {

  Joystick driverJoystick = new Joystick(RobotMap.DRIVER_JOYSTICK_ID);

  public OI() {
    JoystickButton inputButton = new JoystickButton(driverJoystick, RobotMap.DRIVER_INTAKE_BUTTON);

    inputButton.whileHeld(new IntakeCommand());
  }

}
1 Like

Then how would it look in the Command. I am kinda new at this and I can’t figure this out

In the command, you run the intake motor in execute() and stop it in end()

1 Like

OK thanks

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