Programming of Pneumatics

I searched and found a couple threads related to this, but no one gave any solid answers. Therefore…

We are trying to use a momentary switch on our control board, to control a pneumatic cylinder. We have tried both single and double solenoids, so far with no luck. What we are attempting to do is this.

The cylinder is in one position (extended or compressed.) The driver hits the momentary switch once, and the cylinder changes position to the opposite extreme and holds. To bring the cylinder back, the driver hits the momentary switch once again, and the cylinder returns and holds.

Pretty simple, but we have run into several issues including hysteresis, the cylinder not returning on the 2nd press of the button, etc… Unfortunately, I’m not the programmer, so I don’t have the actual code we’ve been working with. Does someone out there have a simple way to execute this command?

Thanks,

Bengineer
GUS, Team 228

What you have to do in the code is put in an if statement that will switch between the 2 positions on the pneumatics, but since the loop executes every 26ms(approx.) you’ll also need to include a latch to prevent this.

The following code is similar to what my team did for this:


  if(p1_sw_top == 1 && button_latch==0) //button_latch is a variable to
// prevent the code from rapidly cycling through piston positions
  {
	if(relay1_rev==1)//if the relay is reversed it will switch to forward
	{
	  relay1_fwd=1;
	  relay1_rev=0;
	  button_latch=1;
	}
	else          //and vice versa
	{
	  relay1_fwd=0;
	  relay1_rev=1;
	  button_latch=1;//latches to prevent cycling
	}
  }
  else if(p1_sw_top == 0 && button_latch==1)
  {
	button_latch=0;//resets latch when you let go of the button
  }

Ah, the latch part is what we’re missing. I couldn’t figure out a way to implement something like that. However, your code is exactly what we’re looking for. I’ll try to 1st thing Friday afternoon, thanks!

Bengineer
GUS, Team 228

You will need to make ‘latch’ a static variable if you are defining it inside a function so that it will retain its value between calls to the function. If you declare it outside a function (global to the file), it is by default static. I would assume you would declare ‘latch’ inside the function, though.