this is my first time using pneumatics and I have got the pneumatic system arranged but I don’t know how to configure or program the pneumatic piston.Can anyone help?
You can configure the pneumatics system by initializing a “Digital Out” component within your code; this refers to the piston’s solenoid and can be set to either true or false to extend or retract the piston.
I don’t have that option on my version of vex code pro v5. Do I need latest version?
Check under the “3-Wire” category.
I don’t have digital out.
This is what mine looks like in VEXcode Pro v5 (digital out circled):
You might want to double check that you have the newest version as a starting point. Unless there’s something strange with the brain selection, I would think it would be on there otherwise.
Thank you. I have updated to the newest version of vexcode pro v5. I programmed the pneumatics into my code, and I know I have done something wrong. none of the buttons work on the code now. this is my drivercontrol code
Leftfront.spin(forward,Controller1.Axis3.position()+Controller1.Axis4.position()-Controller1.Axis1.position(), percent);
Rightfront.spin(forward,Controller1.Axis3.position()-Controller1.Axis4.position()+Controller1.Axis1.position(), percent);
Rightrear.spin(forward,Controller1.Axis3.position()+Controller1.Axis4.position()+Controller1.Axis1.position(), percent);
Leftrear.spin(forward,Controller1.Axis3.position()-Controller1.Axis4.position()-Controller1.Axis1.position(), percent);
while(true){
if( Controller1.ButtonX.pressing() ) {
piston.set( true );
}
else {
piston.set( false );
}
wait(20,msec);
Start by getting the ‘wait’ inside of the while, see if that helps.
In addition to what Mike said above, move the motor spinning inside the while loop. Also, the problem with if(Controller1.ButtonX.pressing()) is that it will only activate if the button is being actively pressed, and won’t act like a toggle. (This might also blow up your solenoids with too many inputs, but I’m not sure on that point).
TL;DR Put things in while loop, and create a toggle switch.
Im sorry, I didnt understand the last line. Also, is it a problem that I have 2 while loops?
I have changed the code so the piston closes using a limit switch. I havent been able to test if it works or not. At the moment i am just playing around with sensors so i can use them next season.
Okay, so having reformatted this with readable indentation (and adding a closing brace to the snippet), I can see now that your wait(20, msec) was actually inside the while loop.
Keep in mind with this code as you have it here, it will run the code prior to the while(true) loop ONCE, and then go into the while(true) loop and never leave.
What soar was saying was that your motor command should be inside the same while(true) loop, so that all of your commands could work, such as:
while(true){
Leftfront.spin(forward,Controller1.Axis3.position()+Controller1.Axis4.position()-Controller1.Axis1.position(), percent);
Rightfront.spin(forward,Controller1.Axis3.position()-Controller1.Axis4.position()+Controller1.Axis1.position(), percent);
Rightrear.spin(forward,Controller1.Axis3.position()+Controller1.Axis4.position()+Controller1.Axis1.position(), percent);
Leftrear.spin(forward,Controller1.Axis3.position()-Controller1.Axis4.position()-Controller1.Axis1.position(), percent);
if( Controller1.ButtonX.pressing() ) {
piston.set( true );
}
else {
piston.set( false );
}
wait(20,msec);
} // end while(true)
Part two post to follow based on soar’s other recommendation.
What soar was recommending with the toggle, is to do something like this:
bool pistonSetState = false; // Tracks set state of piston
bool waitingOnRelease = false; // Monitor for release of button so that pistonSetState doesn't continually bounce back and forth every 20ms
while(true){
Leftfront.spin(forward,Controller1.Axis3.position()+Controller1.Axis4.position()-Controller1.Axis1.position(), percent);
Rightfront.spin(forward,Controller1.Axis3.position()-Controller1.Axis4.position()+Controller1.Axis1.position(), percent);
Rightrear.spin(forward,Controller1.Axis3.position()+Controller1.Axis4.position()+Controller1.Axis1.position(), percent);
Leftrear.spin(forward,Controller1.Axis3.position()-Controller1.Axis4.position()-Controller1.Axis1.position(), percent);
if( Controller1.ButtonX.pressed() && (pistonSetState == false) && (waitingOnRelease == false) ) {
piston.set( true ); // Deploy the piston
pistonSetState = true; // Indicate it's set
waitingOnRelease = true; // Flag to wait for button release
}
else if( Controller1.ButtonX.pressed() && (pistonSetState == true) && (waitingOnRelease == false) ) {
piston.set( false ); // Retract the piston
pistonSetState = false; // Indicate it's not set
waitingOnRelease = true; // Flag to wait for button release
}
else if( Controller1.ButtonX.released() ) {
waitingOnRelease = false; // Flag that button has been released, so next press will toggle to the opposite state
}
wait(20,msec);
} // end while(true)
The code above adds in the ability to use a single button to toggle a state, rather than have two buttons, one to deploy, one to retract.
Disclaimer: I’m at the end of a long day, and no V5 material with which to test the above, so there may be (likely is) something that’s not perfect about the above, but it should be close. Also, probably a way to be somewhat more elegant, but this gets the general idea across.