|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Timer for solenoid?
We are using pneumatics with our robot this year and want to know how/if we can use a timer to tell the solenoid to stay open for a certain amount of time.
|
|
#2
|
|||
|
|||
|
Re: Timer for solenoid?
We have historically used timestamps:
Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
// Boolean used to determine whether or not the frisby indexer is on
boolean indexerActive = false;
/* Timestamp variables for identifying the robots current cycle time
* This is to be used most primarily for user intarction via button
* presses. Prevents the button from being repeatedly cycled.
*/
long CPUlastTime;
long CPUcurrentTime;
long CPUtimeDifference;
public void robotInit() {
}
public void operatorControl() {
if(xboxControl.getRawButton(1)){
CPUcurrentTime = System.currentTimeMillis();
CPUtimeDifference = CPUcurrentTime - CPUlastTime;
if(indexerActive == true) {
if(CPUtimeDifference > 500) {
indexerActive = false;
CPUlastTime = System.currentTimeMillis();
}
}
else {
if(CPUtimeDifference > 500) {
indexerActive = true;
CPUlastTime = System.currentTimeMillis();
}
}
System.out.println("HID: XBox|A pressed");
}
}
|
|
#3
|
|||
|
|||
|
Re: Timer for solenoid?
There are a few methods. You could used command based programming, and then use it as such (assuming you're using a spike relay, aka bridge driver to control the solenoid):
Code:
public ShootFrisbee() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(shooterSubsystem);
setTimeout(0.25);
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
shooterSubsystem.shootSolenoid(Relay.Value.kOn);
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return isTimedOut();
}
// Called once after isFinished returns true
protected void end() {
shooterSubsystem.shootSolenoid(Relay.Value.kOff);
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
Code:
solenoid.set(Relay.Value.kOn); wait(0.25); solenoid.set(Relay.Value.kOff); Last edited by arithehun : 11-02-2013 at 23:03. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|