项目: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;
}
private static byte [] createAnalogPacket(int module) {
byte [] data = new byte[9 + headerSize];
generateHeader(data,headerSize,1);
data[headerSize] = (byte)module;
for (int i = 0; i < 8; i++) {
data[i+headerSize+1] = (byte)(5 / AnalogModule.getInstance(module).getVoltage(i+1) * 255);
// data[i+headerSize+1] = 0;
}
return data;
}
private static byte [] createAnalogPacket(int module) {
byte [] data = new byte[9 + headerSize];
generateHeader(data,1);
data[headerSize] = (byte)module;
for (int i = 0; i < 8; i++) {
data[i+headerSize+1] = (byte)(5 / AnalogModule.getInstance(module).getVoltage(i+1) * 255);
// data[i+headerSize+1] = 0;
}
return data;
}
项目:2012
文件:UltraSonicSensor.java
/**
* Constructor that uses the default module slot
*
* @param analogChannel channel the ultrasonic sensor is connected to on the
* cRIO 9201 module.
*/
public UltraSonicSensor(int analogChannel)
{
channel = analogChannel;
ultrasonicSensor = AnalogModule.getInstance(1);
}
项目:2013
文件:Ultrasonic.java
/**
* Constructor that uses the default module slot
*
* @param analogChannel channel the ultrasonic sensor is connected to on the
* cRIO 9201 module.
*/
public Ultrasonic(int analogChannel) {
channel = analogChannel;
ultrasonicSensor = AnalogModule.getInstance(1);
}