Go to Post Or use an IFI control system and you won't have to wait 2 minutes to use your bathroom :P - Chris is me [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2013, 16:28
Mr.Roboto3335's Avatar
Mr.Roboto3335 Mr.Roboto3335 is offline
Wait, What?
AKA: Jimmy
FRC #3335 (Cy-Borgs)
Team Role: Programmer
 
Join Date: Nov 2011
Rookie Year: 2011
Location: Texas
Posts: 47
Mr.Roboto3335 is an unknown quantity at this point
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.
__________________
Wait, what?
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2013, 16:38
y-aji y-aji is offline
Registered User
FRC #3734
 
Join Date: Dec 2011
Location: Lake Forest
Posts: 38
y-aji is an unknown quantity at this point
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");
            }
}
Pardon the mess. Let me know how that works for you. Alternatively, you can start learning about the iterativeRobot structure to do it, which shoots it off into separate threads in separate files. Someone correct me on any of this if it sounds off..
Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2013, 22:56
arithehun arithehun is offline
Registered User
AKA: Ari Falkner
FRC #3024
Team Role: Programmer
 
Join Date: Feb 2011
Rookie Year: 2011
Location: Ashland, Oregon
Posts: 27
arithehun is an unknown quantity at this point
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() {
    }
If you want to just use the SimpleRobot, then using java's built in delay command should work (solenoid is the relay object in this block)

Code:
solenoid.set(Relay.Value.kOn);
wait(0.25);
solenoid.set(Relay.Value.kOff);
Of course, the second example's block of code should be run in a separate thread so the wait(0.25) function does not clog up your robot's "docket".

Last edited by arithehun : 11-02-2013 at 23:03.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:47.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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