Skip to content

Commit

Permalink
imu + gp
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJeffreyKuo committed Feb 20, 2024
1 parent ea5a19d commit 3bbde97
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pages/user-guides/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"reading-hardware": "Reading Hardware",
"linearopmode": "OpMode",
"mecanum-teleop": "Mecanum TeleOp",
"imu": "Reading IMU",
"gamepad": "Gamepad",
"pid" : "PID Controller"
}
46 changes: 46 additions & 0 deletions pages/user-guides/gamepad.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Callout } from "nextra/components";

# Gamepad

There are two gamepads/drivers, `gamepad1` and `gamepad2`. We designate gamepad1`to the driver and`gamepad2` to subsystems.

## Gamepad Usage

```java
if (gamepad1.a) {
servo.setPosition(servo.getPosition()+0.1);
}
else if (gamepad1.b) {
servo.setPosition(servo.getPosition()-0.1);
}
```

Handling boolean simply involves putting the gamepad boolean under an if statement inside the main loop. Note that the methods inside the if statement will continously run while the button is being held down, unless we use a rising edge detector.

```java
double y = -gamepad1.left_stick_y;
motor.setPower(y);
```

Float inputs are directly set to control hardware.

## Rising Edge Detector

A commonly used technique is a rising edge detector. It allows code to be run only once upon the initial button press rather than continuously while the button is held down. It verifies the button was not pressed in the previous loop but is pressed currently.

```java
// Usage
if (currentGamepad1.a && !previousGamepad1.a) {
servo.setPosition(servo.getPosition() + 0.1);
}

// Rising Edge Detector method
public boolean risingEdgeDetect(boolean current, boolean previous) {
return current && !previous;
}
```

<Callout type="info" emoji="ℹ️">
This is easily achieved through
[FTCLib](https://docs.ftclib.org/ftclib/v/v2.0.0/features/gamepad-extensions#buttonreader).
</Callout>
24 changes: 24 additions & 0 deletions pages/user-guides/imu.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# IMU

## Orientation Parameters

Initializing the IMU is a little different from normal hardware because you need to set the orientation of the IMU/Control Hub. You can read the FTC doc page on the IMU interface and the orientation parameters [here](https://ftc-docs.firstinspires.org/en/latest/programming_resources/imu/imu.html).

```java
imu = hardwareMap.get(IMU.class, "imu");

IMU.Parameters parameters = new IMU.Parameters(new RevHubOrientationOnRobot(
RevHubOrientationOnRobot.LogoFacingDirection.UP,
RevHubOrientationOnRobot.UsbFacingDirection.FORWARD));
imu.initialize(parameters);
```

## Reading IMU

For all axes, IMU angles are provided in the range of -Pi to +Pi radians which is -180 to +180 degrees.

```java
double Yaw = imu.getRobotYawPitchRollAngles().getYaw(AngleUnit.RADIANS);
double Pitch = imu.getRobotYawPitchRollAngles().getPitch(AngleUnit.RADIANS);
double Roll = imu.getRobotYawPitchRollAngles().getRoll(AngleUnit.RADIANS);
```

0 comments on commit 3bbde97

Please sign in to comment.