Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   solenoid problems (http://www.chiefdelphi.com/forums/showthread.php?t=83192)

Twisted eric 20-02-2010 16:36

solenoid problems
 
I need help with Programming the solenoid to a the trigger button on our controller it will be on the kicker joystick.

Code:

package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Watchdog;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Jaguar;


public class Demonized extends SimpleRobot {

    private static final long TIME_DELAY = 1000; // in milliseconds
    RobotDrive drive = new RobotDrive(1, 2);
    Joystick leftStick = new Joystick(1);
    Joystick rightStick = new Joystick(2);
    Joystick kicker = new Joystick(3);
    Watchdog fenrir = Watchdog.getInstance();
    Compressor fluffy = new Compressor(1, 1);
    Joystick leftstick = new Joystick(1);
    Joystick rightstick = new Joystick(2);
    Jaguar spot = new Jaguar(4);
    Joystick pup = new Joystick(4);
 
    void setUpRobot() {
        fluffy.start();
        fenrir.feed();
    }



    public void autonomous() {
        setUpRobot();
            while (true && isAutonomous() && isEnabled()) {
                for (int i = 0; i < 4; i++) {
                    fenrir.feed();
                    drive.drive(0.5, 0.0);  // drive 50% fwd 0% turn
                    fenrir.feed();
                    drive.drive(0.0, 0.5);  // drive 0% fwd 50% turn
                    fenrir.feed();
                    drive.drive(0.0, -0.5); // drive 0% fwd -50% turn
                }
            }
            drive.drive(0.0, 0.0); // drive 0% fwd, 0% turn 
    }
    public void operatorControl() {
        setUpRobot();
        while (true && isOperatorControl() && isEnabled()) // loop until change
        {
            drive.tankDrive(leftStick, rightStick);
            Timer.delay(0.005);
            fenrir.feed();
           
          // New compressor code...
if (fluffy.getPressureSwitchValue()) {
fluffy.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
} else {
fluffy.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOn);
}


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

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


help will be much appreciated.

ygd 20-02-2010 17:15

Re: solenoid problems
 
What's the point of this:

Code:

if (fluffy.getPressureSwitchValue()) {
fluffy.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
} else {
fluffy.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOn);
}

Also, this was our code when we were using pneumatics for our kicker:

Code:

if (System.currentTimeMillis() - lastFired >= 2000) {
                if (j.getTrigger() && !fired) {
                    fire();
                    fired = true;
                    lastFired = System.currentTimeMillis();
                } else if (!j.getTrigger() && fired) {
                    fired = false;
                }
            }
            try {
                Thread.sleep(50);
            } catch (Exception e) {
                System.out.print(e.getMessage());
                e.printStackTrace();
            }

Where fire() launches the solenoids and fired is a boolean set to false and lastFired is a long set to 0. This code also makes sure you can only fire once every two seconds.

Twisted eric 20-02-2010 17:18

Re: solenoid problems
 
if (fluffy.getPressureSwitchValue()) {
fluffy.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
} else {
fluffy.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOn);
}


this will i believe to turn off the compressor
(have not yet tried it yet)

also is the only import we need is

import edu.wpi.first.wpilibj.solenoid;

right


thanks.

Twisted eric 20-02-2010 17:25

Re: solenoid problems
 
How can I implement that into my code.

nikRbokRz 20-02-2010 17:58

Re: solenoid problems
 
Quote:

Originally Posted by Twisted eric (Post 924716)
if (fluffy.getPressureSwitchValue()) {
fluffy.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOff);
} else {
fluffy.setRelayValue(edu.wpi.first.wpilibj. Relay.Value.kOn);
}


this will i believe to turn off the compressor
(have not yet tried it yet)

also is the only import we need is

import edu.wpi.first.wpilibj.solenoid;

right


thanks.

First of all, instead of doing "edu.wpi.first.wpilibj.Relay.value.kOn", isn't it much easier to just to "Relay.value.kOn"?

From what my team assumed, the compressor automatically turns on/off, depending on the pressure switch. We initially couldn't get it to work, but it turned out to just be a bad spike. So I'm not really sure if you need to be turning it on/off.

As for the solenoid, yes all you need to import is
Code:

import edu.wpi.first.spilibj.Solenoid;
Depending on how you've connected your solenoid(s), you will have to set them true or false to get it to work as you wish.

Hope that helped.

KayyPii 20-02-2010 22:34

Re: solenoid problems
 
After you import the solenoid class, you will have to create your solenoid objects in Java. You can do this using :

Solenoid kicker = new Solenoid ( slot, channel );

then in your program, you can check the status of the trigger using an "if" selection and use the set( boolean on ); method to turn the solenoid on.

Twisted eric 21-02-2010 14:14

Re: solenoid problems
 
Quote:

Originally Posted by KayyPii (Post 924975)
After you import the solenoid class, you will have to create your solenoid objects in Java. You can do this using :

Solenoid kicker = new Solenoid ( slot, channel );

then in your program, you can check the status of the trigger using an "if" selection and use the set( boolean on ); method to turn the solenoid on.

Can you please show me an example this is my first year programming in Java and I have no mentor to help.

KayyPii 21-02-2010 22:08

Re: solenoid problems
 
Code:

Solenoid kicker = new Solenoid ( 7, 1 ); //locate a solenoid on slot 7 of cRio and channel 1 on the solenoid breakout.
if ( pup.getButton( Joystick.ButtonType.kTrigger ) == true ) //if the switch is pressed
        kicker.set(true); //turn on the solenoid
else
        kicker.set(false); //turn off the solenoid

That is pretty much our code for our kicker with the few changes to the variable names. Also, I believe that when you initialize the solenoid to channel 1, it is the first channel on the breakout board. I think its labelled as 0. Hope this helps :D


All times are GMT -5. The time now is 09:26.

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