Java 类edu.wpi.first.wpilibj.Notifier 实例源码

项目:449-central-repo    文件:ShiftWithSensorComponent.java   
/**
 * Default constructor.
 *
 * @param otherShiftables         All objects that should be shifted when this component's piston is.
 * @param piston                  The piston that shifts.
 * @param startingGear            The gear to start in. Can be null, and if it is, the starting gear is gotten from
 *                                the piston's position.
 * @param highGearSensors         The reed switches that detect if the shifter pistons are in high gear.
 * @param lowGearSensors          The reed switches that detect if the shifter pistons are in low gear.
 * @param motorsToDisable         The motors that should be disabled while the piston is shifting.
 * @param motorDisableTimer       The timer for how long the piston can be considered shifting before we ignore the
 *                                sensors and re-enable the motors.
 * @param sensorCheckerPeriodSecs The period for the loop that checks the sensors and enables/disables the motors,
 *                                in seconds.
 */
@JsonCreator
public ShiftWithSensorComponent(@NotNull @JsonProperty(required = true) List<Shiftable> otherShiftables,
                                @NotNull @JsonProperty(required = true) MappedDoubleSolenoid piston,
                                @Nullable Shiftable.gear startingGear,
                                @NotNull @JsonProperty(required = true) List<MappedDigitalInput> highGearSensors,
                                @NotNull @JsonProperty(required = true) List<MappedDigitalInput> lowGearSensors,
                                @NotNull @JsonProperty(required = true) List<SimpleMotor> motorsToDisable,
                                @NotNull @JsonProperty(required = true) BufferTimer motorDisableTimer,
                                @JsonProperty(required = true) double sensorCheckerPeriodSecs) {
    super(otherShiftables, piston, startingGear);
    this.highGearSensors = highGearSensors;
    this.lowGearSensors = lowGearSensors;
    this.motorsToDisable = motorsToDisable;
    this.motorDisableTimer = motorDisableTimer;
    this.sensorChecker = new Notifier(this::checkToReenable);
    this.sensorChecker.startPeriodic(sensorCheckerPeriodSecs);
    this.sensorCheckerPeriodSecs = sensorCheckerPeriodSecs;
}
项目:Ballbasaur-Code-Rewrite    文件:Robot.java   
/**
 * The method that runs when the robot is turned on. Initializes all subsystems from the map.
 */
public void robotInit() {
    //Set up start time
    Clock.setStartTime();
    Clock.updateTime();

    enabled = false;

    //Yes this should be a print statement, it's useful to know that robotInit started.
    System.out.println("Started robotInit.");
    Yaml yaml = new Yaml();
    try {
        Map<?, ?> normalized = (Map<?, ?>) yaml.load(new FileReader(RESOURCES_PATH+"ballbasaur_map.yml"));
        YAMLMapper mapper = new YAMLMapper();
        String fixed = mapper.writeValueAsString(normalized);
        mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
        robotMap = mapper.readValue(fixed, RobotMap.class);
    } catch (IOException e) {
        System.out.println("Config file is bad/nonexistent!");
        e.printStackTrace();
    }

    //Read sensors
    this.robotMap.getUpdater().run();

    this.loggerNotifier = new Notifier(robotMap.getLogger());
    this.driveSubsystem = robotMap.getDrive();

    //Run the logger to write all the events that happened during initialization to a file.
    robotMap.getLogger().run();
    Clock.updateTime();
}
项目:FRC-2017-Public    文件:SubsystemLooper.java   
public SubsystemLooper() {
    mLoops = new ArrayList<>();
    mNotifier = new Notifier(mRunnable);
    mRunning = false;

    mPrintNotifier = new Notifier(mPrinterRunnable);
    mPrinting = false;
}
项目:449-central-repo    文件:Robot.java   
/**
 * The method that runs when the robot is turned on. Initializes all subsystems from the map.
 */
public void robotInit() {
    //Set up start time
    Clock.setStartTime();
    Clock.updateTime();

    enabled = false;

    //Yes this should be a print statement, it's useful to know that robotInit started.
    System.out.println("Started robotInit.");

    Yaml yaml = new Yaml();
    try {
        //Read the yaml file with SnakeYaml so we can use anchors and merge syntax.
        Map<?, ?> normalized = (Map<?, ?>) yaml.load(new FileReader(RESOURCES_PATH + mapName));
        YAMLMapper mapper = new YAMLMapper();
        //Turn the Map read by SnakeYaml into a String so Jackson can read it.
        String fixed = mapper.writeValueAsString(normalized);
        //Use a parameter name module so we don't have to specify name for every field.
        mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
        //Add mix-ins
        mapper.registerModule(new WPIModule());
        //Deserialize the map into an object.
        robotMap = mapper.readValue(fixed, RobotMap.class);
    } catch (IOException e) {
        //This is either the map file not being in the file system OR it being improperly formatted.
        System.out.println("Config file is bad/nonexistent!");
        e.printStackTrace();
    }

    //Read sensors
    this.robotMap.getUpdater().run();

    //Set fields from the map.
    this.loggerNotifier = new Notifier(robotMap.getLogger());

    //Run the logger to write all the events that happened during initialization to a file.
    robotMap.getLogger().run();
    Clock.updateTime();
}
项目:FRC-2017-Public    文件:Looper.java   
public Looper() {
    notifier_ = new Notifier((Runnable) runnable_);
    running_ = false;
    loops_ = new ArrayList<>();
}
项目:FRC-2017    文件:MotionProfilePrototype.java   
/**
 * initialize method
 * 
 */
public static void initialize() {

    if (!initialized) {
        _talon = new CANTalon(TALON_ID);
        if (_talon != null) {

            System.out.println("Initializing motor (motion profile mode)...");

            //_talon.clearStickyFaults();

            _talon.reverseOutput(true);  // NEED TO REVERSE OUTPUT - used for closed loops modes only
            _talon.reverseSensor(true);  // encoder needs to be reversed

            /***** PID Motor Control section ******/
            // WARNING:  DO NOT SET I-term (middle value) TO NON-ZERO UNLESS YOU KNOW WHAT YOU'RE DOING
            // MOTOR CAN GO UNSTABLE AND CAN DESTROY ITSELF
            _talon.setPID(1, 0, 0);     // works - accurate position, light gains
            _talon.setF(0.3);    // set feedforward gain
            /***** PID Motor Control section ******/

            /******* Motion Profile mode *******/
            _talon.changeControlMode(CANTalon.TalonControlMode.MotionProfile);
            _talon.setFeedbackDevice(CANTalon.FeedbackDevice.QuadEncoder);
            _talon.setStatusFrameRateMs(CANTalon.StatusFrameRate.QuadEncoder, 10);
            _talon.configEncoderCodesPerRev(1024);
            _talon.changeMotionControlFramePeriod(5);

            _notifier = new Notifier(new PeriodicRunnable());
            _notifier.startPeriodic(0.005);

            _talon.setPosition(0);        // initializes encoder to zero                
            _talon.enableBrakeMode(true);        
        }
        else
            System.out.println("ERROR: motor not initialized!");        

        // reset the motion profile state machine
        reset();

        initialized = true;
    }
}