Pneumatic Code Issue

I’m using PROS by Purdue to actuate a piston, but after each cycle of the loop the piston retracts, and I’m not sure why. How would I be able to keep it in the extended position? (The delay is there because without it the piston won’t actuate, due to it being retracted right after). (Also I tried to see if I did the same in VEXCode V5 but it worked correctly there) Here is my code, where I have the button to extend the piston:
if (wingButton.isPressed()) {

The solonoid should not change its state unless specifically told to (in the program) OR if you have a dogy solenoid cable etc.

It seems like what is happening is that whenever the button to open the wing is pressed the acuator will toggle itself (open and close). You need to be checking for a new button press, which is when a button is pressed once. Because you are not checking for a new button press inside a infinite loop, it will constantly toggle itself on and off potentially damamging the acuators.

This is how I personally would write the solenoid toggle.

bool toggle_wings(pros::controller_digital_e_t button, bool wing_toggle, pros::ADIDigitalOut solonoid) {
        // Checks if the button has been pressed, runs once while pressing then changes to false.
        if (controller_main.get_digital_new_press(button)) {
            // Inverts the wings state. e.g. if currently true this will invert it to false.
            wing_toggle = !wing_toggle;
        return wing_toggle;

You would then call this function passing in the parameters for your wings (if they are set up independently of each other).

1 Like