项目:strongback-java
文件:Hardware.java
/**
* 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;
}
项目:turtleshell
文件:Robot.java
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 ),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);
}
}
项目:SwerveDrive
文件:AbsoluteAnalogEncoder.java
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;
}
项目:SwerveDriveTest
文件:AnalogChannelVolt.java
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();
}
项目:MOEnarch-Drive
文件:AnalogChannelVolt.java
public AnalogChannelVolt(int moduleNumber,AnalogTriggerOutput.Type.kRisingpulse);
m_count.start();
}