diff --git a/src/control/examples/flywheels.md b/src/control/examples/flywheels.md index fdd79e0..040759f 100644 --- a/src/control/examples/flywheels.md +++ b/src/control/examples/flywheels.md @@ -40,7 +40,7 @@ We can easily do that by simply changing the `goal` of our `ControlSystem`: ```kotlin class FlywheelExample() : OpMode() { - val flywheelMotor by lazy { hardwareMap.get(DcMotorEx.class, "flywheel") } + val flywheelMotor by lazy { hardwareMap.get(DcMotorEx::class.java, "flywheel") } val controller = controlSystem { velPid(0.001, 0.0, 0.0) } @@ -58,10 +58,10 @@ class FlywheelExample() : OpMode() { controller.goal = KineticState(0.0, 1000.0) } - flywheelMotor.power = controller.calculate( - flywheelMotor.currentPosition, - flywheelMotor.velocity - ) + flywheelMotor.power = controller.calculate(KineticState( + flywheelMotor.currentPosition.toDouble(), + flywheelMotor.velocity + )) } } ``` @@ -81,23 +81,23 @@ public class FlywheelExample extends OpMode { .velPid(0.001, 0.0, 0.0) .build(); - controller.goal = new KineticState(0.0); + controller.setGoal(new KineticState(0.0)); } @Override public void loop() { if (gamepad1.aWasPressed()) { - controller.goal = new KineticState(0.0, 2000.0); + controller.setGoal(new KineticState(2000.0)); } else if (gamepad1.bWasPressed()) { - controller.goal = new KineticState(0.0, 0.0); + controller.setGoal(new KineticState(0.0)); } else if (gamepad1.xWasPressed()) { - controller.goal = new KineticState(0.0, 1000.0); + controller.setGoal(new KineticState(1000.0)); } - flywheelMotor.setPower(controller.calculate( - flywheelMotor.getCurrentPosition(), - flywheelMotor.getVelocity() - )); + flywheelMotor.setPower(controller.calculate(new KineticState( + flywheelMotor.getCurrentPosition(), + flywheelMotor.getVelocity())) + ); } } ``` diff --git a/src/control/examples/slides.md b/src/control/examples/slides.md index d40fb90..154e9d7 100644 --- a/src/control/examples/slides.md +++ b/src/control/examples/slides.md @@ -45,7 +45,7 @@ We can easily do that by simply changing the `goal` of our `ControlSystem`: ```kotlin class SlideExample() : OpMode() { - val slideMotor by lazy { hardwareMap.get(DcMotorEx.class, "slides") } + val slideMotor by lazy { hardwareMap.get(DcMotorEx::class.java, "slides") } val controller = controlSystem { posPid(0.1, 0.0, 0.0) elevatorFF(0.04) @@ -64,10 +64,10 @@ class SlideExample() : OpMode() { controller.goal = KineticState(500.0) } - slideMotor.power = controller.calculate( - slideMotor.currentPosition, + slideMotor.power = controller.calculate(KineticState( + slideMotor.currentPosition.toDouble(), slideMotor.velocity - ) + )) } } ``` @@ -88,23 +88,23 @@ public class SlideExample extends OpMode { .elevatorFF(0.04) .build(); - controller.goal = new KineticState(0.0); + controller.setGoal(new KineticState(0)); } @Override public void loop() { if (gamepad1.a) { - controller.goal = new KineticState(1000.0); + controller.setGoal(new KineticState(1000.0)); } else if (gamepad1.b) { - controller.goal = new KineticState(0.0); + controller.setGoal(new KineticState(0.0)); } else if (gamepad1.x) { - controller.goal = new KineticState(500.0); + controller.setGoal(new KineticState(500.0)); } - slideMotor.setPower(controller.calculate( - slideMotor.getCurrentPosition(), - slideMotor.getVelocity() - )); + slideMotor.setPower(controller.calculate(new KineticState( + slideMotor.getCurrentPosition(), + slideMotor.getVelocity())) + ); } } ``` diff --git a/src/nextftc/hardware/drivetrain-commands/differential.md b/src/nextftc/hardware/drivetrain-commands/differential.md index 00b9453..84d1c2b 100644 --- a/src/nextftc/hardware/drivetrain-commands/differential.md +++ b/src/nextftc/hardware/drivetrain-commands/differential.md @@ -6,120 +6,37 @@ > [!TIP] INFO > For a differential drive, there are two types of drive systems. You can use the tank and arcade control schemes with a differential drive. > -> Arcade drive use a y-value input from the controller and a value from the turn stick. We know that when the turn stick is pushed left, the right side should move forward and the left side should move backwards. Therefore, since pushing the turn stick to the left returns a negative value, it should be added to the left speed and subtracted from the right speed. +> Arcade drive uses a y-value input from the controller and a value from the turn stick. We know that when the turn stick is pushed left, the right side should move forward and the left side should move backwards. Therefore, since pushing the turn stick to the left returns a negative value, it should be added to the left speed and subtracted from the right speed. > > Tank drive uses a y-value input from the left and right sticks. The sticks control their respective side of the robot. ## Usage -First, you need to create your motors. Let's create variables for their names: +First, you need to create your motors. Let's create variables for them: :::tabs key:code == Kotlin ```kotlin -val frontLeftName = "front_left" -val frontRightName = "front_right" -val backLeftName = "back_left" -val backRightname = "back_right" -``` - -== Java - -```java -public String frontLeftName = "front_left"; -public String frontRightName = "front_right"; -public String backLeftName = "back_left"; -public String backRightName = "back_right"; -``` - -::: - -Next, we'll create variables for the motors and motor groups for each of the sides. If you only have one motor each side, you can skip creating the motor groups. - -:::tabs key:code -== Kotlin - -```kotlin -lateinit var frontLeftMotor: MotorEx -lateinit var frontRightMotor: MotorEx -lateinit var backLeftMotor: MotorEx -lateinit var backRightMotor: MotorEx - -lateinit var leftMotors: MotorGroup -lateinit var rightMtoors: MotorGroup -``` - -== Java - -```java -public MotorEx frontLeftMotor; -public MotorEx frontRightMotor; -public MotorEx backLeftMotor; -public MotorEx backRightMotor; - -public MotorGroup leftMotors; -public MotorGroup rightMotors; -``` - -::: +private val frontLeftMotor = MotorEx("front_left").breakMode().reversed() +private val frontRightMotor = MotorEx("front_right").breakMode() +private val backLeftMotor = MotorEx("back_left").breakMode().reversed() +private val backRightMotor = MotorEx("back_right").breakMode() -Lastly, we'll create a variable for the command: - -:::tabs key:code -== Kotlin - -```kotlin -lateinit var driverControlled: Command +private val leftMotors = MotorGroup(frontLeftMotor, backLeftMotor); +private val rightMotors = MotorGroup(frontRightMotor, backRightMotor); ``` == Java ```java -public Command driverControlled; -``` - -::: +private MotorEx frontLeftMotor = new MotorEx("front_left").breakMode().reversed(); +private MotorEx frontRightMotor = new MotorEx("front_right").breakMode(); +private MotorEx backLeftMotor = new MotorEx("back_left").breakMode().reversed(); +private MotorEx backRightMotor = new MotorEx("back_right").breakMode(); -Now, in the `onInit()` function, we will initialize all our variables: - -:::tabs key:code -== Kotlin - -```kotlin -frontLeftMotor = MotorEx(frontLeftName) -backLeftMotor = MotorEx(backLeftName) -backRightMotor = MotorEx(backRightName) -frontRightMotor = MotorEx(frontRightName) - -// Change your motor directions to suit your robot. -frontLeftMotor.direction = DcMotorSimple.Direction.REVERSE -backLeftMotor.direction = DcMotorSimple.Direction.REVERSE -frontRightMotor.direction = DcMotorSimple.Direction.FORWARD -backRightMotor.direction = DcMotorSimple.Direction.FORWARD - -// Skip this if you are only using two motors. -leftMotors = MotorGroup(frontLeftMotor, backLeftMotor) -rightMotors = MotorGroup(frontRightMotor, backRightMotor) -``` - -== Java - -```java -frontLeftMotor = new MotorEx(frontLeftName); -backLeftMotor = new MotorEx(backLeftName); -backRightMotor = new MotorEx(backRightName); -frontRightMotor = new MotorEx(frontRightName); - -// Change your motor directions to suit your robot. -frontLeftMotor.setDirection(DcMotorSimple.Direction.REVERSE); -backLeftMotor.setDirection(DcMotorSimple.Direction.REVERSE); -frontRightMotor.setDirection(DcMotorSimple.Direction.FORWARD); -backRightMotor.setDirection(DcMotorSimple.Direction.FORWARD); - -// Skip this if you are only using two motors. -leftMotors = new MotorGroup(frontLeftMotor, backLeftMotor); -rightMotors = new MotorGroup(frontRightMotor, backRightMotor); +private MotorGroup leftMotors = new MotorGroup(frontLeftMotor, backLeftMotor); +private MotorGroup rightMotors = new MotorGroup(frontRightMotor, backRightMotor); ``` ::: @@ -135,14 +52,24 @@ You can run it as a tank drive: == Kotlin ```kotlin -driverControlled = DifferentialTankDriverControlled(leftMotors, rightMotors, gamepadManager.gamepad1) +driverControlled = DifferentialTankDriverControlled( + leftMotors, + rightMotors, + Gamepads.gamepad1.leftStickY, + Gamepads.gamepad1.rightStickY +) driverControlled() ``` == Java ```java -driverControlled = new DifferentialTankDriverControlled(leftMotors, rightMotors, gamepadManager.gamepad1); +driverControlled = new DifferentialTankDriverControlled( + leftMotors, + rightMotors, + Gamepads.gamepad1().leftStickY(), + Gamepads.gamepad1().rightStickY() +); driverControlled.schedule(); ``` @@ -154,14 +81,24 @@ Or as an arcade drive: == Kotlin ```kotlin -driverControlled = DifferentialArcadeDriverControlled(leftMotors, rightMotors, gamepadManager.gamepad1, false, imu) +driverControlled = DifferentialArcadeDriverControlled( + leftMotors, + rightMotors, + Gamepads.gamepad1.leftStickY, + Gamepads.gamepad1.rightStickX +) driverControlled() ``` == Java ```java -driverControlled = new DifferentialArcadeDriverControlled(leftMotors, rightMotors, gamepadManager.gamepad1, false, imu); +driverControlled = new DifferentialArcadeDriverControlled( + leftMotors, + rightMotors, + Gamepads.gamepad1().leftStickY(), + Gamepads.gamepad1().rightStickX() +); driverControlled.schedule(); ```