本文整理汇总了Java中edu.wpi.first.wpilibj.util.BoundaryException.assertWithinBounds方法的典型用法代码示例。如果您正苦于以下问题:Java BoundaryException.assertWithinBounds方法的具体用法?Java BoundaryException.assertWithinBounds怎么用?Java BoundaryException.assertWithinBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.wpi.first.wpilibj.util.BoundaryException
的用法示例。
在下文中一共展示了BoundaryException.assertWithinBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAnalogOut
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Set the analog output voltage.
*
* AO1 is pin 11 on the top connector (P2).
* AO2 is pin 12 on the top connector (P2).
* AO1 is the reference voltage for the 2 analog comparators on DIO15 and DIO16.
*
* The output range is 0V to 4V, however due to the supply voltage don't expect more than about 3V.
* Current supply capability is only 100uA.
*
* @param channel The analog output channel on the DS IO. [1,2]
* @param value The voltage to output on the channel.
*/
public void setAnalogOut(int channel, double value) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 2);
if (!m_outputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
if (value < 0.0) {
value = 0.0;
}
if (value > kAnalogOutputReference) {
value = kAnalogOutputReference;
}
if (value > kAnalogOutputReference) {
value = kAnalogOutputReference;
}
synchronized (m_outputDataSemaphore) {
m_outputData.data.dac[channel - 1] = (byte) (value / kAnalogOutputReference * kAnalogOutputResolution);
}
}
示例2: setLED
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Set the state of an LED on the IO board.
*
* @param channel The LED channel to set. [1,8]
* @param value True to turn the LED on.
*/
public void setLED(int channel, boolean value) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 8);
if (!m_outputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
byte leds;
synchronized (m_outputDataSemaphore) {
leds = m_outputData.data.leds;
leds &= ~(1 << (channel - 1));
if (value) {
leds |= 1 << (channel - 1);
}
m_outputData.data.leds = leds;
}
}
示例3: setDigitalOutput
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Set the state of a DIO line that is configured for digital output.
*
* @param channel The DIO channel to set. [1,16]
* @param value The state to set the selected channel to.
*/
public void setDigitalOutput(int channel, boolean value) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 16);
if (!m_outputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
short digital;
synchronized (m_outputDataSemaphore) {
if ((m_outputData.data.digital_oe & (1 << (channel - 1))) != 0) {
digital = m_outputData.data.digital;
digital &= ~(1 << (channel - 1));
if (value) {
digital |= 1 << (channel - 1);
}
m_outputData.data.digital = digital;
} else {
System.err.println("Line not configured for output");
}
}
}
示例4: setFixedDigitalOutput
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Set the state to output on a Fixed High Current Digital Output line.
*
* FixedDO1 is pin 5 on the top connector (P2).
* FixedDO2 is pin 3 on the top connector (P2).
*
* The FixedDO lines always output 0V and 3.3V regardless of J1 and J4.
* They can source 4mA and can sink 25mA. Because of this, they are expected to be used
* in an active low configuration, such as connecting to the cathode of a bright LED.
* Because they are expected to be active low, they default to true.
*
* @param channel The FixedDO channel to set.
* @param value The state to set the FixedDO.
*/
public void setFixedDigitalOutput(int channel, boolean value) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 2);
if (!m_outputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
byte digital;
synchronized (m_outputDataSemaphore) {
digital = m_outputData.data.fixed_digital_out;
digital &= ~(1 << (channel - 1));
if (value) {
digital |= 1 << (channel - 1);
}
m_outputData.data.fixed_digital_out = digital;
}
}
示例5: setPIDSourceType
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Set which parameter of the encoder you are using as a process control variable. The counter
* class supports the rate and distance parameters.
*
* @param pidSource An enum to select the parameter.
*/
public void setPIDSourceType(PIDSourceType pidSource) {
if (pidSource == null) {
throw new NullPointerException("PID Source Parameter given was null");
}
BoundaryException.assertWithinBounds(pidSource.value, 0, 1);
m_pidSource = pidSource;
}
示例6: setPIDSourceType
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Set which parameter of the encoder you are using as a process control
* variable. The counter class supports the rate and distance parameters.
*
* @param pidSource An enum to select the parameter.
*/
public void setPIDSourceType(PIDSourceType pidSource) {
if (pidSource == null) {
throw new NullPointerException("PID Source Parameter given was null");
}
BoundaryException.assertWithinBounds(pidSource.value, 0, 1);
m_pidSource = pidSource;
}
示例7: readOnly
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Execute a read only transaction with the device.
* <p/>
* Read 1 to 7 bytes from a device. This method does not write any data to prompt
* the device.
*
* @param buffer A pointer to the array of bytes to store the data read from
* the device.
* @param count The number of bytes to read in the transaction. [1..7]
* @return Transfer Aborted... false for success, true for aborted.
*/
public boolean readOnly(byte[] buffer, int count) {
BoundaryException.assertWithinBounds(count, 1, 7);
if (buffer == null) {
throw new NullPointerException("Null return buffer was given");
}
ByteBuffer dataReceivedBuffer = ByteBuffer.allocateDirect(count);
int retVal = 0;
dataReceivedBuffer.get(buffer);
return retVal < 0;
}
示例8: getPWMOutput
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Get the percent duty-cycle that the PWM generator channel is configured to output.
*
* @param channel The DIO line's PWM generator to get the duty-cycle from. [1,4]
* @return The percent duty-cycle being output (if the DIO line is configured for PWM). [0.0,1.0]
*/
public double getPWMOutput(int channel) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 4);
if (!m_outputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
synchronized (m_outputDataSemaphore) {
int tempCompare = m_outputData.data.pwm_compare[channel - 1] & 0xFFFF;
int tempPeriod = m_outputData.data.pwm_period[(channel - 1) >> 1] & 0xFFFF;
return (double) tempCompare / (double) tempPeriod;
}
}
示例9: getAnalogInRatio
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Query an analog input channel on the DS IO in ratiometric form.
*
* @param channel The channel number to read. [1,8]
* @return The analog input percentage for the channel.
*/
public double getAnalogInRatio(int channel) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 8);
if (!m_inputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
synchronized (m_inputDataSemaphore) {
return m_inputData.data.analog[channel - 1] / kAnalogInputResolution;
}
}
示例10: getAnalogOut
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Query the voltage currently being output.
*
* AO1 is pin 11 on the top connector (P2).
* AO2 is pin 12 on the top connector (P2).
*
* @param channel The analog output channel on the DS IO. [1,2]
* @return The voltage being output on the channel.
*/
public double getAnalogOut(int channel) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 2);
if (!m_outputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
synchronized (m_outputDataSemaphore) {
int tempData = m_outputData.data.dac[channel - 1];
tempData = tempData < 0 ? tempData + 256 : tempData;
return tempData * kAnalogOutputReference / kAnalogOutputResolution;
}
}
示例11: getDigitalConfig
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Get the current configuration for a DIO line.
*
* This has the side effect of forcing the Driver Station to switch to Enhanced mode if it's not when called.
* If Enhanced mode is not enabled when this is called, it will return kUnknown.
*
* @param channel The DIO channel config to get. [1,16]
* @return The configured mode for the DIO line.
*/
public tDigitalConfig getDigitalConfig(int channel) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 16);
if (!m_outputValid) {
m_requestEnhancedEnable = true;
throw new EnhancedIOException("Enhanced IO Missing");
}
synchronized (m_outputDataSemaphore) {
if ((channel >= 1) && (channel <= 4)) {
if ((m_outputData.data.pwm_enable & (1 << (channel - 1))) != 0) {
return tDigitalConfig.kPWM;
}
}
if ((channel >= 15) && (channel <= 16)) {
if ((m_outputData.data.comparator_enable & (1 << (channel - 15))) != 0) {
return tDigitalConfig.kAnalogComparator;
}
}
if ((m_outputData.data.digital_oe & (1 << (channel - 1))) != 0) {
return tDigitalConfig.kOutput;
}
if ((m_outputData.data.digital_pe & (1 << (channel - 1))) == 0) {
return tDigitalConfig.kInputFloating;
}
if ((m_outputData.data.digital & (1 << (channel - 1))) != 0) {
return tDigitalConfig.kInputPullUp;
} else {
return tDigitalConfig.kInputPullDown;
}
}
}
示例12: setPWMOutput
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Set the percent duty-cycle to output on a PWM enabled DIO line.
*
* DIO1 through DIO4 have the ability to output a PWM signal. The period of the
* signal can be configured in pairs using SetPWMPeriod().
*
* @param channel The DIO line's PWM generator to set. [1,4]
* @param value The percent duty-cycle to output from the PWM generator. [0.0,1.0]
*/
public void setPWMOutput(int channel, double value) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 4);
if (!m_outputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
if (value > 1.0) {
value = 1.0;
} else if (value < 0.0) {
value = 0.0;
}
synchronized (m_outputDataSemaphore) {
m_outputData.data.pwm_compare[channel - 1] = (short) (value * (double) m_outputData.data.pwm_period[(channel - 1) >> 1]);
}
}
示例13: getFixedDigitalOutput
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Get the state being output on a fixed digital output.
*
* @param channel The FixedDO line to get. [1,2]
* @return The state of the FixedDO line.
*/
public boolean getFixedDigitalOutput(int channel) throws EnhancedIOException {
BoundaryException.assertWithinBounds(channel, 1, 2);
if (!m_outputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
synchronized (m_outputDataSemaphore) {
return ((m_outputData.data.fixed_digital_out >> (channel - 1)) & 1) != 0;
}
}
示例14: resetEncoder
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Reset the position of an encoder to 0.
*
* This simply stores an offset locally. It does not reset the hardware counter on the IO board.
* If you use this method with Index enabled, you may get unexpected results.
*
* @param encoderNumber The quadrature encoder to reset. [1,2]
*/
public void resetEncoder(int encoderNumber) throws EnhancedIOException {
BoundaryException.assertWithinBounds(encoderNumber, 1, 2);
if (!m_inputValid) {
throw new EnhancedIOException("Enhanced IO Missing");
}
synchronized (m_inputDataSemaphore) {
m_encoderOffsets[encoderNumber - 1] = m_inputData.data.quad[encoderNumber - 1];
}
}
示例15: getEncoderIndexEnable
import edu.wpi.first.wpilibj.util.BoundaryException; //导入方法依赖的package包/类
/**
* Get the current configuration of a quadrature encoder index channel.
*
* This has the side effect of forcing the Driver Station to switch to Enhanced mode if it's not when called.
* If Enhanced mode is not enabled when this is called, it will return false.
*
* @param encoderNumber The quadrature encoder. [1,2]
* @return Is the index channel of the encoder enabled.
*/
public boolean getEncoderIndexEnable(int encoderNumber) throws EnhancedIOException {
BoundaryException.assertWithinBounds(encoderNumber, 1, 2);
if (!m_outputValid) {
m_requestEnhancedEnable = true;
throw new EnhancedIOException("Enhanced IO Missing");
}
synchronized (m_outputDataSemaphore) {
return ((m_outputData.data.quad_index_enable >> (encoderNumber - 1)) & 1) != 0;
}
}