|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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. |
|
#2
|
|||
|
|||
|
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);
}
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();
}
|
|
#3
|
||||
|
||||
|
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. Last edited by Twisted eric : 02-20-2010 at 05:20 PM. Reason: revision |
|
#4
|
||||
|
||||
|
Re: solenoid problems
How can I implement that into my code.
|
|
#5
|
|||
|
|||
|
Re: solenoid problems
Quote:
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; Hope that helped. |
|
#6
|
||||
|
||||
|
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. |
|
#7
|
||||
|
||||
|
Re: solenoid problems
Quote:
|
|
#8
|
||||
|
||||
|
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
![]() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Solenoid actuation problems | Alexandstein | Pneumatics | 4 | 02-17-2010 09:39 PM |
| Solenoid not firing off Solenoid Breakout | spooncwru | Pneumatics | 2 | 01-30-2010 05:46 PM |
| single solenoid | seanl | Pneumatics | 4 | 02-18-2007 02:32 AM |
| Programming a Solenoid | Brigander | Pneumatics | 4 | 02-17-2007 02:06 PM |
| Labview problems and code problems | ajsetter | Programming | 25 | 01-18-2006 05:07 PM |