本文整理汇总了Java中com.qualcomm.robotcore.util.ElapsedTime类的典型用法代码示例。如果您正苦于以下问题:Java ElapsedTime类的具体用法?Java ElapsedTime怎么用?Java ElapsedTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ElapsedTime类属于com.qualcomm.robotcore.util包,在下文中一共展示了ElapsedTime类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gyroHold
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
/**
* Method to obtain & hold a heading for a finite amount of time
* Move will stop once the requested time has elapsed
*
* @param speed Desired speed of turn.
* @param angle Absolute Angle (in Degrees) relative to last gyro reset.
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
* If a relative angle is required, add/subtract from current heading.
* @param holdTime Length of time (in seconds) to hold the specified heading.
*/
public void gyroHold( double speed, double angle, double holdTime) {
ElapsedTime holdTimer = new ElapsedTime();
// keep looping while we have time remaining.
holdTimer.reset();
while (opModeIsActive() && (holdTimer.time() < holdTime)) {
// Update telemetry & Allow time for other processes to run.
onHeading(speed, angle, P_TURN_COEFF);
telemetry.update();
}
// Stop all motion;
robot.leftMotor.setPower(0);
robot.rightMotor.setPower(0);
}
示例2: gyroHold
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
/**
* Method to obtain & hold a heading for a finite amount of time
* Move will stop once the requested time has elapsed
*
* @param speed Desired speed of turn.
* @param angle Absolute Angle (in Degrees) relative to last gyro reset.
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
* If a relative angle is required, add/subtract from current heading.
* @param holdTime Length of time (in seconds) to hold the specified heading.
*/
public void gyroHold( double speed, double angle, double holdTime) {
ElapsedTime holdTimer = new ElapsedTime();
// keep looping while we have time remaining.
holdTimer.reset();
while (opModeIsActive() && (holdTimer.time() < holdTime)) {
// Update telemetry & Allow time for other processes to run.
onHeading(speed, angle, P_TURN_COEFF);
telemetry.update();
}
// Stop all motion;
robot.leftDrive.setPower(0);
robot.rightDrive.setPower(0);
}
示例3: gyroHold
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
/**
* Method to obtain & hold a heading for a finite amount of time
* Move will stop once the requested time has elapsed
*
* @param speed Desired speed of turn.
* @param angle Absolute Angle (in Degrees) relative to last gyro reset.
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
* If a relative angle is required, add/subtract from current heading.
* @param holdTime Length of time (in seconds) to hold the specified heading.
* @throws InterruptedException
*/
public void gyroHold( double speed, double angle, double holdTime)
throws InterruptedException {
ElapsedTime holdTimer = new ElapsedTime();
// keep looping while we have time remaining.
holdTimer.reset();
while (opModeIsActive() && (holdTimer.time() < holdTime)) {
// Update telemetry & Allow time for other processes to run.
onHeading(speed, angle, P_TURN_COEFF);
telemetry.update();
idle();
}
// Stop all motion;
robot.leftMotor.setPower(0);
robot.rightMotor.setPower(0);
}
示例4: gyroHold
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
/**
* Method to obtain & hold a heading for a finite amount of time
* Move will stop once the requested time has elapsed
*
* @param speed Desired speed of turn.
* @param angle Absolute Angle (in Degrees) relative to last gyro reset.
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
* If a relative angle is required, add/subtract from current heading.
* @param holdTime Length of time (in seconds) to hold the specified heading.
*/
public void gyroHold(double speed, double angle, double holdTime) {
ElapsedTime holdTimer = new ElapsedTime();
// keep looping while we have time remaining.
holdTimer.reset();
while (opModeIsActive() && (holdTimer.time() < holdTime)) {
// Update telemetry & Allow time for other processes to run.
onHeading(speed, angle, P_TURN_COEFF);
telemetry.update();
}
// Stop all motion;
robot.leftMotor.setPower(0);
robot.rightMotor.setPower(0);
}
示例5: init
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
@Override
public void init() {
driveRightFront = hardwareMap.dcMotor.get("driveRightFront");
driveLeftFront = hardwareMap.dcMotor.get("driveLeftFront");
driveRightBack = hardwareMap.dcMotor.get("driveRightBack");
driveLeftBack = hardwareMap.dcMotor.get("driveLeftBack");
driveRightFront.setDirection(DcMotor.Direction.REVERSE);
driveRightBack.setDirection(DcMotor.Direction.REVERSE);
driveFrontController = hardwareMap.dcMotorController.get("driveFrontController");
driveBackController = hardwareMap.dcMotorController.get("driveBackController");
time = new ElapsedTime();
state = State.drivingStraight;
}
示例6: runOpMode
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
@Override
public void runOpMode() throws InterruptedException
{
DcMotor motor = this.hardwareMap.dcMotor.get("motorRight");
Servo servo = this.hardwareMap.servo.get("servo");
waitForStart();
double servoPosition = 0;
servo.setPosition(servoPosition);
motor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
ElapsedTime elapsedTime = new ElapsedTime();
int spinCount = 0;
while (this.opModeIsActive())
{
servoPosition += 1. / 256.;
if (servoPosition >= 1)
servoPosition = 0;
servo.setPosition(servoPosition);
motor.setPower(0.15);
spinCount++;
double ms = elapsedTime.milliseconds();
telemetry.addData("position", format(servoPosition));
telemetry.addData("#spin", format(spinCount));
telemetry.addData("ms/spin", format(ms / spinCount));
this.updateTelemetry(telemetry);
}
motor.setPower(0);
}
示例7: I2cDeviceClient
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
/**
* Instantiate an I2cDeviceClient instance in the indicated device with the indicated initial
* window of registers being read.
*
* @param context the OpMode within which the creation is taking place
* @param i2cDevice the device we are to be a client of
* @param i2cAddr8Bit its 8 bit i2cAddress
*/
public I2cDeviceClient(@Nullable OpMode context, II2cDevice i2cDevice, int i2cAddr8Bit, boolean closeOnOpModeStop) {
i2cDevice.setI2cAddr(i2cAddr8Bit);
this.i2cDevice = i2cDevice;
this.isArmed = false;
this.disarming = false;
this.callback = new Callback();
this.callbackThread = null;
this.callbackThreadOriginalPriority = 0; // not known
this.callbackThreadPriorityBoost = 0; // no boost
this.hardwareCycleCount = 0;
this.loggingEnabled = false;
this.loggingTag = String.format("%s:client(%s)", this.getClass().getSimpleName(), i2cDevice.getDeviceName());
this.timeSinceLastHeartbeat = new ElapsedTime();
this.timeSinceLastHeartbeat.reset();
this.msHeartbeatInterval = 0;
this.heartbeatAction = null;
this.heartbeatExecutor = null;
this.readCache = this.i2cDevice.getI2cReadCache();
this.readCacheLock = this.i2cDevice.getI2cReadCacheLock();
this.writeCache = this.i2cDevice.getI2cWriteCache();
this.writeCacheLock = this.i2cDevice.getI2cWriteCacheLock();
this.readWindow = null;
this.readWindowActuallyRead = null;
this.readWindowSentToController = null;
this.readWindowChanged = false;
this.readWindowSentToControllerInitialized = false;
this.nanoTimeReadCacheValid = 0;
this.readCacheStatus = READ_CACHE_STATUS.IDLE;
this.writeCacheStatus = WRITE_CACHE_STATUS.IDLE;
this.modeCacheStatus = MODE_CACHE_STATUS.IDLE;
if (closeOnOpModeStop)
RobotStateTransitionNotifier.register(context, this);
}
示例8: runOpMode
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
@Override public void runOpMode() {
/* we keep track of how long it's been since the OpMode was started, just
* to have some interesting data to show */
ElapsedTime opmodeRunTime = new ElapsedTime();
// We show the log in oldest-to-newest order, as that's better for poetry
telemetry.log().setDisplayOrder(Telemetry.Log.DisplayOrder.OLDEST_FIRST);
// We can control the number of lines shown in the log
telemetry.log().setCapacity(6);
// The interval between lines of poetry, in seconds
double sPoemInterval = 0.6;
/**
* Wait until we've been given the ok to go. For something to do, we emit the
* elapsed time as we sit here and wait. If we didn't want to do anything while
* we waited, we would just call {@link #waitForStart()}.
*/
while (!isStarted()) {
telemetry.addData("time", "%.1f seconds", opmodeRunTime.seconds());
telemetry.update();
idle();
}
// Ok, we've been given the ok to go
/**
* As an illustration, the first line on our telemetry display will display the battery voltage.
* The idea here is that it's expensive to compute the voltage (at least for purposes of illustration)
* so you don't want to do it unless the data is <em>actually</em> going to make it to the
* driver station (recall that telemetry transmission is throttled to reduce bandwidth use.
* Note that getBatteryVoltage() below returns 'Infinity' if there's no voltage sensor attached.
*
* @see Telemetry#getMsTransmissionInterval()
*/
telemetry.addData("voltage", "%.1f volts", new Func<Double>() {
@Override public Double value() {
return getBatteryVoltage();
}
});
// Reset to keep some timing stats for the post-'start' part of the opmode
opmodeRunTime.reset();
int loopCount = 1;
// Go go gadget robot!
while (opModeIsActive()) {
// Emit poetry if it's been a while
if (poemElapsed.seconds() > sPoemInterval) {
emitPoemLine();
}
// As an illustration, show some loop timing information
telemetry.addData("loop count", loopCount);
telemetry.addData("ms/loop", "%.3f ms", opmodeRunTime.milliseconds() / loopCount);
// Show joystick information as some other illustrative data
telemetry.addLine("left joystick | ")
.addData("x", gamepad1.left_stick_x)
.addData("y", gamepad1.left_stick_y);
telemetry.addLine("right joystick | ")
.addData("x", gamepad1.right_stick_x)
.addData("y", gamepad1.right_stick_y);
/**
* Transmit the telemetry to the driver station, subject to throttling.
* @see Telemetry#getMsTransmissionInterval()
*/
telemetry.update();
/** Update loop info and play nice with the rest of the {@link Thread}s in the system */
loopCount++;
}
}
示例9: runOpMode
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
@Override public void runOpMode() throws InterruptedException {
/* we keep track of how long it's been since the OpMode was started, just
* to have some interesting data to show */
ElapsedTime opmodeRunTime = new ElapsedTime();
// We show the log in oldest-to-newest order, as that's better for poetry
telemetry.log().setDisplayOrder(Telemetry.Log.DisplayOrder.OLDEST_FIRST);
// We can control the number of lines shown in the log
telemetry.log().setCapacity(6);
// The interval between lines of poetry, in seconds
double sPoemInterval = 0.6;
/**
* Wait until we've been given the ok to go. For something to do, we emit the
* elapsed time as we sit here and wait. If we didn't want to do anything while
* we waited, we would just call {@link #waitForStart()}.
*/
while (!isStarted()) {
telemetry.addData("time", "%.1f seconds", opmodeRunTime.seconds());
telemetry.update();
idle();
}
// Ok, we've been given the ok to go
/**
* As an illustration, the first line on our telemetry display will display the battery voltage.
* The idea here is that it's expensive to compute the voltage (at least for purposes of illustration)
* so you don't want to do it unless the data is <em>actually</em> going to make it to the
* driver station (recall that telemetry transmission is throttled to reduce bandwidth use.
* Note that getBatteryVoltage() below returns 'Infinity' if there's no voltage sensor attached.
*
* @see Telemetry#getMsTransmissionInterval()
*/
telemetry.addData("voltage", "%.1f volts", new Func<Double>() {
@Override public Double value() {
return getBatteryVoltage();
}
});
// Reset to keep some timing stats for the post-'start' part of the opmode
opmodeRunTime.reset();
int loopCount = 1;
// Go go gadget robot!
while (opModeIsActive()) {
// Emit poetry if it's been a while
if (poemElapsed.seconds() > sPoemInterval) {
emitPoemLine();
}
// As an illustration, show some loop timing information
telemetry.addData("loop count", loopCount);
telemetry.addData("ms/loop", "%.3f ms", opmodeRunTime.milliseconds() / loopCount);
// Show joystick information as some other illustrative data
telemetry.addLine("left joystick | ")
.addData("x", gamepad1.left_stick_x)
.addData("y", gamepad1.left_stick_y);
telemetry.addLine("right joystick | ")
.addData("x", gamepad1.right_stick_x)
.addData("y", gamepad1.right_stick_y);
/**
* Transmit the telemetry to the driver station, subject to throttling.
* @see Telemetry#getMsTransmissionInterval()
*/
telemetry.update();
/** Update loop info and play nice with the rest of the {@link Thread}s in the system */
loopCount++;
idle();
}
}
示例10: milliseconds
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
static public double milliseconds(ElapsedTime elapsed) {
return elapsed.time() * 1000.0;
}
示例11: runOpMode
import com.qualcomm.robotcore.util.ElapsedTime; //导入依赖的package包/类
@Override public void runOpMode() throws InterruptedException {
/* we keep track of how long it's been since the OpMode was started, just
* to have some interesting data to show */
ElapsedTime opmodeRunTime = new ElapsedTime();
// We show the log in oldest-to-newest order, as that's better for poetry
telemetry.log().setDisplayOrder(Telemetry.Log.DisplayOrder.OLDEST_FIRST);
// We can control the number of lines shown in the log
telemetry.log().setCapacity(6);
// The interval between lines of poetry, in seconds
double sPoemInterval = 0.6;
/**
* Wait until we've been given the ok to go. For something to do, we emit the
* elapsed time as we sit here and wait. If we didn't want to do anything while
* we waited, we would just call {@link #waitForStart()}.
*/
while (!isStarted()) {
telemetry.addData("time", "%.1f seconds", opmodeRunTime.seconds());
telemetry.update();
idle();
}
// Ok, we've been given the ok to go
/**
* As an illustration, the first line on our telemetry display will display the battery voltage.
* The idea here is that it's expensive to compute the voltage (at least for purposes of illustration)
* so you don't want to do it unless the data is <em>actually</em> going to make it to the
* driver station (recall that telemetry transmission is throttled to reduce bandwidth use.
* Note that getBatteryVoltage() below returns 'Infinity' if there's no voltage sensor attached.
*
* @see Telemetry#getMsTransmissionInterval()
*/
telemetry.addData("voltage", "%.1f volts", new Func<Double>() {
@Override public Double value() {
return getBatteryVoltage();
}
});
// Reset to keep some timing stats for the post-'start' part of the opmode
opmodeRunTime.reset();
int loopCount = 1;
// Go go gadget robot!
while (opModeIsActive()) {
// Emit poetry if it's been a while
if (poemElapsed.seconds() > sPoemInterval) {
emitPoemLine();
}
// As an illustration, show some loop timing information
telemetry.addData("loop count", loopCount);
telemetry.addData("ms/loop", "%.3f ms", opmodeRunTime.milliseconds() / loopCount);
// Show joystick information as some other illustrative data
telemetry.addLine("left joystick | ")
.addData("x", gamepad1.left_stick_x)
.addData("y", gamepad1.left_stick_y);
telemetry.addLine("right joystick | ")
.addData("x", gamepad1.right_stick_x)
.addData("y", gamepad1.right_stick_y);
/**
* Transmit the telemetry to the driver station, subject to throttling.
* @see Telemetry#getMsTransmissionInterval()
*/
telemetry.update();
/** Update loop info and play nice with the rest of the {@link Thread}s in the system */
loopCount++;
}
}