What to return for WPI_TalonSRX using Commands in VSCode (Java)?

So, we are currently trying to code the hatch mechanism for our robot. I created a command “HatchMechanism” and, to get it to spin, I wrote this code:

boolean hatchSpinning = true;
public void toggle()
{
if(hatchSpinning)
{
hatchTalon.set(ControlMode.PercentOutput, 0.8); // raises the claw
Timer.delay(waitTime); // seconds
hatchTalon.set(ControlMode.PercentOutput, 0);
hatchSpinning = !hatchSpinning;
System.out.println(“hatch mech going up”);
}
else if(!hatchSpinning)
{
hatchTalon.set(ControlMode.PercentOutput, -0.8);
Timer.delay(waitTime);
hatchTalon.set(ControlMode.PercentOutput, 0);
hatchSpinning = !hatchSpinning;
System.out.println(“hatch mech going down”);
}
}

Then, in the Robot file, in Teleop, I wrote:

if(driverStick.getRawButton(HATCH_SPINNER_BUTTON))
{
hatchSpin.toggle();
}

(hatch spinner button is the button you press to spin the hatch mechanism and hatchSpin is the WPI_TalonSRX for spinning the hatch mechanism.)

When I do that, I get an error, saying “he method toggle() is undefined for the type WPI_TalonSRX.” So I then change public void toggle() to:

public WPI_TalonSRX toggle()

But when I do that, I get an error message that says “This method must return a result of type WPI_TalonSRX”

What do I return? Or am I doing something wrong? Any help is appreciated. I am a new coder for my team. Thanks!

1 Like

Seeing the code from your Robot class would help, but my guess is that hatchSpin is an instance of WPI_TalonSRX rather than your HatchMechanism class.

1 Like

Thank you so much! It worked!

1 Like