本文整理汇总了Java中edu.wpi.first.wpilibj.SPI类的典型用法代码示例。如果您正苦于以下问题:Java SPI类的具体用法?Java SPI怎么用?Java SPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SPI类属于edu.wpi.first.wpilibj包,在下文中一共展示了SPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: NavX
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public NavX() {
try {
/***********************************************************************
* navX-MXP:
* - Communication via RoboRIO MXP (SPI, I2C, TTL UART) and USB.
* - See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface.
*
* navX-Micro:
* - Communication via I2C (RoboRIO MXP or Onboard) and USB.
* - See http://navx-micro.kauailabs.com/guidance/selecting-an-interface.
*
* Multiple navX-model devices on a single robot are supported.
************************************************************************/
ahrs = new AHRS(SPI.Port.kMXP); // Use SPI!!!
//ahrs = new AHRS(I2C.Port.kMXP);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
}
示例2: IMU
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public IMU() {
try {
/***********************************************************************
* navX-MXP:
* - Communication via RoboRIO MXP (SPI, I2C, TTL UART) and USB.
* - See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface.
*
* navX-Micro:
* - Communication via I2C (RoboRIO MXP or Onboard) and USB.
* - See http://navx-micro.kauailabs.com/guidance/selecting-an-interface.
*
* Multiple navX-model devices on a single robot are supported.
************************************************************************/
ahrs = new AHRS(SPI.Port.kMXP);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
}
示例3: ADXRS453_Gyro
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
/**
* Constructor.
*
* @param port
* (the SPI port that the gyro is connected to)
*/
public ADXRS453_Gyro(SPI.Port port) {
m_spi = new SPI(port);
m_spi.setClockRate(3000000);
m_spi.setMSBFirst();
m_spi.setSampleDataOnRising();
m_spi.setClockActiveHigh();
m_spi.setChipSelectActiveLow();
/** Validate the part ID */
if ((readRegister(kPIDRegister) & 0xff00) != 0x5200) {
m_spi.free();
m_spi = null;
DriverStation.reportError("Could not find ADXRS453 gyro on SPI port " + port.value, false);
return;
}
m_spi.initAccumulator(kSamplePeriod, 0x20000000, 4, 0x0c00000E, 0x04000000, 10, 16, true, true);
calibrate();
LiveWindow.addSensor("ADXRS453_Gyro", port.value, this);
}
示例4: ADXRS453_Gyro
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
/**
* Constructor.
*
* @param port
* (the SPI port that the gyro is connected to)
*/
public ADXRS453_Gyro(SPI.Port port) {
m_spi = new SPI(port);
m_spi.setClockRate(3000000);
m_spi.setMSBFirst();
m_spi.setSampleDataOnRising();
m_spi.setClockActiveHigh();
m_spi.setChipSelectActiveLow();
/** Validate the part ID */
if ((readRegister(kPIDRegister) & 0xff00) != 0x5200) {
m_spi.free();
m_spi = null;
DriverStation.reportError("Could not find ADXRS453 gyro on SPI port " + port.name(), false);
return;
}
m_spi.initAccumulator(kSamplePeriod, 0x20000000, 4, 0x0c00000E, 0x04000000, 10, 16, true, true);
calibrate();
}
示例5: SpatialAwarenessSubsystem
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public SpatialAwarenessSubsystem() {
super("SpatialAwarenessSubsystem");
cameraServer = CameraServer.getInstance();
gearCamera = cameraServer.startAutomaticCapture(0);
gearCamera.setResolution(IMG_WIDTH, IMG_HEIGHT);
gearCamera.setFPS(30);
gearCamera.setBrightness(7);
gearCamera.setExposureManual(30);
gearVideo = cameraServer.getVideo(gearCamera);
visionProcessing = new VisionProcessing();
leftUltrasonic = new AnalogInput(RobotMap.ANALOG_ULTRASONIC_LEFT);
rightUltrasonic = new AnalogInput(RobotMap.ANALOG_ULTRASONIC_RIGHT);
leftUltrasonicKalman = new SimpleKalman(1.4d, 64d, leftUltrasonic.getAverageVoltage() * ULTRASONIC_VOLTS_TO_METERS);
rightUltrasonicKalman = new SimpleKalman(1.4d, 64d, rightUltrasonic.getAverageVoltage() * ULTRASONIC_VOLTS_TO_METERS);
navX = new AHRS(SPI.Port.kMXP);
System.out.println("SpatialAwarenessSubsystem constructor finished");
}
示例6: initialize
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public static void initialize()
{
if (!initialized) {
System.out.println("NavXSensor::initialize() called...");
try {
ahrs = new AHRS(SPI.Port.kMXP);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
reset();
initialized = true;
}
}
示例7: Robot
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public Robot() {
myRobot = new RobotDrive(0, 1);
myRobot.setExpiration(0.1);
stick = new Joystick(0);
try {
/***********************************************************************
* navX-MXP:
* - Communication via RoboRIO MXP (SPI, I2C, TTL UART) and USB.
* - See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface.
*
* navX-Micro:
* - Communication via I2C (RoboRIO MXP or Onboard) and USB.
* - See http://navx-micro.kauailabs.com/guidance/selecting-an-interface.
*
* Multiple navX-model devices on a single robot are supported.
************************************************************************/
ahrs = new AHRS(SPI.Port.kMXP);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
}
示例8: Robot
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public Robot() {
myRobot = new RobotDrive(frontLeftChannel, rearLeftChannel,
frontRightChannel, rearRightChannel);
myRobot.setExpiration(0.1);
stick = new Joystick(0);
try {
/***********************************************************************
* navX-MXP:
* - Communication via RoboRIO MXP (SPI, I2C, TTL UART) and USB.
* - See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface.
*
* navX-Micro:
* - Communication via I2C (RoboRIO MXP or Onboard) and USB.
* - See http://navx-micro.kauailabs.com/guidance/selecting-an-interface.
*
* Multiple navX-model devices on a single robot are supported.
************************************************************************/
ahrs = new AHRS(SPI.Port.kMXP);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
}
示例9: Robot
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public Robot() {
myRobot = new RobotDrive(frontLeftChannel, rearLeftChannel,
frontRightChannel, rearRightChannel);
myRobot.setExpiration(0.1);
stick = new Joystick(0);
try {
/***********************************************************************
* navX-MXP:
* - Communication via RoboRIO MXP (SPI, I2C, TTL UART) and USB.
* - See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface.
*
* navX-Micro:
* - Communication via I2C (RoboRIO MXP or Onboard) and USB.
* - See http://navx-micro.kauailabs.com/guidance/selecting-an-interface.
*
* Multiple navX-model devices on a single robot are supported.
************************************************************************/
ahrs = new AHRS(SPI.Port.kMXP);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
}
示例10: Robot
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public Robot() {
myRobot = new RobotDrive(frontLeftChannel, rearLeftChannel,
frontRightChannel, rearRightChannel);
myRobot.setExpiration(0.1);
stick = new Joystick(0);
try {
/***********************************************************************
* navX-MXP:
* - Communication via RoboRIO MXP (SPI, I2C, TTL UART) and USB.
* - See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface.
*
* navX-Micro:
* - Communication via I2C (RoboRIO MXP or Onboard) and USB.
* - See http://navx-micro.kauailabs.com/guidance/selecting-an-interface.
*
* Multiple navX-model devices on a single robot are supported.
************************************************************************/
ahrs = new AHRS(SPI.Port.kMXP);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
}
示例11: Robot
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public Robot() {
stick = new Joystick(0);
try {
/***********************************************************************
* navX-MXP:
* - Communication via RoboRIO MXP (SPI, I2C, TTL UART) and USB.
* - See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface.
*
* navX-Micro:
* - Communication via I2C (RoboRIO MXP or Onboard) and USB.
* - See http://navx-micro.kauailabs.com/guidance/selecting-an-interface.
*
* Multiple navX-model devices on a single robot are supported.
************************************************************************/
ahrs = new AHRS(SPI.Port.kMXP);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
}
示例12: robotInit
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public void robotInit() {
// Create subsystems
drive = new Drive();
intake = new Intake();
arm = new Arm();
shooter = new Shooter();
hanger = new Hanger();
oi = new OI();
// Create motion profiles
crossLowBar = new Profile(AutoMap.crossLowBar);
reach = new Profile(AutoMap.reach);
toShoot = new Profile(AutoMap.toShoot);
toLowGoal = new Profile(AutoMap.toLowGoal);
// Pick an auto
chooser = new SendableChooser();
chooser.addDefault("Do Nothing", new DoNothing());
chooser.addObject("Low Bar", new LowBarRawtonomous());
chooser.addObject("Low Bar (profile)", new CrossLowBar(crossLowBar));
chooser.addObject("Reach", new Reach(reach));
chooser.addObject("Forward Rawto", new ForwardRawtonomous());
chooser.addObject("Backward Rawto", new BackwardRawtonomous());
chooser.addObject("Shoot", new AutoShoot());
SmartDashboard.putData("Auto mode", chooser);
// Start camera stream
camera = new USBCamera();
server = CameraServer.getInstance();
server.setQuality(40);
server.startAutomaticCapture(camera);
// Start compressor
compressor = new Compressor();
compressor.start();
navx = new AHRS(SPI.Port.kMXP);
}
示例13: MappedAHRS
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
/**
* Default constructor.
*
* @param port The port the NavX is plugged into. It seems like only kMXP (the port on the RIO) works.
* @param invertYaw Whether or not to invert the yaw axis. Defaults to true.
*/
@JsonCreator
public MappedAHRS(@JsonProperty(required = true) SPI.Port port,
Boolean invertYaw) {
this.ahrs = new AHRS(port);
ahrs.reset();
if (invertYaw == null || invertYaw) {
this.invertYaw = -1;
} else {
this.invertYaw = 1;
}
}
示例14: DotStarsLEDStrip
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
/**
* Constructor for led strip class
*
* @param numLEDs number of LED's in the total strip.
*/
public DotStarsLEDStrip(int numLEDs) {
// Number of bytes in color buffer needed - each LED has 4 bytes (1 brightness, then 1 for
// RGB each),
// plus the start and end frame.
num_leds = numLEDs;
int num_bytes_for_strip = 4 * numLEDs + startFrame.length + endFrame.length;
endFrameOffset = 4 * numLEDs + startFrame.length;
// Initialize color buffer
ledBuffer = new byte[num_bytes_for_strip];
// Write in the start/end buffers
for (int i = 0; i < startFrame.length; i++)
ledBuffer[i] = startFrame[i];
for (int i = 0; i < endFrame.length; i++)
ledBuffer[i + endFrameOffset] = endFrame[i];
// mark buffer as not-yet-written-to-the-LEDs
newBuffer = true;
// Initialize SPI coms on the Offboard port
spi = new SPI(SPI.Port.kMXP);
spi.setMSBFirst();
spi.setClockActiveLow();
spi.setClockRate(SPI_CLK_RATE);
spi.setSampleDataOnFalling();
timerThread = new java.util.Timer("DotStar LED Strip Control");
timerThread.schedule(new DotStarsTask(this), (long) (m_update_period_ms), (long) (m_update_period_ms));
}
示例15: Sensors
import edu.wpi.first.wpilibj.SPI; //导入依赖的package包/类
public Sensors() {
ahrs = new AHRS(SPI.Port.kMXP);
ahrs.reset();
intakeLidar = new AnalogInput(RobotMap.INTAKE_LIDAR_PORT);
longLidar = new AnalogInput(RobotMap.LONG_LIDAR_PORT);
table = NetworkTable.getTable("SmartDashboard");
}