Compressor Code not working

The title is a general overview, but to get more into detail, we are trying to get the compressor to start at 10 psi and keep going until 20 psi (in the event of a brown out.) everything we’ve tried fails and it keeps stopping at 10 psi or doesn’t get what we want. can anyone fix our code?

public void powerRation() {
if (batteryVoltage < 12.7) {
compPowerRation();
}
}
// 12.7 is to simulate a brownout without having to go wasting power
public void compPowerRation() {
if (currentPSI < 10) {
comp.start();
} else if (currentPSI > 20) {
comp.stop();
}

Quick question, why do you want to keep the psi at 10 - 20?

In the event of a brown out, we want to keep as little power going to the compressor as possible.

I think @Low3arth0rbit’s question was what would be the value of having between 10 and 20 psi? Most solenoid valves usable in FRC are piloted, which means that they usually need about 30psi to operate. Further, if you have your regulator set anywhere over 20, it won’t do you any good.

A really key question here - how are you assigning values for batteryVoltage and currentPSI? I’m presuming they’re global, or at least defined in a higher level context.

3 Likes

Per the docs, start() and stop() are the correct methods for allowing the compressor to run, and forcing it off.

Echoing all the previous questions on the thread though - without context to what batteryVoltage, currentPSI, orcomp are, it’s hard to say what the posted code will do.

Also how are you collecting psi data. May play a role as could be a wiring issue there.

Also make sure a solenoid is instantiated. Still required even if using manual compressor commands (I think).

1 Like

We are using an off-the-shelf pressure sensor from Amazon to collect the psi data. We get a voltage from that sensor and use a simple quadratic regression equation to scale it to psi based on experimental values. I will send a link to the source code after school today when I get the chance.
EDIT: I don’t believe that the PSI reading is faulty, as we’ve checked our regression equation pretty thoroughly. I believe it is more of a logic issue.

Thanks for the info. We weren’t sure what the minimum operating pressure was, so we were just planning to use trial and error. As for the values, see my post above replying to @risho900.

FWIW the basics of the code presented above seem reasonable - the hysteresis behavior you indicate (deactivate > 20, activate < 10) is the one I’d recommend.

One thing to consider is the sensor accuracy in that range - at best you’re working in the lower 10% of the sensor’s reading range, I’m wondering if nonlinearities and noise might be impacting behavior. Even if you have a super-accurate sensor, the single pulses from each stroke of the piston inside the compressor might be enough to push the sensor from 5 PSI to 20 PSI momentarily. An averaging or median filter on the measured pressure might be in order here.

If you can post the full code or link to a github repo, that would probably help.

You haven’t really given us much to goo off here, just some code snippets and “it doesn’t work.” We’re going to need some more details to really be able to help you.

What do you mean by “not working”? What’s your resting battery voltage? What’s the voltage when the compressor is running? What action are you using pneumatics for that you only need 10-20 psi? Can your solenoids actually switch at pressures that low? How many actuations of your cylinders does it take to go from above 20 psi to below 10 psi?

And as always, sharing your whole code is much more helpful than just a small piece of it.

Interesting. The sensor didn’t give you a scaling value to convert? I know REV sells an analog pressure sensor so keep that in mind if the sensor becomes the issue but otherwise I don’t see the issue in the code.

Actually first though, which compressor are you using too. If you’re using the AM 1.1 pump that one has issues and doesn’t turn off when it should (AM gave my team a refund for it and stop selling it on their website).
Also does it work normally like can it store up to 120 and auto shut off due to pressure switch?

Did the pump have an additional, internal shutoff switch?

From what I remember I heard there were case shorting issues or something but essentially, the pressure switch would only turn off the pump sometimes so it could not be used in comp

Gotcha. When I’d first read the post, it sounded like the pump itself had a stuck-on failure mode (which didn’t make much sense to me). However, the pressure switch failing makes more sense.

Every powered system on a robot causes an overall reduction in the system voltage when active. For example, turning the compressor on could cause a drop in system voltage. Are you able to measure what that is for your setup?

Does the robot start at 0 PSI, or something else?

Ideally you should post the entire class, or link to a github repo. This will help us eliminate logic-specific possibilities.

Well, it works now. Thanks to @GeeTwo for his advice on the required pressure for the solenoids. I just deleted everything unnecessary from the code and I think that the issue was setting the compressor at more than one place.

Here is a link to the pressure sensor. It is $20 cheaper than the REV one, and it works perfectly: https://www.amazon.com/dp/B01IR2MANC/ref=cm_sw_r_em_apa_i_81EJDbJJ0CMCZ

Here is a link to my source code. Let me know whether you think I should post it in a new thread as a pressure sensing solution (the quadratic equation is usually accurate to ~0.5 PSI): https://github.com/lowtorola/2586-BrownoutPrevention/blob/master/Pressure%20Sensor

image

Nice.

Thanks - good to know there’s a decent alternative out there, and glad it’s up and working!

FYI - if you are looking to just upload a single code file for temporary reference, Github has this “gist” thing which is similar to what pastebin has, but I guess better.