Pneumatics coding

I’m helping out a team with no programming experience and I have basic experience but none relating to FIRST.

They are trying to code their pneumatics but don’t know how to do so or even where to start.

The basic setup is as follows:

there are 3 pneumatic valves:
the first one is connected as follows: festo valve -> spike relay -> pwm8
the second is festo valve -> spike relay -> pwm12
the third is festo valve -> spike relay -> pwm16

the compressive is compressor-> spike-> relay8

the 3 valves would be independently controlled by 3 arbitrary joystick buttons

Would anyone be so kind as to point me in the right direction?

what program are you using?

sorry about that, mplab

ill have to let someone else help you then, i only no easyc…srry, i would try a help menu on mplab…they are surprisingly helpful, our programmer taught himself that way…only took 2.5 months

ok, so first of all spike relays cannot be plugged into pwm outputs. What they do need to be plugged into are the relay outputs.

ok now that you have all the pneumatics plugged into relays and not pwms, ill go over how they work. The relays are basically 2 digital outputs slapped into a single cable, so there are two bits that you can set. relay#_fwd and relay#_rev. What this gets translated into is either +12V, -12V, 0V to the festo Valves. So in order to set them to one direction you would use this line of code

relay#_fwd = 1;
relay#_rev = 0;

this will set your festo valve to actuate your pneumatic one way and if you switch which bit is set to 1 then you actuate the pneumatic the other way. Now is for some reason you dont want any pressure in the cylinders then you set each bit to 0.

Now if you want to change these based on a button on a joystick then you can change the relay#_fwd and relay#_rev bits inside an if statment such as

if(p1_sw_top ==1)
{
relay#_fwd = 1;
relay#_rev = 0;
}

If you need any help any further feel free to pm me and I’ll try to help you.

You’re close, but you’re not quite right.

First off, you’re right about the connections to RC. Spikes MUST be plugged into the RELAY outputs on the RC. I don’t know that there is a rule saying this, but its implied by the fact that they won’t work if you don’t.

The FESTO valves are single solenoid. I don’t know what these will do with reverse polarity, but I imagine its along the lines of either a) just not do anything, or b) cease to function ever again.

Thusly, I wouldn’t touch relay#_rev on those units, except to ensure its set to 0.

The FESTO valves can be simply switched using relay#_fwd = 1;, and relay#_fwd = 0;

The SMC single solenoid is the same.

The SMC Double solenoid is used in the way you describe, using relay#_fwd for one direction, and relay#_rev for the other direction, assuming you’ve wired the two positives to M+ and M- on your spike, and the grounds to ground.

Setting _fwd and _rev to zero on a SMC double will leave the gate in whichever direction it was last set to. We are not given “center-off” valves that would give the behavior you describe.

First off thanks so much to everyone that replied and helped and also thanks so much Squishy for helping me at all, I really appreciate it. <3

basically I used this line of code so far

relay2_fwd = 0;
relay2_rev = 0;

if(p4_sw_trig == 1)
{
relay2_fwd=1;
relay2_rev=0;
}
else if (p4_sw_trig == 0)
{
relay2_fwd=0;
relay2_rev=0;
}

like would that work… or is that completely wrong?

sorry, I really don’t have any experience in programming so my questions might seem pointless. So like I said, sorry ahead of time :smiley:

That will work famously.

Pulling the trigger on port 4’s joystick will result in the spike at relay2, and presumably, the solenoid valve attached to it, to actuate, and releasing the trigger will de-actuate the cylinder, assuming you’re using the FESTO single solenoid valves (the roundish white ones with a blue lever and 4 grey ports.)

okay, I understand how it all works now however I’m not sure how I could write a block of coding that would allow me to toggle the buttons… if that is possible.

Is there a code that would allow me to just press button = active;
press again = inactive?

Well, you need to know some characteristics about these switches.

First off, you will need to probably de-bounce the switches. The chances that you get something like “000000100010101110111111” when the button is pressed are likely. I don’t use toggles, so I don’t know about code for this. While I could script it up, it would likely be horribly inefficient…

Second, you will need to have a static variable that you set to 1 when the switch is triggered; set it to 0 when the switch goes to 0. Before you set this variable, check if the switch is 1 and the variable is 0; if this condition is true, change the pneumatic, then set the variable to 1.

Let me know if you would like pseudo code, but I’d prefer not to write specific code. That should be left up to you. :smiley:

JBot

We’re having issues programming the compressor and pressure switch, which I thought was part of the original question, but never got answered.

Our team is using Easy C, which we’re really efficient with. I believe that we lack the sufficient knowledge of the pneumatics system, due to years of the coach saying that it was a waste of time.

Well, the future is NOW! people. Team 1688 has ventured into the land of safety orange tubing, and pressure gauge happiness!

I thought that I read somewhere that input 16 was used for the pressure switch and one of the spike relays was used for the compressor? Can someone help? Or at least direct me to a thread that can?

THANKS!

~Tom

Put InitPressureSwitch() into the Initialize block and just specify the digital input that the pressure sensor is plugged into and the Relay the compressor’s Spike is connected to.

We had something similar. Perhaps we just had it backwards. I’ll check it when I get to the lab.

THANKS!

We are having a similar problem. We have this basic layout for our shifters and another cylinder:

relay2_fwd = 0;
relay2_rev = 0;

if(p4_sw_trig == 1)
{
relay2_fwd=1;
relay2_rev=0;
}
else if (p4_sw_trig == 0)
{
relay2_fwd=0;
relay2_rev=0;
}

We are using a button on the control panel to activate it. The problem is that the we have to hold the button to say in high or low gear. I tried to set it so that one press of the button would activate the cylinder and a second would deactivate the cylinder. I have tried doing this a couple different ways, but as the code cycles every 20 something milliseconds, the shift state changes with it. So as I press the button quickly, it will activate and deactivate a couple dozen times. How do I stop this? (using MBLAB)

Something such as:


  static char toggle=1;

  if(p4_sw_trig && toggle)
  {
	toggle = 0;
  	relay2_fwd = !relay2_fwd; 
  	relay2_rev = 0;
  }
  if(!p4_sw_trig)
  {
	toggle = 1;
  }

prevents further toggling until the button has been released again.

Thank you!!!:yikes:

Well, I downloaded my file to the rc and tried testing the triggers and the pneumatics did not even budge one bit. I have this block of code for each of the valves to be activated/deactivated

relay#_fwd = 0;
relay#_rev = 0;

if(p#_sw_x == 1)
{
relay#_fwd=1;
}
else if (p#_sw_x == 0)
{
relay#_fwd=0;
}

I did not keep in mind my compressor however, and am not sure on how to go about coding the compressor to make it turn off automatically when the pressure switch reaches a certain value.

As for the pneumatics could I have named the trigger buttons incorrectly?
I used p#_sw_x == 1 such that # = 2 or 4 and x = either trig, aux1, or aux2 in the if and else if’s for the joystick inputs.

I also read somewhere that you have to

use the OI Digital input block to get the reading off the joystick. Then you can assign the button to an unsigned char variable

How exactly do I go about doing that?

:confused: HELP!!!

What are you using to program your robot?

  1. MPLAB IFI default code
  2. MPLAB Kevin Watson default code
  3. EasyC Pro / WPILIB
  4. RobotC

The answer differs

oh I’m sorry, MPLAB IFI Default Code

with severe troubleshooting and an all nighter, I got it to work! :D!! I am sooooo happy :slight_smile: I squealed like girls usually do when the arm moved aha :stuck_out_tongue: Thanks so much for all the help, and good luck to everyone else who has had problems with their programming <3!