So I made this piston code in my teleopPeriodic in Robot.java. However, since I’m writing in Command, OI would be useless so here’s two things I need help.
How do I connect my pistonFront and pistonRear in my OI to my piston code in Robot.java?
How do I make my code work when I press the button once, the piston comes out and when pressed again, it retracts instead of holding the button?
So as it stands, pushing either button will fire the command.
Both frontPiston and rearPiston booleans are false.
Both if statements will run reading that the vars are false and will call the frontRaise() and rearRaise() methods.
The booleans aren’t designated as true ever, so if you press another button, the command will continue to fire frontRaise() and rearRaise().
This isn’t what you want.
First of all, you have to swap the boolean after the if statement with the frontPiston = !frontPiston, so it becomes the opposite of what it was. This will give you the toggle state you are looking for.
To continue with one command you could pass an argument into the command telling it which if statement you want to fire, then check for that value in the if statement, but that would be more complex.
Personally, I would make two commands, one for each button that raises the front or back separately.
One more thing. When you go to test this for the first time, be careful. If the solenoid air flow is backwards to what you expect, the cylinders may raise the front/back when the code fires up.
You are putting rearLower() and frontLower() in the constructor function of your subsystem. This is correct. But if you have the air flow backwards, rearLower() would actually raise the rear.
You can fix this by swapping the solenoid ports, changing kForward to kReverse or physically swapping which air line goes to which port on the cylinders.
Just be aware this might happen. We put our robot on a couple crates because we didn’t have a chance to test the final solution before the cylinders were installed on the robot.
I don’t know why but this static toggle wasn’t working for us today. I didn’t have time to mess with it, so we came up with a different solution. Instead of firing the command on .whenPressed(), we are going to use .whileHeld(). In the command initialize() method we will extend the cylinder. In the end() method, we will retract the cylinder. This way, the driver has to hold the button for it to stay extended. I think this will make it easier on the driver as well.