Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   How to program solenoid and compressor? (http://www.chiefdelphi.com/forums/showthread.php?t=80790)

Jason F 01-21-2010 04:46 PM

How to program solenoid and compressor?
 
Hi, this is team 2198 and we are having trouble programming for the solenoids and compressors for java. We would appreciate any help we can receive whether it is a program or a simple guide. :p

Thanks for reading :o

derekwhite 01-21-2010 09:56 PM

Re: How to program solenoid and compressor?
 
If someone has real sample code, jump in. In the mean time, there is some test code in edu.wpi.first.wpilibj.CompressorTest which is used to test WPILibJ on a special test rig.

Also, if you could give some details about the problems your seeing?
- not sure how to get started?
- code doesn't compile?
- code runs with exceptions?
- code runs, but doesn't do what you want?

Jason F 01-22-2010 09:51 AM

Re: How to program solenoid and compressor?
 
I am not sure howto get started :ahh:

derekwhite 01-22-2010 11:40 AM

Re: How to program solenoid and compressor?
 
OK, there's some solenoid example code in the DefaultCodeProject.

From NetBeans, select "File/New Project...". In the window, open the "Samples" folder, select "FRC Java", then "DefaultCodeProject.zip" and continue making the project from there.

Also, as I mentioned before there is some test code in WPILibJ. To see that code, select "File/Open Project...". Navigate to your "sunspotfrcsdk" directory, then the "lib" directory under that. From there select WPILibJ.

Derschatten 01-30-2010 12:51 AM

Re: How to program solenoid and compressor?
 
This should give you a good idea.

Code:

package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Solenoid;

public class Airsystem extends SimpleRobot {
    private Joystick DriverStick;
    private AxisCamera camera;                      //defines Axis Camera
    private Solenoid s1,s2;                            //defines solenoids

    public Airsystem() {
          DriverStick = new Joystick(1);            // USB port
          airCompressor = new Compressor(1,1);  //Digtial I/O,Relay
          airCompressor.start();                        // Start the air compressor

          s1 = new Solenoid(1);                        // Solenoid port
          s2 = new Solenoid(2);
    public void autonomous() {
    }
    public void operatorControl() {
          if(DriverStick.getRawButton(1) == true)
          {
                s1.set(true);
                s2.set(false);
          }
          if(DriverStick.getRawButton(2) == true)
          {
                s1.set(false);
                s2.set(true);
            }
    }
    }


bamse 01-30-2010 04:37 PM

Re: How to program solenoid and compressor?
 
Howdy...

We had to insert this piece of code in the operatorControl() as well,

// New compressor code...
if (airCompressor.getPressureSwitchValue()) {
airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
} else {
airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOn);
}

And don't forget to turn the compressor off when exiting your operatorControl loop...

airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);

Kingofl337 02-07-2010 01:00 AM

Re: How to program solenoid and compressor?
 
Quote:

Originally Posted by bamse (Post 910036)
Howdy...

We had to insert this piece of code in the operatorControl() as well,

// New compressor code...
if (airCompressor.getPressureSwitchValue()) {
airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
} else {
airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOn);
}

And don't forget to turn the compressor off when exiting your operatorControl loop...

airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);

This is not correct, call the Compressor class tell it the digital input and the spike port and it will take care for you.

ex: Compressor myComp = new Compressor(1,1); //That's all you need

MattD 02-07-2010 01:22 AM

Re: How to program solenoid and compressor?
 
Quote:

Originally Posted by Kingofl337 (Post 914947)
This is not correct, call the Compressor class tell it the digital input and the spike port and it will take care for you.

ex: Compressor myComp = new Compressor(1,1); //That's all you need

By default, the compressor is not enabled until you call the start() method on it. This is needed in addition to the creation of a Compressor object.

Quote:

Originally Posted by bamse (Post 910036)
Howdy...

We had to insert this piece of code in the operatorControl() as well,

// New compressor code...
if (airCompressor.getPressureSwitchValue()) {
airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
} else {
airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOn);
}

And don't forget to turn the compressor off when exiting your operatorControl loop...

airCompressor.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);

Make sure to call start() on the compressor object, and also make sure that it is a class member so it does not go out of scope. Since the example code in post #5 shows no declaration for airCompressor, my best guess is that you're creating a new one each loop.

The example should look more like this:
Code:

....
public class Airsystem extends SimpleRobot {
    private Joystick DriverStick;
    private AxisCamera camera;                      //defines Axis Camera
    private Solenoid s1,s2;                            //defines solenoids
    private Compressor airCompressor;

    public Airsystem() {
          DriverStick = new Joystick(1);            // USB port
          airCompressor = new Compressor(1,1);  //Digtial I/O,Relay
          airCompressor.start();                        // Start the air compressor

          s1 = new Solenoid(1);                        // Solenoid port
          s2 = new Solenoid(2);
    }
    ...


synth3tk 02-08-2010 03:15 PM

Re: How to program solenoid and compressor?
 
Instead of deleting your post with "Problem is now solved", can you please tell us in case we have the same issue? We also don't know how to program the compressor using Java.


All times are GMT -5. The time now is 08:12 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi