The simple answer is, it depends
But i’ll try to lay things out for you in a way that you can figure out from your situation.
First, a brief overview of the controller. If you’re using a 360 controller, then i assume you’re using the USB chicklet from IFI? if so, then this document will help:
The controller is plugged into one of your joystick ports (lets say 1, for the sake of argument). That port has a number of variables associated with it:
p1_x
p1_y
p1_aux
p1_wheel
p1_trig
p1_top
pt_aux1
p1_aux2
Now, if you look at the mappings on page 5 of the document above, you’ll see what actions map to which variables. for example, button 1 maps to p1_trig. So, if you press on button 1 (which ever button that’s assigned to), the value for p1_trig will change to 1. when you release, it’ll go back to 0. That gives you a very easy way to tell when a button is pressed and released. Note that if you have in your code something like:
if (p1_trig == 1)
{
//do something
}
then you’ll do that multiple times per button press, because each press is so long that the code loops through several times. This may or may not be a problem for your situation (but it’s easily solvable).
Now, the joysticks are similar. You read those in from their variables. They’ll have a value of 0-255, with 127 indicating the dead center, 255 the extreme positive end, and 0 the extreme negative end.
All of these variables are updated very often (as high as 40 times a second, i believe), so you don’t have to worry about that!
So, once you get your inputs, you need to be able to output them. This is also pretty easy. Your motors will be plugged into one of the PWM ports on the RC. For the sake of argument, we’ll assume they’re in port 01. Conveniently, that maps in the code to a variable called pwm_01. All you have to do is set that variable to whatever speed you want (or even to the joystick input!) It follows the same conventions as the joysticks, with 127 being stop, 0 being full speed reverse, and 255 being full speed forward.
If you’re using KoP materials for your pneumatics, then your piston should be connected through one of the relay ports. Again, i’ll assume it’s port 1. This port actually has two variables associated with it - relay1_fwd and relay1_rev. The tricky thing with working with pneumatics is knowing how the solenoids work. Basically, You can apply power to two sides of it. When you provide power to one side, it opens up the valve in that direction, letting the air flow through that port, and closing the other. provide power to the other side, and the same thing happens over there. provide power to both sides, and you can’t be sure what will happen - they’ll both try to open their side and close the other. Provide power to neither side, and you have the same situation where you don’t know what will happen.
For that reason, whenever you’re working with pneumatics in this fashion, you always want to set the variables together as a pair. To move the piston in one direction, you’ll set relay1_fwd = 1 and relay1_rev = 0. For the other direction, relay1_fwd = 0 and relay1_rev = 1.
As for the motor up and down, it depends on how it’s wired up - those can be wired to either victors or spikes. Luckily for you, those are both controlled the same way as I described above.
So, some very simple code to do what you described (but maybe not exactly what you want, your questions were a little generic) might be:
pwm_01 = p1_x;
pwm_02=p1_y;
//control the piston
if (p1_trig == 1)
{
relay1_fwd = 1;
relay1_rev = 0;
}
else
{
relay1_fwd = 0;
relay1_rev = 1;
}
//control the motor
//I'm leaving this portion up to you to figure out :)