本文整理汇总了Java中com.qualcomm.robotcore.hardware.GyroSensor类的典型用法代码示例。如果您正苦于以下问题:Java GyroSensor类的具体用法?Java GyroSensor怎么用?Java GyroSensor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GyroSensor类属于com.qualcomm.robotcore.hardware包,在下文中一共展示了GyroSensor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calibrateGyro
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
/**
* @param stateName the name of the state
* @param nextStateName the name of the next state
* @param gyro the gyro sensor to be calibrated
* @return the created State
* @see GyroSensor
*/
public static State calibrateGyro(StateName stateName, final StateName nextStateName, final GyroSensor gyro) {
gyro.calibrate();
return new BasicAbstractState(stateName) {
@Override
public void init() {
}
@Override
public boolean isDone() {
return !gyro.isCalibrating();
}
@Override
public StateName getNextStateName() {
return nextStateName;
}
};
}
示例2: gyroStabilize
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
public static State gyroStabilize(StateName stateName, StateName nextStateName, final MecanumControl mecanumControl, final GyroSensor gyro, final Angle orientation, Angle tolerance) {
List<Transition> transitions = ImmutableList.of(
new Transition(EVEndConditions.gyroCloseTo(gyro, orientation, tolerance), nextStateName)
);
return new AbstractState(stateName, transitions) {
@Override
public void init() {
mecanumControl.setTranslationControl(TranslationControls.ZERO);
mecanumControl.setRotationControl(RotationControls.gyro(gyro, orientation));
}
@Override
public void run() {
}
@Override
public void dispose() {
mecanumControl.stop();
}
};
}
示例3: gyroCloseTo
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
/**
* wait until the gyro heading is close to a target value
*
* @param gyro the gyro sensor
* @param target the target value
* @param tolerance the accepted tolerance to be considered "close to"
* @return the created EndCondition
* @see GyroSensor
*/
public static EndCondition gyroCloseTo(final GyroSensor gyro, Angle target, final Angle tolerance) {
final Vector2D targetVector = new Vector2D(1, target);
return new EndCondition() {
@Override
public void init() {
}
@Override
public boolean isDone() {
Vector2D gyroVector = new Vector2D(1, Angle.fromDegrees(gyro.getHeading()));
Angle separation = Vector2D.signedAngularSeparation(targetVector, gyroVector);
return Math.abs(separation.radians()) <= tolerance.radians();
}
};
}
示例4: gyroCloseToRelative
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
/**
* wait until the gyro heading is close to a target value relative to the starting heading
*
* @param gyro the gyro sensor
* @param target the target value relative to the starting heading
* @param tolerance the accepted tolerance to be considered "close to"
* @return the created State
* @see GyroSensor
*/
public static EndCondition gyroCloseToRelative(final GyroSensor gyro, Angle target, final Angle tolerance) {
final Vector2D targetVector = new Vector2D(1, target);
return new EndCondition() {
double gyroInit = 0;
@Override
public void init() {
gyroInit = gyro.getHeading();
}
@Override
public boolean isDone() {
Vector2D gyroVector = new Vector2D(1, Angle.fromDegrees(gyro.getHeading() - gyroInit));
Angle separation = Vector2D.signedAngularSeparation(targetVector, gyroVector);
return Math.abs(separation.degrees()) <= tolerance.degrees();
}
};
}
示例5: displayGyroIsCalibrated
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
/**
* Display whether or not a gyro sensor is calibrated on the telemetry screen
*
* @param gyro the gyro sensor
*/
public static void displayGyroIsCalibrated(GyroSensor gyro) {
if (gyro.isCalibrating()) {
telemetry.addData("Gyro state", "CALIBRATING");
} else {
telemetry.addData("Gyro state", "ready");
}
}
示例6: mecanumDrive
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
/**
* drive using the mecanum wheels
* travels for a certain amount of time defined by the robots speed and a desired distance
*
* @param stateName the name of the state
* @param nextStateName the next state to go to
* @param distance the distance to travel
* @param mecanumControl the mecanum wheels
* @param gyro the gyro sensor
* @param velocity the velocity to drive at
* @param direction the direction to drive
* @param orientation the angle to rotate to
* @param maxAngularSpeed the max speed to rotate to that angle
* @return the created State
* @see MecanumControl
* @see GyroSensor
* @see Distance
*/
public static State mecanumDrive(StateName stateName, final StateName nextStateName, Distance distance, final MecanumControl mecanumControl, final GyroSensor gyro, final double velocity, final Angle direction, final Angle orientation, final Angle tolerance, final double maxAngularSpeed) {
mecanumControl.setDriveMode(MecanumMotors.MecanumDriveMode.NORMALIZED);
double speedMetersPerMillisecond = mecanumControl.getMaxRobotSpeed().metersPerMillisecond() * velocity;
final double durationMillis = Math.abs(distance.meters() / speedMetersPerMillisecond);
final EndCondition gyroEC = EVEndConditions.gyroCloseTo(gyro, orientation, tolerance);
return new BasicAbstractState(stateName) {
long startTime = 0;
@Override
public void init() {
mecanumControl.setControl(
TranslationControls.constant(velocity, direction),
RotationControls.gyro(gyro, orientation, maxAngularSpeed)
);
startTime = System.currentTimeMillis();
}
@Override
public boolean isDone() {
long now = System.currentTimeMillis();
long elapsedTime = now - startTime;
if (elapsedTime >= durationMillis) {
mecanumControl.setTranslationControl(TranslationControls.ZERO);
return gyroEC.isDone();
}
return false;
}
@Override
public StateName getNextStateName() {
mecanumControl.stop();
return nextStateName;
}
};
}
示例7: LineUpControl
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
public LineUpControl(LineSensorArray lineSensorArray, Button buttonToLineUpWith, DistanceSensor distanceSensor, Distance distanceTarget, GyroSensor gyro, Angle targetHeading) {
this.lineSensorArray = lineSensorArray;
this.buttonToLineUpWith = buttonToLineUpWith;
this.distanceSensor = distanceSensor;
this.distanceTarget = distanceTarget;
this.gyro = gyro;
this.targetHeadingVector = new Vector2D(1, targetHeading);
}
示例8: createDeviceMaps
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
/**
* Move the propriety {@link HardwareMap.DeviceMapping} to our {@link DeviceMap} for our
* internal use
*/
private void createDeviceMaps() {
fullMap.checkedPut(DcMotorController.class, new DeviceMap<>(basicMap.dcMotorController));
fullMap.checkedPut(DcMotor.class, new DeviceMap<>(basicMap.dcMotor));
fullMap.checkedPut(ServoController.class, new DeviceMap<>(basicMap.servoController));
fullMap.checkedPut(Servo.class, new DeviceMap<>(basicMap.servo));
fullMap.checkedPut(LegacyModule.class, new DeviceMap<>(basicMap.legacyModule));
fullMap.checkedPut(TouchSensorMultiplexer.class, new DeviceMap<>(basicMap.touchSensorMultiplexer));
fullMap.checkedPut(DeviceInterfaceModule.class, new DeviceMap<>(basicMap.deviceInterfaceModule));
fullMap.checkedPut(AnalogInput.class, new DeviceMap<>(basicMap.analogInput));
fullMap.checkedPut(DigitalChannel.class, new DeviceMap<>(basicMap.digitalChannel));
fullMap.checkedPut(OpticalDistanceSensor.class, new DeviceMap<>(basicMap.opticalDistanceSensor));
fullMap.checkedPut(TouchSensor.class, new DeviceMap<>(basicMap.touchSensor));
fullMap.checkedPut(PWMOutput.class, new DeviceMap<>(basicMap.pwmOutput));
fullMap.checkedPut(I2cDevice.class, new DeviceMap<>(basicMap.i2cDevice));
fullMap.checkedPut(AnalogOutput.class, new DeviceMap<>(basicMap.analogOutput));
fullMap.checkedPut(ColorSensor.class, new DeviceMap<>(basicMap.colorSensor));
fullMap.checkedPut(LED.class, new DeviceMap<>(basicMap.led));
fullMap.checkedPut(AccelerationSensor.class, new DeviceMap<>(basicMap.accelerationSensor));
fullMap.checkedPut(CompassSensor.class, new DeviceMap<>(basicMap.compassSensor));
fullMap.checkedPut(GyroSensor.class, new DeviceMap<>(basicMap.gyroSensor));
fullMap.checkedPut(IrSeekerSensor.class, new DeviceMap<>(basicMap.irSeekerSensor));
fullMap.checkedPut(LightSensor.class, new DeviceMap<>(basicMap.lightSensor));
fullMap.checkedPut(UltrasonicSensor.class, new DeviceMap<>(basicMap.ultrasonicSensor));
fullMap.checkedPut(VoltageSensor.class, new DeviceMap<>(basicMap.voltageSensor));
LinkedHashMultimap<DcMotorController, DcMotor> multimap = LinkedHashMultimap.create();
for (DcMotor motor : dcMotors()) {
multimap.put(motor.getController(), motor);
}
}
示例9: update
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
public void update(GyroSensor g) {
//update raw gyro rotation
gyroSensor = g;
//store new values
velPrevious = velCurr;
velCurr = getRotation();
dt = timers.getClockValue(clockName, TimeUnit.SECONDS);
heading += (velPrevious + velCurr) * .5D * dt;
//prepare for next values
timers.resetClock(clockName);
}
示例10: runOpMode
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
GyroSensor sensorGyro;
int xVal, yVal, zVal = 0;
int heading = 0;
// write some device information (connection info, name and type)
// to the log file.
hardwareMap.logDevices();
// get a reference to our GyroSensor object.
sensorGyro = hardwareMap.gyroSensor.get("gyro");
// calibrate the gyro.
sensorGyro.calibrate();
// wait for the start button to be pressed.
waitForStart();
// make sure the gyro is calibrated.
while (sensorGyro.isCalibrating()) {
Thread.sleep(50);
}
while (opModeIsActive()) {
// if the A and B buttons are pressed, reset Z heading.
if(gamepad1.a && gamepad1.b) {
// reset heading.
sensorGyro.resetZAxisIntegrator();
}
// get the x, y, and z values (rate of change of angle).
xVal = sensorGyro.rawX();
yVal = sensorGyro.rawY();
zVal = sensorGyro.rawZ();
// get the heading info.
// the Modern Robotics' gyro sensor keeps
// track of the current heading for the Z axis only.
heading = sensorGyro.getHeading();
telemetry.addData("1. x", String.format("%03d", xVal));
telemetry.addData("2. y", String.format("%03d", yVal));
telemetry.addData("3. z", String.format("%03d", zVal));
telemetry.addData("4. h", String.format("%03d", heading));
Thread.sleep(100);
}
}
示例11: beaconLineUp
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
/**
* Line up with the beacon using the line sensor array and distance sensor
*
* @param stateName the name of the state
* @param successState the state to go to if the line up succeeds
* @param failState the state to go to if the line up fails
* @param mecanumControl the mecanum wheels
* @param direction the direction angle to face
* @param gyro the gyro to use for rotation stabilization
* @param distSensor the distance sensor to detect distance from the beacon
* @param lineSensorArray the line sensor array to line up sideways with the line
* @param teamColor the team you are on and ...
* @param beaconColorResult ... the beacon configuration to decide which button to line up with
* @param distance the distance from the beacon to line up to
* @return the created State
* @see LineUpControl
*/
public static State beaconLineUp(StateName stateName, final StateName successState, final StateName failState, final MecanumControl mecanumControl, final Angle direction, final GyroSensor gyro, final DistanceSensor distSensor, final LineSensorArray lineSensorArray, TeamColor teamColor, final ResultReceiver<BeaconColorResult> beaconColorResult, final Distance distance) {
// final EndCondition distEndCondition = EVEndConditions.distanceSensorLess(distSensor, Distance.add(distance, Distance.fromInches(4)));
final EndCondition distEndCondition = EVEndConditions.distanceSensorLess(distSensor, distance);
final EndCondition gyroEndCondition = EVEndConditions.gyroCloseTo(gyro, direction, 2);
final BeaconColorResult.BeaconColor myColor = BeaconColorResult.BeaconColor.fromTeamColor(teamColor);
final BeaconColorResult.BeaconColor opponentColor = BeaconColorResult.BeaconColor.fromTeamColor(teamColor.opposite());
return new BasicAbstractState(stateName) {
private boolean success;
LineUpControl.Button buttonToLineUpWith;
@Override
public void init() {
buttonToLineUpWith = null;
if (beaconColorResult.isReady()) {
BeaconColorResult result = beaconColorResult.getValue();
BeaconColorResult.BeaconColor leftColor = result.getLeftColor();
BeaconColorResult.BeaconColor rightColor = result.getRightColor();
if (leftColor == myColor && rightColor == opponentColor) {
buttonToLineUpWith = LineUpControl.Button.LEFT;
}
if (leftColor == opponentColor && rightColor == myColor) {
buttonToLineUpWith = LineUpControl.Button.RIGHT;
}
}
success = buttonToLineUpWith != null;
LineUpControl lineUpControl = new LineUpControl(lineSensorArray, buttonToLineUpWith, distSensor, distance, gyro, direction);
mecanumControl.setTranslationControl(lineUpControl);
mecanumControl.setRotationControl(lineUpControl);
distEndCondition.init();
gyroEndCondition.init();
}
@Override
public boolean isDone() {
if (!mecanumControl.translationWorked()) {
success = false;
}
return !success || distEndCondition.isDone();
}
@Override
public StateName getNextStateName() {
mecanumControl.stop();
return success ? successState : failState;
}
};
}
示例12: mapNxtGyroSensor
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
private void mapNxtGyroSensor(HardwareMap map, DeviceManager deviceMgr, LegacyModule legacyModule, DeviceConfiguration devConf) {
if (!devConf.isEnabled()) return;
GyroSensor gyro = deviceMgr.createNxtGyroSensor(legacyModule, devConf.getPort());
map.gyroSensor.put(devConf.getName(), gyro);
}
示例13: mapModernRoboticsGyro
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
private void mapModernRoboticsGyro(HardwareMap map, DeviceManager deviceMgr, I2cController i2cController, DeviceConfiguration devConf) {
if (!devConf.isEnabled()) return;
GyroSensor gyroSensor = deviceMgr.createModernRoboticsI2cGyroSensor(i2cController, devConf.getPort());
map.gyroSensor.put(devConf.getName(), gyroSensor);
}
示例14: runOpMode
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
@Override
public void runOpMode() throws InterruptedException {
GyroSensor sensorGyro;
int xVal, yVal, zVal = 0;
int heading = 0;
// write some device information (connection info, name and type)
// to the log file.
hardwareMap.logDevices();
// get a reference to our GyroSensor object.
sensorGyro = hardwareMap.gyroSensor.get("gyro");
// calibrate the gyro.
sensorGyro.calibrate();
// wait for the start button to be pressed.
waitForStart();
// make sure the gyro is calibrated.
while (sensorGyro.isCalibrating()) {
Thread.sleep(50);
}
while (opModeIsActive()) {
// if the A and B buttons are pressed, reset Z heading.
if (gamepad1.a && gamepad1.b) {
// reset heading.
sensorGyro.resetZAxisIntegrator();
}
// get the x, y, and z values (rate of change of angle).
xVal = sensorGyro.rawX();
yVal = sensorGyro.rawY();
zVal = sensorGyro.rawZ();
// get the heading info.
// the Modern Robotics' gyro sensor keeps
// track of the current heading for the Z axis only.
heading = sensorGyro.getHeading();
telemetry.addData("1. x", String.format("%03d", xVal));
telemetry.addData("2. y", String.format("%03d", yVal));
telemetry.addData("3. z", String.format("%03d", zVal));
telemetry.addData("4. h", String.format("%03d", heading));
Thread.sleep(100);
}
}
示例15: Gyroscope
import com.qualcomm.robotcore.hardware.GyroSensor; //导入依赖的package包/类
public Gyroscope(GyroSensor g) {
timers = new Timers();
timers.startClock(clockName);
gyroSensor = g;
reset();
}