Pnuematic trouble

for what ever reason when i turn on my robot and try to connect my pnuematic spazes out continously switches using up most of there air. can anyone tellme why its doing that. its a dual-acting piston. heres the code i have
if(vexRT[Btn8D] == 1)
{
SensorValue[solenoid] = 1;
}
else
if(vexRT[Btn8R] == 1)
{
SensorValue[solenoid] = 0;
}

Nothing looks wrong from here, can you post more of the code it’s a part of so I can get a better view of it in context/

I’m not sure what causes it, but it’s a known problem. Look through these threads for some more information and to hopefully find a fix that works for you:

https://vexforum.com/t/start-up-pneumatic-firing-problem/25403/1
https://vexforum.com/t/pneumatics-programming-problem/23226/1

There really is no easy solution except to leave the air turned off until the cortex connects. Sometimes you can find a combination of solenoid driver and cortex digital port that does not cause the pneumatics to fire, but it’s not predictable. The problem is that the cpu initializes all digital IO as inputs followed by ROBOTC enabling the pullup resistor on them, when your code executes the port will be reconfigured as an output which by default is usually pulled low. There are some tricks that allow the pneumatics to fire a maximum of one time on power up but it’s a bit advanced for most users.

I dont know why but this is never a problem when using easyc

EasyC defines a few of the ports as outputs on initialization.

RobotC defines them all as inputs. Not until it is connected and runs the pragmas does it know it is not an input.

My understanding at least and Jpearman can correct me if I am wrong.

I actually don’t know if EasyC has the same problem or not, when I see pneumatics fire several times it’s when the cortex is still trying to make a VEXnet connectiion and user code is not always running at that point.

When EasyC compiles a program it creates several hidden files that are linked with the user code. One of them is called MainIO.c, it looks like this and is called early in the cpu startup process.

#include "Main.h"

void IO_Initialization(void)
{
	SetCompetitionMode ( -1, -1 ) ;
	SetAutonomousMode ( 0 ) ;
	SetTeamInfo ( "000easyC" ) ;
	DefineControllerIO ( 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 ) ;
	DefineImeTable ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ) ;
	DefineMotorTypes ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ) ;
}

The function that does digital port setup is DefineControllerIO, you can see the default input and outputs set in the code above.

This will happen sooner than ROBOTC which uses a two stage startup process, first run the virtual machine and set all ports as inputs, then run the user code and change configuration to whatever the user code wants.

So I will have to test this I guess and get back to you all.

Ok, so EasyC does not have this problem. I will post a full explanation as to why in another thread later.