I have a problem trying to cause the piston going forwards and backwards.
What Ive tried to do is to move the piston backwards when the user clicks on the joysticks trig and to move the piston forwards when the user get rid of the joystick`s trig.
I had a problem which seemed ambiguous for me and I couldn`t find the error, it compiled successfully.
I made sure the spike is plugged in the proper relay, and the joystick is plugged in the proper port.
Your software is entirely correct. Unfortunately the connectors on the Spikes are very finicky, so you might try plugging them in a few times. But, before you do that, I suggest taking a volt meter or an led and seeing if the fwd and rev pins are being set/unset. If they aren’t, you can test it at the pin too. If it isn’t working there, check with dashboard to see if your button is working and is showing up where your software thinks it should be.
In addition to what Qbranch said about verifying the connections, you may need to verify you are connecting the solenoids correctly to the Spike.
For this code to work, you need to have the positive (red) lead from each solenoid connected to either the M+ or M- on the Spike (one lead per side). You also need to have both negative (black) wires connected to ground, preferably at the distribution block.
If the piston functions backward from your intent, swap the two red leads on the Spike, or, swap the two pneumatic lines on the valve assembly.
Where did you put your code? The default code also messes with the relays, so if you put your code before the default code, the default code would overwrite your settings.
Have you checked the pwm cable connection? One problem we kept getting was that the Spikes’ long port between the controller had a tendency of bending the pins and sometimes slipping out quite easily. We had to resort to taping them down with electrical tape.
Actually, when i said FWD and REV pins I was specifically referring to the logic level (5VDC) outputs from the controller to eliminate the spike from the system at first. If you’re getting the 5V signals, then you can work down the chain of command from there (5V signal -> spike -> solenoid -> piston -> mechanical action).
Not to be contradictory – but I guess I may be. I had to dig out our last year’s pneumatic code to check how we did it. In autonomous, the routine was called with variable Position either 1 or 0:
if (Position==1) //Open pinchers/release tube?
{
relay1_fwd= 1; //Pressurize to open
relay1_rev= 0; //This always zero
}
else if (Position==0) //Close pinchers/pinch tube?
{
relay1_fwd= 0; //Depressurize to open (release tube)
relay1_rev= 0; //This always zero
}
The relay1_rev was always zero, and only relay1_fwd switched between one and zero. I always thought it was odd, but hey, it did work.
But another place was in user_routines.c/User_Initialization routine – make sure your digital_io was set to INPUT:
digital_io_18 = INPUT; /* Used for pneumatic pressure switch. */
We also had a slightly different way with the joystick trigger, to click it each time to reverse state:
if (p2_sw_trig != SqueezeTrigLast) //Trigger changed state? (squeeze/no squeeze)
{ //Yes:
if (p2_sw_trig == 1) //...Trigger pressed
{
SqueezeState= 1 - SqueezeState; //Toggle state 0 to 1 to 0
}
//printf("SS=%d fwd=%d rev=%d",SqueezeState, relay1_fwd, relay1_rev);
// Part 2 Open... or... shut???
if (SqueezeState==0) //Is state to be OPEN?
{ //Yes:
relay1_fwd= 1; //Pressurize
relay1_rev= 0; //This stays zero
//printf ("OPEN
");
}
else //State is NOT OPEN
{
relay1_fwd= 0; //Depressurize
relay1_rev= 0; //This stays zero
//printf ("SHUT
");
}
SqueezeTrigLast= p2_sw_trig; //Save trigger state for next time check
}
This way you don’t have to hold the trig button.
And yes, because programmers are always perfect, have the hardware guys make sure they did everything right.
Every revolutionary idea seems to evoke three stages of reaction. They may be summed up by the phrases: (1) It’s completely impossible. (2) It’s possible, but it’s not worth doing. (3) I said it was a good idea all along. RIP Arthur C. Clarke
The code necessary depends on the type of solenoid used and the method of wiring.
The code you posted is correct for a double solenoid (two red and two black wires) if the two red wires are wired to the spike and the grounds connect to ground elsewhere.
A single solenoid has one red and one black wire going to the spike and is controlled by (as in Roger’s example):
So I have to call out the “it all depends” escape clause? I’m glad I wasn’t wrong – it did work – but I’m also glad I wasn’t saying Qbranch and billbo911 were wrong, either. Now I know why relay1_rev never gets set to one. I guess this is what happens when I don’t pay attention to the hardware end of the robot…
chuckle Ok, I guess we all jumped the gun and assumed you had a double acting/double pull solenoid. Glad you got it working… now I have a question for you:
Sorry, I meant our last year’s code did work on our (Team 1153) robot. I don’t know if beefy23 got his/hers to work, or what solenoid type it was. It was a loooooong weekend…