diff --git a/pages/user-guides/_meta.json b/pages/user-guides/_meta.json index 91f7724..8f931ac 100644 --- a/pages/user-guides/_meta.json +++ b/pages/user-guides/_meta.json @@ -2,5 +2,7 @@ "reading-hardware": "Reading Hardware", "linearopmode": "OpMode", "mecanum-teleop": "Mecanum TeleOp", + "imu": "Reading IMU", + "gamepad": "Gamepad", "pid" : "PID Controller" } \ No newline at end of file diff --git a/pages/user-guides/gamepad.mdx b/pages/user-guides/gamepad.mdx new file mode 100644 index 0000000..042ac98 --- /dev/null +++ b/pages/user-guides/gamepad.mdx @@ -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; +} +``` + + + This is easily achieved through + [FTCLib](https://docs.ftclib.org/ftclib/v/v2.0.0/features/gamepad-extensions#buttonreader). + diff --git a/pages/user-guides/imu.mdx b/pages/user-guides/imu.mdx new file mode 100644 index 0000000..232dc8c --- /dev/null +++ b/pages/user-guides/imu.mdx @@ -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); +```