3 Position Solenoid Help

Hello, my team has just got this new solenoid that take up two ports on the cRio. This solenoid allows us to put as much or little air in a cylinder as we want or it can handle. What we are trying to do is make it so when you press button 8 and hold it, it will go up until you let go then it will stop right where it is. If you hold button 9 down it will go down and stop where it is when you let go. I can make it go the whole way up or down for a regular solenoid, but I don’t know how to make it go and stop when you want it to. Can anyone help me out? Thanks!

A schematic or link to the part might help, but I think what you want to do is set your solenoid #1 output on if button 8 is pressed, #2 output on if 9 is pressed, and set both to off when neither is pressed. What is probably happening now, is you’re not clearing the output in the neither pressed case, so it just remembers the last setting it had (and keeps extending or retracting)

So something like this?

if(joystick1.getRawButton(8)) {
solenoid7.set(true);
}else{
solenoid7.set(false);
}

if(joystick1.getRawButton(9)) {
solenoid8.set(true);
}else{
solenoid8.set(false);
}

OK so this did work but i also need an alternative button that will make it go up the whole way with out holding it… Do i just put a timer in it to make it go up for a certain time till it is up or is there a simpler way.

You could set two buttons up to to change the state of the solenoid when they transition from not being pressed – to being pressed.

The only problem I foresee with this is if you ever wanted to stop the thing from moving, you would need to set up a new command on another button which set both solenoid channels to their false state. (Added to the code example)

This can be thought of as a rising edge trigger. Something (whatever is in the if statement) will happen once when the button is pressed, and never again until the button is released and pressed again.


//These should be declared outside of the method which code
// is executing in.
Boolean currentButton1Value = false,
        prevButton1Value    = false,
        currentButton2Value = false,
        prevButton2Value    = false;




//The below code should be placed in whatever method is continually
//  executing code (e.g. teleop periodic)


//Check the current button values
currentButton1Value = joystick1.getRawButton(1);
currentButton2Value = joystick1.getRawButton(2);

//If the button was just transitioned from not pressed to pressed,
//  extend? completely.
if((currenButton1Value == true) && (prevButton1Value == false)) {
  //The only way to get in here is if button 1 is currently true,
  //  and used to be false.
  solenoid7.set(true);
  solenoid8.set(false);
}

//If the button was just transitioned from not pressed to pressed,
//  retract? completely.
//Using a simplified form for the boolean logic (does the same thing as above)
if(currenButton2Value && !prevButton2Value) {
  solenoid7.set(false);
  solenoid8.set(true);
}

//Keep a history of the button presses
prevButton1Value = currentButton1Value;
prevButton2Value = currentButton2Value;

if(joystick1.getRawButton(3)){
  solenoid7.set(false);
  solenoid8.set(false);
}

Note this code isn’t tested, and I don’t know what your application is, so I’m not sure if it fits the need well. Hope it helps.