Presumably this code will end up inside teleopPeriodic?
If that’s the case, this code will be getting run ~50x per second.
So it’s good to keep in mind that the “default” positions you have identified will be re-asserted many times a second.
I would say if you move the code that asserts default positions off into the
robotinit method, and leave the remaining code in
teleopperiodic, your code would make sense to allow toggling the solenoid positions with the different buttons referenced.
The question of will it work is harder to answer because we don’t have the complete robot code or info on how the robot is wired/plumbed, nor a notion of what behaviors/controls you would deem acceptable to solve your problem.
One way you can answer the question for yourself is to execute your code in simulation mode right on your computer. This will allow you to check if what you expect should happen actually does once the code is running.
There’s info here on how to setup and execute your code in sim:
You won’t see a robot do stuff, but you can verify there are no compilation/runtime errors, and then see what happens to your solenoid output states whe. You press the buttons on your keyboard or a real joystick plugged into your computer. It a great stepping stone to verifying your expectations when you don’t have a robot sitting in front of you to deploy code to