Hey, thanks to some great help from Jon236, Alan Anderson and Mark McLeod, I think I got some code that might work with the pneumatics system…
If someone could take a look over it and maybe give me some pointers, that’d be great! (School is closed until Tuesday…Furlough days.:mad: )
#include "WPILib.h"
#include "1771Constants.h"
#include <iostream>
using namespace std;
namespace Team1771
{
class Team1771Robot : public SimpleRobot
{
RobotDrive driveTrain;
Joystick leftStick;
Joystick rightStick;
Joystick manipulator;
Compressor compressorControl;
Solenoid turret;
public:
Team1771Robot(void):
driveTrain(LEFT_DRIVE_MOTOR_PORT,
RIGHT_DRIVE_MOTOR_PORT),
leftStick(LEFT_JOYSTICK_PORT),
rightStick(RIGHT_JOYSTICK_PORT),
manipulator(MANIPULATOR_JOYSTICK_PORT),
compressorControl(3,3,COMPRESSOR_PORT,7),
turret(5) //THIS *HAS* TO BE CHANGED
//I just made up random number
//TODO: Figure out how to hook it up!!!
{
compressorControl.Start();
};
void Autonomous(void)
{
GetWatchdog().SetEnabled(false);
while(IsAutonomous() && !IsDisabled())
{}
}
void OperatorControl(void)
{
GetWatchdog().SetEnabled(false);
while (IsOperatorControl() && !IsDisabled())
{
//FIRE AWAY CAP'N!
if(manipulator.GetRawButton(1))
{
//Seeing if I have enough. Just a rough estimate.
if(compressorControl.GetPressureSwitchValue() < 100)
{
cout << "Not enough power to fire. " << endl;
cout << compressorControl.GetPressureSwitchValue() << endl;
Wait(1);
}
else //Fire into the crowd! Rawr!
{
//Uncomment to see pressure values before firing
/*
cout << compressorControl.GetPressureSwitchValue() << endl;
*/
turret.Set(1); //I think this will tell the solenoid(I think its the solenoid?)
//to switch and let the air fire from the chamber.
turret.Set(0);//Then that should turn it off?
//TODO: Figure out if 1 is letting air in, or if 0 is.
//Uncomment this below for seeing how much pressure we lose from firing.
/*
cout << compressorControl.GetPressureSwitchValue() << endl;
*/
Wait(1);
}
}
}
}
};
START_ROBOT_CLASS(Team1771Robot);
}
One of my questions that I already have however, is with the Compressor.Start()
I noticed in the Compressor.h file, there is a function called void SetRelayValue(Relay::Value relayValue). Does the Compressor class automatically call this is needed?
From what I understand, calling compressorControl.Start() will turn on the compressor, and automatically keep the pressure to a certain level.
Hey. Admittedly I don’t have too much experience programming for the new control system (I was delegated to electronics this past year), but a couple things look kind of fishy. First of all, I don’t think you’re supposed to be disabling the Watchdog like that. From what I remember of the documentation and example code, you should be Feed()ing it. Also, I don’t think doing
turret.Set(1)
and then
turret.Set(0)
on the next line will make it fire. The way I see it, there are a couple ways to get this to do what you want. The first way would be to just do
turret.Set(manipulator.GetRawButton(1))
so that it fires the solenoid when you press the button. I’m assuming you’re using a Festo single-solenoid valve, of course. The other way would be to write it so that when you press the button, it sets the solenoid to 1 and then starts a counter. Then, when the counter reaches 0, it sets the solenoid to 0. It could probably look like this
int shootercounter
void Pneumatics()
{
if( shootercounter > 0 )
shootercounter-- //decrement the counter
else
turret.Set(0); //close the valve
if( manipulator.GetRawButton(1) )
{
//open the valve for 200 cycles
shootercounter = 200;
turret.Set(1);
}
}
Though there’s definitely a better way to do it with timers, I’m not sure how to use timers in the new system.
Another issue is the pressure switch doesn’t behave the way you want.
The pressure switch value will only be 1 or 0.
It will trip to 1 if the pressure is or falls below 95 psi.
Once tripped it will remain at 1 until pressure rises to 115 psi.
At 115 psi it resets to 0 and stays that way until pressure falls below 95 psi again.
So part of the automatic compressor operation is built in to the pressure switch they send us in the KOP.
You’d have to buy (fairly expensive) a pressure transducer to get a constant readout of current pressure the way you want.
As for the watchdog, it doesn’t matter for us now. We have been programming it that way, and whenever we did try feeding it, it would gives us Watchdog errors.
For the turret.Set(1) and turret.Set(0), I added a Wait in between them for 2 seconds. That should make the solenoid open up for 2 seconds, right?
For the pressure switch readings, I guess that means you can’t get it to be over 115 PSI? When we hooked it up manually (using 2 batteries and manually sparking them to fire) we fired it at 120 PSI, but we used a manual gauge thing.
If I use compressorControl.Start(), does that mean it will never put the pressure above 115?
(Note: this is for non-FRC competition use)
Start() will always cut off at 115psi using the current KOP pneumatic system and won’t run again until the pressure falls to 95psi.
There were some older KOP pressure switches that were set at 120psi and you might be able to buy a switch pre-set for 120psi.
If you can’t launch anywhere in the range of 95-115psi, then you probably want to use your own code rather than Start().
If your goal is to launch only at a particular pressure each time, then you’ll either have to watch the gauge and operate the compressor manually, or dump enough pressure each use to trip the pressure switch (by dropping to 95psi) and let it build up to 115psi, or buy a pressure transducer.
If it must be at 120psi every time, then you could force the compressor to run a minute more after the pressure switch cuts off to build up to 120psi.
The only reason I had it test the pressure in my code, was because I wouldn’t want it to fire if it only had like 60 PSI.
As far as my solenoid firing, would that work? My thought was that it would switch the valves on the FESTO Solenoid for a second, allowing air to shoot out.
With the Wait() added, as Jeremy suggested, the solenoid should operate the way you expect.
The solenoids we get in the Kit won’t supply the fast, sudden pressure you need to launch a t-shirt though. There are different solutions for how to do the valve that other teams have used.
T-shirt launchers have been talked about a lot on Chief Delphi, so check out some of those threads for how other teams have done it:
Er, I think that would depend on the type of double solenoid you used and how it was wired to the spike. For instance the ones Team 1546 used last year (the same ones supplied in the KoP previously) actually had two sets of solenoid power terminals. To use one spike for both solenoids, you’d need to rig up a couple diodes. I think there’s a diagram of what to do in regards to that somewhere around here. I don’t recall if a different type of double solenoid valve was included in the KoP last year, so my advice may be out of date.
Yea, there are different methods of wiring the solenoid to the spike.
We only see one solenoid type in FRC. They are all simple coils that get energized or not, essentially, two single solenoids in one package.
Typically, the major variations you’ll see in wiring a double solenoid on FRC robots are:
Use two outputs on the Pneumatic Bumper w/o a spike at all (diagram 3 below). This is the easiest choice.
Use diodes to direct the current flow from the spike to a either side of the solenoid (2nd diagram below). Jeremy’s favorite method.
*]Cross-wire the sides of the solenoid to a spike (first diagram below). This is the way I usually tell people to wire a double solenoid to a Spike.
All three methods work fine. It’s just a matter of choice and circumstances.
Since I can’t really know the pressure (without buying an expensive item…we are flat broke for this project. :P) I decided to make my own gauge…thing.
I made a new integer, called compressorValue, and I will use that to store the value of the pressure left. I can do some tests, and see how much pressure is used by firing one shot, and how much is added in X amount of seconds of the compressor running…
But, this is where my question is.
Will the times change based on the pressure? Eg: Will it increase quicker at first, then increase slower as the pressure builds? Or is the compressor (the ones that came in the KoP) powerful enough that this resistance is negligible?
You’ll lose the same amount of pressure each time, down to 60 psi, so that part’s consistent.
Restoring the pressure is a function of how much pressure is already in the system. The compressor takes longer the more it has to work against higher pressure. So, for example, pumping 5psi back into a system already at 110 psi will take longer than pumping 5 psi into a system at 60 psi.
What you’re suggesting will probably work for your purposes though. You don’t have to be too exact. You can probably go with the time you measure when the overall system is down to 90 psi and you’d be fine. Then you could still check the pressure sensor for “1” and keep the compressor running as long as it doesn’t turn back to “0”.