本文整理匯總了Java中edu.wpi.first.wpilibj.DriverStation類的典型用法代碼示例。如果您正苦於以下問題:Java DriverStation類的具體用法?Java DriverStation怎麽用?Java DriverStation使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DriverStation類屬於edu.wpi.first.wpilibj包,在下文中一共展示了DriverStation類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: printError
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
/**
* Prints error to specified devices
*
* @param errorMessage
* the message to be printed.
* @param attatchTimeStamp
* whether or not to include a time stamp.
*/
public void printError (String errorMessage,
boolean attatchTimeStamp)
{
String appendedErrorMessage;
rioTime = getDate();
matchTime = Hardware.driverStation.getMatchTime();
if (appendTimeStamp == true)
appendedErrorMessage = appendErrorMessage(errorMessage);
else
appendedErrorMessage = errorMessage;
// if the error must print to the Drivers' Station
if (defaultPrintDevice == PrintsTo.driverStation ||
defaultPrintDevice == PrintsTo.driverStationAndRoboRIO)
{
final String dsReport = appendErrorMessage(errorMessage);
DriverStation.reportError(dsReport, false);
}
// if the error must print to the errorlog on the rio.
if (defaultPrintDevice == PrintsTo.roboRIO ||
defaultPrintDevice == PrintsTo.driverStationAndRoboRIO)
PrintsToRIO(appendedErrorMessage);
}
示例2: NavX
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的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(SerialPort.Port.kUSB);
} catch (RuntimeException ex ) {
DriverStation.reportError("Error instantiating navX MXP: " + ex.getMessage(), true);
}
}
示例3: JsonAutonomous
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
/**
* Creates a JsonAutonomous from the specified file
* @param file The location of the file to parse
*/
public JsonAutonomous(String file)
{
ap_ds = DriverStation.getInstance();
turn = new PIDController(0.02, 0, 0, Robot.navx, this);
turn.setInputRange(-180, 180);
turn.setOutputRange(-0.7, 0.7);
turn.setAbsoluteTolerance(0.5);
turn.setContinuous(true);
straighten = new PIDController(0.01, 0, 0, Robot.navx, this);
straighten.setInputRange(-180, 180);
straighten.setOutputRange(-0.7, 0.7);
straighten.setAbsoluteTolerance(0);
straighten.setContinuous(true);
turn.setPID(Config.getSetting("auto_turn_p", 0.02),
Config.getSetting("auto_turn_i", 0.00001),
Config.getSetting("auto_turn_d", 0));
straighten.setPID(Config.getSetting("auto_straight_p", 0.2),
Config.getSetting("auto_straight_i", 0),
Config.getSetting("auto_straight_d", 0));
parseFile(file);
}
示例4: NavX
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的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);
}
}
示例5: IMU
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的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);
}
}
示例6: logPeriodic
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
private void logPeriodic() {
mLogger.logRobotThread("Match time", DriverStation.getInstance().getMatchTime());
mLogger.logRobotThread("DS Connected", DriverStation.getInstance().isDSAttached());
mLogger.logRobotThread("DS Voltage", DriverStation.getInstance().getBatteryVoltage());
// mLogger.logRobotThread("Battery current", HardwareAdapter.getInstance().kPDP.getTotalCurrent());
// mLogger.logRobotThread("Battery watts drawn", HardwareAdapter.getInstance().kPDP.getTotalPower());
mLogger.logRobotThread("Outputs disabled", DriverStation.getInstance().isSysActive());
mLogger.logRobotThread("FMS connected: "+DriverStation.getInstance().isFMSAttached());
if (DriverStation.getInstance().isAutonomous()) {
mLogger.logRobotThread("Game period: Auto");
} else if (DriverStation.getInstance().isDisabled()) {
mLogger.logRobotThread("Game period: Disabled");
} else if (DriverStation.getInstance().isOperatorControl()) {
mLogger.logRobotThread("Game period: Teleop");
} else if (DriverStation.getInstance().isTest()) {
mLogger.logRobotThread("Game period: Test");
}
if (DriverStation.getInstance().isBrownedOut()) mLogger.logRobotThread("Browned out");
if (!DriverStation.getInstance().isNewControlData()) mLogger.logRobotThread("Didn't receive new control packet!");
}
示例7: ADXRS453_Gyro
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的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);
}
示例8: disabledPeriodic
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
public void disabledPeriodic() {
RobotMap.lightRing.set(Relay.Value.kOff);
Scheduler.getInstance().run();
recordedID = (String) (oi.index.getSelected());
recordedAuton = SmartDashboard.getBoolean("Use Recorded Autonomous");
Aimer.toPositionMode();
RobotMap.winchMotor.setEncPosition(0);
RobotMap.winchMotor.setPosition(0);
RobotMap.winchMotor.set(0);
DashboardOutput.putPeriodicData();
isBlue = (DriverStation.getInstance().getAlliance() == Alliance.Blue);
sendStateToLights(false, false);
}
示例9: forceSync
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
/**
* Clears the IO buffer in memory and forces things to file. Generally a good idea to use this
* as infrequently as possible (because it increases logging overhead), but definitely use it
* before the roboRIO might crash without a proper call to the close() method (ie, during
* brownout)
*
* @return 0 on flush success or -1 on failure.
*/
public static int forceSync() {
if (log_open == false) {
DriverStation.reportError("Error - Log is not yet opened, cannot sync!", false);
return -1;
}
try {
log_file.flush();
}
// Catch ALL the errors!!!
catch (IOException e) {
DriverStation.reportError("Error flushing IO stream file: " + e.getMessage(), false);
return -1;
}
return 0;
}
示例10: close
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
/**
* Closes the log file and ensures everything is written to disk. init() must be called again in
* order to write to the file.
*
* @return -1 on failure to close, 0 on success
*/
public static int close() {
if (log_open == false) {
return 0;
}
try {
log_file.close();
log_open = false;
}
// Catch ALL the errors!!!
catch (IOException e) {
DriverStation.reportError("Error Closing Log File: " + e.getMessage(), false);
return -1;
}
return 0;
}
示例11: logData
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
/**
* Logs data for all stored method handles. Methods that are not considered "simple" should be
* handled accordingly within this method. This method should be called once per loop.
*
* @param forceSync set true if a forced write is desired (i.e. brownout conditions)
* @return 0 if log successful, -1 if log is not open, and -2 on other errors
*/
public static int logData(boolean forceSync) {
if (!log_open) {
//System.out.println("ERROR - Log is not yet opened, cannot write!");
return -1;
}
if (forceSync)
forceSync();
try {
for (int i = 0; i < methodHandles.size(); i++) {
MethodHandle mh = methodHandles.get(i);
String fieldName = dataFieldNames.get(i);
Vector<Object> mhArgs = mhReferenceObjects.get(i);
log_file.write(getStandardLogData(mh, mhArgs,fieldName) + ", ");
}
log_file.write("\n");
} catch (Exception ex) {
DriverStation.reportError("Error writing to log file: " + ex.getMessage(), false);
return -2;
}
return 0;
}
示例12: ADXRS453_Gyro
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的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();
}
示例13: printError
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
/**
* Prints error to specified devices.
*
* @param errorMessage
* to be printed
*/
public void printError (String errorMessage)
{
String appendedErrorMessage;
rioTime = getDate();
matchTime = Hardware.driverStation.getMatchTime();
if (appendTimeStamp == true)
appendedErrorMessage = appendErrorMessage(errorMessage);
else
appendedErrorMessage = errorMessage;
// if the error must print to the Drivers' Station
if (defaultPrintDevice == PrintsTo.driverStation ||
defaultPrintDevice == PrintsTo.driverStationAndRoboRIO)
{
final String dsReport = appendErrorMessage(errorMessage);
DriverStation.reportError(dsReport, false);
}
// if the error must print to the errorlog on the rio.
if (defaultPrintDevice == PrintsTo.roboRIO ||
defaultPrintDevice == PrintsTo.driverStationAndRoboRIO)
PrintsToRIO(appendedErrorMessage);
}
示例14: runOnce
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
/**
* Runs the pipeline one time, giving it the next image from the video source specified
* in the constructor. This will block until the source either has an image or throws an error.
* If the source successfully supplied a frame, the pipeline's image input will be set,
* the pipeline will run, and the listener specified in the constructor will be called to notify
* it that the pipeline ran.
*
* <p>This method is exposed to allow teams to add additional functionality or have their own
* ways to run the pipeline. Most teams, however, should just use {@link #runForever} in its own
* thread using a {@link VisionThread}.</p>
*/
public void runOnce() {
if (Thread.currentThread().getId() == RobotBase.MAIN_THREAD_ID) {
throw new IllegalStateException(
"VisionRunner.runOnce() cannot be called from the main robot thread");
}
long frameTime = m_cvSink.grabFrame(m_image);
if (frameTime == 0) {
// There was an error, report it
String error = m_cvSink.getError();
DriverStation.reportError(error, true);
} else {
// No errors, process the image
m_pipeline.process(m_image);
m_listener.copyPipelineOutputs(m_pipeline);
}
}
示例15: autonomousInit
import edu.wpi.first.wpilibj.DriverStation; //導入依賴的package包/類
@Override
public void autonomousInit() {
System.out.println("Auto INIT");
Auto am = (Auto) a.getSelected();
Auto bm = (Auto) b.getSelected();
Auto cm = (Auto) c.getSelected();
String picked = "We picked: ";
picked += am.getClass().getName() + ", ";
picked += bm.getClass().getName() + ", ";
picked += cm.getClass().getName();
DriverStation.reportError(picked, false);
Auto[] m = { am, bm, cm };
RobotMap.arm1.setSetpoint(RobotMap.arm1.getPosition());
move = new ConfigMove(m);
//move = new TimedStraightMove(0.3, 10);
move.init();
}