/** * Create an analog switch sensor that is triggered when the value exceeds the specified upper voltage and that is no * longer triggered when the value drops below the specified lower voltage. * * @param channel the port to use for the analog trigger 0-3 are on-board, 4-7 are on the MXP port * @param lowerVoltage the lower voltage limit that below which will result in the switch no longer being triggered * @param upperVoltage the upper voltage limit that above which will result in triggering the switch * @param option the trigger option; may not be null * @param mode the trigger mode; may not be null * @return the analog switch; never null */ public static Switch analog(int channel, double lowerVoltage, double upperVoltage, AnalogOption option, TriggerMode mode) { if (option == null) throw new IllegalArgumentException("The analog option must be specified"); if (mode == null) throw new IllegalArgumentException("The analog mode must be specified"); AnalogTrigger trigger = new AnalogTrigger(channel); trigger.setLimitsVoltage(lowerVoltage, upperVoltage); switch (option) { case AVERAGED: trigger.setAveraged(true); break; case FILTERED: trigger.setFiltered(true); break; case NONE: break; } return mode == TriggerMode.AVERAGED ? trigger::getTriggerState : trigger::getInWindow; }
public Robot() { stick = new Joystick(0); try { /* Construct Digital I/O Objects */ pwm_out_9 = new Victor( getChannelFromPin( PinType.PWM, 9 )); pwm_out_8 = new Jaguar( getChannelFromPin( PinType.PWM, 8 )); dig_in_7 = new DigitalInput( getChannelFromPin( PinType.DigitalIO, 7 )); dig_in_6 = new DigitalInput( getChannelFromPin( PinType.DigitalIO, 6 )); dig_out_5 = new DigitalOutput( getChannelFromPin( PinType.DigitalIO, 5 )); dig_out_4 = new DigitalOutput( getChannelFromPin( PinType.DigitalIO, 4 )); enc_3and2 = new Encoder( getChannelFromPin( PinType.DigitalIO, 3 ), getChannelFromPin( PinType.DigitalIO, 2 )); enc_1and0 = new Encoder( getChannelFromPin( PinType.DigitalIO, 1 ), getChannelFromPin( PinType.DigitalIO, 0 )); /* Construct Analog I/O Objects */ /* NOTE: Due to a board layout issue on the navX MXP board revision */ /* 3.3, there is noticeable crosstalk between AN IN pins 3, 2 and 1. */ /* For that reason, use of pin 3 and pin 2 is NOT RECOMMENDED. */ an_in_1 = new AnalogInput( getChannelFromPin( PinType.AnalogIn, 1 )); an_trig_0 = new AnalogTrigger( getChannelFromPin( PinType.AnalogIn, 0 )); an_trig_0_counter = new Counter( an_trig_0 ); an_out_1 = new AnalogOutput( getChannelFromPin( PinType.AnalogOut, 1 )); an_out_0 = new AnalogOutput( getChannelFromPin( PinType.AnalogOut, 0 )); /* Configure I/O Objects */ pwm_out_9.setSafetyEnabled(false); /* Disable Motor Safety for Demo */ pwm_out_8.setSafetyEnabled(false); /* Disable Motor Safety for Demo */ /* Configure Analog Trigger */ an_trig_0.setAveraged(true); an_trig_0.setLimitsVoltage(MIN_AN_TRIGGER_VOLTAGE, MAX_AN_TRIGGER_VOLTAGE); } catch (RuntimeException ex ) { DriverStation.reportError( "Error instantiating MXP pin on navX MXP: " + ex.getMessage(), true); } }
public AbsoluteAnalogEncoder(int channel, double minVoltage, double maxVoltage, double offsetDegrees, int analogSampleRate, double analogTriggerThresholdDifference) { //TODO: Implement direction super(channel); _channel = channel; if (minVoltage >= maxVoltage) throw new IllegalArgumentException("Minimum voltage must be less than maximum voltage"); if (offsetDegrees < 0 || offsetDegrees > 360) throw new IllegalArgumentException("Offset must be between 0 and 360 degrees"); // Initialize analog trigger // _analogTrigger = new AnalogTrigger(channel); _analogTrigger.setFiltered(true); _analogTrigger.setLimitsVoltage(minVoltage + analogTriggerThresholdDifference, maxVoltage - analogTriggerThresholdDifference); AnalogTriggerOutput _analogTriggerFalling = new AnalogTriggerOutput(_analogTrigger, AnalogTriggerOutput.Type.kFallingPulse); AnalogTriggerOutput _analogTriggerRising = new AnalogTriggerOutput(_analogTrigger, AnalogTriggerOutput.Type.kRisingPulse); // Set analog module sampling rate // AnalogModule module = (AnalogModule) Module.getModule(ModulePresence.ModuleType.kAnalog, DEFAULT_ANALOG_MODULE); module.setSampleRate(analogSampleRate); // Initialize turn counter // _turnCounter = new Counter(); _turnCounter.setUpDownCounterMode(); _turnCounter.setUpSource(_analogTriggerRising); _turnCounter.setDownSource(_analogTriggerFalling); _turnCounter.start(); _minVoltage = minVoltage; _maxVoltage = maxVoltage; _offsetDegrees = offsetDegrees; }
public AnalogChannelVolt(int moduleNumber, int channel) { super(moduleNumber, channel); this.getModule().setSampleRate(1000); m_trig = new AnalogTrigger(moduleNumber, channel); m_trig.setFiltered(true); m_trig.setLimitsVoltage(1.35, 3.65); m_count = new Counter(); m_count.setUpDownCounterMode(); m_count.setUpSource(m_trig, AnalogTriggerOutput.Type.kFallingPulse); m_count.setDownSource(m_trig, AnalogTriggerOutput.Type.kRisingPulse); m_count.start(); }