本文整理汇总了Java中edu.wpi.first.wpilibj.I2C类的典型用法代码示例。如果您正苦于以下问题:Java I2C类的具体用法?Java I2C怎么用?Java I2C使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
I2C类属于edu.wpi.first.wpilibj包,在下文中一共展示了I2C类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
public void update(){
// Shift all of the values to the left once
for (int i = 0; i < numberOfSamples - 1; i++) {
xValues[i] = xValues[i + 1];
yValues[i] = yValues[i + 1];
zValues[i] = zValues[i + 1];
}
// Update all of the values with accelerometer
xValues[numberOfSamples - 1] = this.getX();
yValues[numberOfSamples - 1] = this.getY();
zValues[numberOfSamples - 1] = this.getZ();
// If all of the latest values are 0, then the accelerometer crashed. DisablePID and stop the shooter aim motor, then try to re-initialize it.
if (xValues[numberOfSamples - 1] == 0 && yValues[numberOfSamples - 1] == 0 && zValues[numberOfSamples - 1] == 0) {
Robot.shooterAim.disablePID();
Robot.shooterAim.manualAim(0);
accelerometer = new ADXL345_I2C(I2C.Port.kOnboard, Accelerometer.Range.k4G);
}
}
示例2: SensorInput
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Instantiates the Sensor Input module to read all sensors connected to the roboRIO.
*/
private SensorInput() {
limit_left = new DigitalInput(ChiliConstants.left_limit);
limit_right = new DigitalInput(ChiliConstants.right_limit);
accel = new BuiltInAccelerometer(Accelerometer.Range.k2G);
gyro = new Gyro(ChiliConstants.gyro_channel);
pdp = new PowerDistributionPanel();
left_encoder = new Encoder(ChiliConstants.left_encoder_channelA, ChiliConstants.left_encoder_channelB, false);
right_encoder = new Encoder(ChiliConstants.right_encoder_channelA, ChiliConstants.right_encoder_channelB, true);
gyro_i2c = new GyroITG3200(I2C.Port.kOnboard);
gyro_i2c.initialize();
gyro_i2c.reset();
gyro.initGyro();
left_encoder.setDistancePerPulse(ChiliConstants.kDistancePerPulse);
right_encoder.setDistancePerPulse(ChiliConstants.kDistancePerPulse);
}
示例3: sendModeOverI2C
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Sends the current mode (auto, teleop, or disabled) over I2C.
*
* @param i2C The I2C channel to send the data over.
* @param mode The current mode, represented as a String.
*/
private void sendModeOverI2C(I2C i2C, String mode) {
//If the I2C exists
if (i2C != null) {
//Turn the alliance and mode into a character array.
char[] CharArray = (allianceString + "_" + mode).toCharArray();
//Transfer the character array to a byte array.
byte[] WriteData = new byte[CharArray.length];
for (int i = 0; i < CharArray.length; i++) {
WriteData[i] = (byte) CharArray[i];
}
//Send the byte array.
i2C.transaction(WriteData, WriteData.length, null, 0);
}
}
示例4: BNO055
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Instantiates a new BNO055 class.
*
* @param port the physical port the sensor is plugged into on the roboRio
* @param address the address the sensor is at (0x28 or 0x29)
*/
private BNO055(I2C.Port port, byte address) {
imu = new I2C(port, address);
executor = new java.util.Timer();
executor.schedule(new BNO055UpdateTask(this), 0L, THREAD_PERIOD);
}
示例5: getInstance
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Get an instance of the IMU object.
*
* @param mode the operating mode to run the sensor in.
* @param port the physical port the sensor is plugged into on the roboRio
* @param address the address the sensor is at (0x28 or 0x29)
* @return the instantiated BNO055 object
*/
public static BNO055 getInstance(opmode_t mode, vector_type_t vectorType,
I2C.Port port, byte address) {
if(instance == null) {
instance = new BNO055(port, address);
}
requestedMode = mode;
requestedVectorType = vectorType;
return instance;
}
示例6: TCS34725ColorSensor
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Constructor for TCS34725 Color Sensor from Adafruit. Initializes internal data structures and
* opens I2C coms to the device.
*/
TCS34725ColorSensor() {
color_sen = new I2C(Port.kOnboard, I2C_constants.TCS34725_I2C_ADDR);
sensor_initalized = false;
good_data_read = false;
}
示例7: BNO055
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Instantiates a new BNO055 class.
*
* @param port the physical port the sensor is plugged into on the roboRio
* @param address the address the sensor is at (0x28 or 0x29)
*/
private BNO055(I2C.Port port, byte address) {
imu = new I2C(port, address);
this.initialized = false;
this.state = 0;
executor = new java.util.Timer();
executor.schedule(new BNO055UpdateTask(this), 0L, THREAD_PERIOD);
}
示例8: getInstance
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Get an instance of the IMU object.
*
* @param mode the operating mode to run the sensor in.
* @param port the physical port the sensor is plugged into on the roboRio
* @param address the address the sensor is at (0x28 or 0x29)
* @return the instantiated BNO055 object
*/
public static BNO055 getInstance(opmode_t mode, vector_type_t vectorType,
I2C.Port port, byte address) {
if (instance == null) {
instance = new BNO055(port, address);
}
requestedMode = mode;
return instance;
}
示例9: initialize
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
public static void initialize() {
if (!initialized)
{
i2cBus = new I2C(I2C.Port.kMXP, 4);
initialized = true;
setTeamColor();
}
}
示例10: CompassReader
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
public CompassReader(VariableStore variables)
{
m_i2c = new I2C(I2C.Port.kOnboard, deviceAddress);
m_i2c.write(2, 0);
m_variables = variables;
alpha = variables.GetDouble(compassAlphaVariableName, alphaOrig);
beta = variables.GetDouble(compassBetaVariableName, betaOrig);
}
示例11: SparkfunGyro
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
public SparkfunGyro() {
mag = new I2C(I2C.Port.kOnboard, MAG_ADDR);
gyro = new I2C(I2C.Port.kOnboard, AG_ADDR);
buffer8[0] = 0;
initGyro();
//Bad startup values
//readCount(20);
//Calculate bias
bias = readCount(30);
bias /= 30;
}
示例12: PixyVision
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
public PixyVision(
final String instanceName, Robot robot, int signature, int brightness, Orientation orientation,
I2C.Port port, int i2cAddress)
{
pixyCamera = new FrcPixyCam(instanceName, port, i2cAddress);
commonInit(robot, signature, brightness, orientation);
}
示例13: FrcPixyCam
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Constructor: Create an instance of the object.
*
* @param instanceName specifies the instance name.
* @param port specifies the I2C port on the RoboRIO.
* @param devAddress specifies the I2C address of the device.
*/
public FrcPixyCam(final String instanceName, I2C.Port port, int devAddress)
{
super(instanceName);
if (debugEnabled)
{
dbgTrace = new TrcDbgTrace(moduleName + "." + instanceName, tracingEnabled, traceLevel, msgLevel);
}
pixyCam = new FrcI2cDevice(instanceName, port, devAddress);
start();
}
示例14: FrcI2cDevice
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Constructor: Creates an instance of the object.
*
* @param instanceName specifies the instance name.
* @param port specifies the I2C port the device is connected to.
* @param devAddress specifies the address of the device on the I2C bus.
*/
public FrcI2cDevice(final String instanceName, Port port, int devAddress)
{
super(instanceName);
if (debugEnabled)
{
dbgTrace = new TrcDbgTrace(moduleName + "." + instanceName, tracingEnabled, traceLevel, msgLevel);
}
device = new I2C(port, devAddress);
}
示例15: ADXL345_I2C_SparkFun
import edu.wpi.first.wpilibj.I2C; //导入依赖的package包/类
/**
* Constructor.
* @param port The I2C port the accelerometer is attached to
* @param range The range (+ or -) that the accelerometer will measure.
*/
public ADXL345_I2C_SparkFun(I2C.Port port, Range range) {
m_i2c = new I2C(port, kAddress);
// Turn on the measurements
m_i2c.write(kPowerCtlRegister, kPowerCtl_Measure);
setRange(range);
UsageReporting.report(tResourceType.kResourceType_ADXL345, tInstances.kADXL345_I2C);
LiveWindow.addSensor("ADXL345_I2C", port.getValue(), this);
}