Skip to content

Commit 43cacdc

Browse files
#24: fix differential drive documentation + slides and flywheel control examples
* Update Differential Drive Documentation * Fix goal setting in Java portion of example usage of Slides * Fix goal setting method in Flywheels for the java portions * fixed java parts of setting motor power in flywheels section * fixed java parts for setting power in slides * fix kotlin syntax for initialization and setting motor power in slides * fix kotlin syntax for motor initialization and setting motor power
1 parent ed643cb commit 43cacdc

3 files changed

Lines changed: 63 additions & 126 deletions

File tree

src/control/examples/flywheels.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ We can easily do that by simply changing the `goal` of our `ControlSystem`:
4040

4141
```kotlin
4242
class FlywheelExample() : OpMode() {
43-
val flywheelMotor by lazy { hardwareMap.get(DcMotorEx.class, "flywheel") }
43+
val flywheelMotor by lazy { hardwareMap.get(DcMotorEx::class.java, "flywheel") }
4444
val controller = controlSystem {
4545
velPid(0.001, 0.0, 0.0)
4646
}
@@ -58,10 +58,10 @@ class FlywheelExample() : OpMode() {
5858
controller.goal = KineticState(0.0, 1000.0)
5959
}
6060

61-
flywheelMotor.power = controller.calculate(
62-
flywheelMotor.currentPosition,
63-
flywheelMotor.velocity
64-
)
61+
flywheelMotor.power = controller.calculate(KineticState(
62+
flywheelMotor.currentPosition.toDouble(),
63+
flywheelMotor.velocity
64+
))
6565
}
6666
}
6767
```
@@ -81,23 +81,23 @@ public class FlywheelExample extends OpMode {
8181
.velPid(0.001, 0.0, 0.0)
8282
.build();
8383

84-
controller.goal = new KineticState(0.0);
84+
controller.setGoal(new KineticState(0.0));
8585
}
8686

8787
@Override
8888
public void loop() {
8989
if (gamepad1.aWasPressed()) {
90-
controller.goal = new KineticState(0.0, 2000.0);
90+
controller.setGoal(new KineticState(2000.0));
9191
} else if (gamepad1.bWasPressed()) {
92-
controller.goal = new KineticState(0.0, 0.0);
92+
controller.setGoal(new KineticState(0.0));
9393
} else if (gamepad1.xWasPressed()) {
94-
controller.goal = new KineticState(0.0, 1000.0);
94+
controller.setGoal(new KineticState(1000.0));
9595
}
9696

97-
flywheelMotor.setPower(controller.calculate(
98-
flywheelMotor.getCurrentPosition(),
99-
flywheelMotor.getVelocity()
100-
));
97+
flywheelMotor.setPower(controller.calculate(new KineticState(
98+
flywheelMotor.getCurrentPosition(),
99+
flywheelMotor.getVelocity()))
100+
);
101101
}
102102
}
103103
```

src/control/examples/slides.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ We can easily do that by simply changing the `goal` of our `ControlSystem`:
4545

4646
```kotlin
4747
class SlideExample() : OpMode() {
48-
val slideMotor by lazy { hardwareMap.get(DcMotorEx.class, "slides") }
48+
val slideMotor by lazy { hardwareMap.get(DcMotorEx::class.java, "slides") }
4949
val controller = controlSystem {
5050
posPid(0.1, 0.0, 0.0)
5151
elevatorFF(0.04)
@@ -64,10 +64,10 @@ class SlideExample() : OpMode() {
6464
controller.goal = KineticState(500.0)
6565
}
6666

67-
slideMotor.power = controller.calculate(
68-
slideMotor.currentPosition,
67+
slideMotor.power = controller.calculate(KineticState(
68+
slideMotor.currentPosition.toDouble(),
6969
slideMotor.velocity
70-
)
70+
))
7171
}
7272
}
7373
```
@@ -88,23 +88,23 @@ public class SlideExample extends OpMode {
8888
.elevatorFF(0.04)
8989
.build();
9090

91-
controller.goal = new KineticState(0.0);
91+
controller.setGoal(new KineticState(0));
9292
}
9393

9494
@Override
9595
public void loop() {
9696
if (gamepad1.a) {
97-
controller.goal = new KineticState(1000.0);
97+
controller.setGoal(new KineticState(1000.0));
9898
} else if (gamepad1.b) {
99-
controller.goal = new KineticState(0.0);
99+
controller.setGoal(new KineticState(0.0));
100100
} else if (gamepad1.x) {
101-
controller.goal = new KineticState(500.0);
101+
controller.setGoal(new KineticState(500.0));
102102
}
103103

104-
slideMotor.setPower(controller.calculate(
105-
slideMotor.getCurrentPosition(),
106-
slideMotor.getVelocity()
107-
));
104+
slideMotor.setPower(controller.calculate(new KineticState(
105+
slideMotor.getCurrentPosition(),
106+
slideMotor.getVelocity()))
107+
);
108108
}
109109
}
110110
```

src/nextftc/hardware/drivetrain-commands/differential.md

Lines changed: 38 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -6,120 +6,37 @@
66
> [!TIP] INFO
77
> For a differential drive, there are two types of drive systems. You can use the tank and arcade control schemes with a differential drive.
88
>
9-
> 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.
9+
> 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.
1010
>
1111
> Tank drive uses a y-value input from the left and right sticks. The sticks control their respective side of the robot.
1212
1313
## Usage
1414

15-
First, you need to create your motors. Let's create variables for their names:
15+
First, you need to create your motors. Let's create variables for them:
1616

1717
:::tabs key:code
1818
== Kotlin
1919

2020
```kotlin
21-
val frontLeftName = "front_left"
22-
val frontRightName = "front_right"
23-
val backLeftName = "back_left"
24-
val backRightname = "back_right"
25-
```
26-
27-
== Java
28-
29-
```java
30-
public String frontLeftName = "front_left";
31-
public String frontRightName = "front_right";
32-
public String backLeftName = "back_left";
33-
public String backRightName = "back_right";
34-
```
35-
36-
:::
37-
38-
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.
39-
40-
:::tabs key:code
41-
== Kotlin
42-
43-
```kotlin
44-
lateinit var frontLeftMotor: MotorEx
45-
lateinit var frontRightMotor: MotorEx
46-
lateinit var backLeftMotor: MotorEx
47-
lateinit var backRightMotor: MotorEx
48-
49-
lateinit var leftMotors: MotorGroup
50-
lateinit var rightMtoors: MotorGroup
51-
```
52-
53-
== Java
54-
55-
```java
56-
public MotorEx frontLeftMotor;
57-
public MotorEx frontRightMotor;
58-
public MotorEx backLeftMotor;
59-
public MotorEx backRightMotor;
60-
61-
public MotorGroup leftMotors;
62-
public MotorGroup rightMotors;
63-
```
64-
65-
:::
21+
private val frontLeftMotor = MotorEx("front_left").breakMode().reversed()
22+
private val frontRightMotor = MotorEx("front_right").breakMode()
23+
private val backLeftMotor = MotorEx("back_left").breakMode().reversed()
24+
private val backRightMotor = MotorEx("back_right").breakMode()
6625

67-
Lastly, we'll create a variable for the command:
68-
69-
:::tabs key:code
70-
== Kotlin
71-
72-
```kotlin
73-
lateinit var driverControlled: Command
26+
private val leftMotors = MotorGroup(frontLeftMotor, backLeftMotor);
27+
private val rightMotors = MotorGroup(frontRightMotor, backRightMotor);
7428
```
7529

7630
== Java
7731

7832
```java
79-
public Command driverControlled;
80-
```
81-
82-
:::
33+
private MotorEx frontLeftMotor = new MotorEx("front_left").breakMode().reversed();
34+
private MotorEx frontRightMotor = new MotorEx("front_right").breakMode();
35+
private MotorEx backLeftMotor = new MotorEx("back_left").breakMode().reversed();
36+
private MotorEx backRightMotor = new MotorEx("back_right").breakMode();
8337

84-
Now, in the `onInit()` function, we will initialize all our variables:
85-
86-
:::tabs key:code
87-
== Kotlin
88-
89-
```kotlin
90-
frontLeftMotor = MotorEx(frontLeftName)
91-
backLeftMotor = MotorEx(backLeftName)
92-
backRightMotor = MotorEx(backRightName)
93-
frontRightMotor = MotorEx(frontRightName)
94-
95-
// Change your motor directions to suit your robot.
96-
frontLeftMotor.direction = DcMotorSimple.Direction.REVERSE
97-
backLeftMotor.direction = DcMotorSimple.Direction.REVERSE
98-
frontRightMotor.direction = DcMotorSimple.Direction.FORWARD
99-
backRightMotor.direction = DcMotorSimple.Direction.FORWARD
100-
101-
// Skip this if you are only using two motors.
102-
leftMotors = MotorGroup(frontLeftMotor, backLeftMotor)
103-
rightMotors = MotorGroup(frontRightMotor, backRightMotor)
104-
```
105-
106-
== Java
107-
108-
```java
109-
frontLeftMotor = new MotorEx(frontLeftName);
110-
backLeftMotor = new MotorEx(backLeftName);
111-
backRightMotor = new MotorEx(backRightName);
112-
frontRightMotor = new MotorEx(frontRightName);
113-
114-
// Change your motor directions to suit your robot.
115-
frontLeftMotor.setDirection(DcMotorSimple.Direction.REVERSE);
116-
backLeftMotor.setDirection(DcMotorSimple.Direction.REVERSE);
117-
frontRightMotor.setDirection(DcMotorSimple.Direction.FORWARD);
118-
backRightMotor.setDirection(DcMotorSimple.Direction.FORWARD);
119-
120-
// Skip this if you are only using two motors.
121-
leftMotors = new MotorGroup(frontLeftMotor, backLeftMotor);
122-
rightMotors = new MotorGroup(frontRightMotor, backRightMotor);
38+
private MotorGroup leftMotors = new MotorGroup(frontLeftMotor, backLeftMotor);
39+
private MotorGroup rightMotors = new MotorGroup(frontRightMotor, backRightMotor);
12340
```
12441

12542
:::
@@ -135,14 +52,24 @@ You can run it as a tank drive:
13552
== Kotlin
13653

13754
```kotlin
138-
driverControlled = DifferentialTankDriverControlled(leftMotors, rightMotors, gamepadManager.gamepad1)
55+
driverControlled = DifferentialTankDriverControlled(
56+
leftMotors,
57+
rightMotors,
58+
Gamepads.gamepad1.leftStickY,
59+
Gamepads.gamepad1.rightStickY
60+
)
13961
driverControlled()
14062
```
14163

14264
== Java
14365

14466
```java
145-
driverControlled = new DifferentialTankDriverControlled(leftMotors, rightMotors, gamepadManager.gamepad1);
67+
driverControlled = new DifferentialTankDriverControlled(
68+
leftMotors,
69+
rightMotors,
70+
Gamepads.gamepad1().leftStickY(),
71+
Gamepads.gamepad1().rightStickY()
72+
);
14673
driverControlled.schedule();
14774
```
14875

@@ -154,14 +81,24 @@ Or as an arcade drive:
15481
== Kotlin
15582

15683
```kotlin
157-
driverControlled = DifferentialArcadeDriverControlled(leftMotors, rightMotors, gamepadManager.gamepad1, false, imu)
84+
driverControlled = DifferentialArcadeDriverControlled(
85+
leftMotors,
86+
rightMotors,
87+
Gamepads.gamepad1.leftStickY,
88+
Gamepads.gamepad1.rightStickX
89+
)
15890
driverControlled()
15991
```
16092

16193
== Java
16294

16395
```java
164-
driverControlled = new DifferentialArcadeDriverControlled(leftMotors, rightMotors, gamepadManager.gamepad1, false, imu);
96+
driverControlled = new DifferentialArcadeDriverControlled(
97+
leftMotors,
98+
rightMotors,
99+
Gamepads.gamepad1().leftStickY(),
100+
Gamepads.gamepad1().rightStickX()
101+
);
165102
driverControlled.schedule();
166103
```
167104

0 commit comments

Comments
 (0)