View Single Post
  #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