This past week Team 291 was finishing up the off-season t-shirt cannon we had been working on. We quickly realized that we would need to add a second compressor to avoid overheating. We wanted to be able to alternate between the compressors in order to give each a break.
This is the code that I wrote to allow us to alternate between the 2 compressors. It's in C++ and being used with an old cRio. We thought this was a really neat idea so I figured I would share it here. As you might have guessed 'comp1' and 'comp2' are the compressors. 'di1' is the pressure switch. A button on the controller was added to allow for a manual override so we could run both at once if needed. We haven't had any issues yet but suggestions for improvements are always appreciated.
Code:
int toggle_comp=1;
bool comp_previous=0;
bool button1=0;
button1 = stick->GetRawButton(1);
if(di1->Get()==1 && comp_previous==0)
{
comp1->Set(comp1->kOff);
comp2->Set(comp2->kOff);
toggle_comp++;
comp_previous=1;
}
else if(di1->Get()==1 && comp_previous==1)
{
comp1->Set(comp1->kOff);
comp2->Set(comp2->kOff);
}
else if(di1->Get()==0 && comp_previous==1)
{
comp_previous=0;
}
if(di1->Get()==0 && toggle_comp%2==0 && button1==0)
{
comp1->Set(comp1->kOff);
comp2->Set(comp2->kOn);
}
else if (di1->Get()==0 && toggle_comp%2!=0 && button1==0)
{
comp1->Set(comp1->kOn);
comp2->Set(comp2->kOff);
}
else if (di1->Get()==0 && button1==1)
{
comp1->Set(comp1->kOn);
comp2->Set(comp2->kOn);
}
Note: This is just the code pertaining to the compressor in teleop and not the entire program