Skip to content

Commit 3042d21

Browse files
committed
fixes for links and additions
1 parent 09196db commit 3042d21

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# OpModeRegistrars
2+
3+
OpModeRegistrars are a great way to remove the ```@Autonomous``` or ```@TeleOp``` tags from your OpModes.
4+
This works by sending in the OpMode to the registrar, which then builds and registers your opMode for you.
5+
6+
## Code
7+
8+
```java
9+
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
10+
import com.qualcomm.robotcore.eventloop.opmode.OpModeManager;
11+
import com.qualcomm.robotcore.eventloop.opmode.OpModeRegistrar;
12+
13+
import org.firstinspires.ftc.robotcore.internal.opmode.OpModeMeta;
14+
15+
public final class AutonomousRegistrar {
16+
private AutonomousRegistrar() {}
17+
18+
private static OpModeMeta metaForClass(Class<? extends OpMode> cls) {
19+
return new OpModeMeta.Builder()
20+
.setName(cls.getSimpleName())
21+
.setGroup("Autonomous")
22+
.setFlavor(OpModeMeta.Flavor.AUTONOMOUS) // can be changed to TELEOP
23+
.build();
24+
}
25+
26+
@OpModeRegistrar
27+
public static void register(OpModeManager manager) {
28+
manager.register(metaForClass(Auto1.class), new Auto1());
29+
manager.register(metaForClass(Auto2.class), new Auto2());
30+
}
31+
}
32+
```
33+
34+
Essentially, it just allows you to remove the ```@Autonomous``` or ```@TeleOp``` tags from your OpModes and instead use a registrar to register them, providing one central spot all of them are registered and stored.
35+
As well as this, if you start using constructors for your teleOp, ex getting Alliance color, this is an easy way because you can change it to include Alliance color as a param. While this is possible, it is not recommended as if you have to change back, it will not allow initialization.
36+
37+
You can use this [website](https://gramgra07.github.io/OpModeRegistrarCreator/) that I made to generate code for you.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ServoStateMachines
2+
3+
## Overview
4+
5+
State machines for servos are a great way to handle servo operation. It allows you to send commands and then operate the servo based on those commands.
6+
7+
## Code
8+
9+
```java
10+
public enum servo1State {UP, DOWN, MID, IDLE}
11+
12+
private servo1State servo1StateVar = servo1State.IDLE;
13+
14+
public void setservo1StateUP() {
15+
servo1StateVar = servo1State.UP;
16+
}
17+
18+
public void setservo1StateDOWN() {
19+
servo1StateVar = servo1State.DOWN;
20+
}
21+
22+
public void setservo1StateMID() {
23+
servo1StateVar = servo1State.MID;
24+
}
25+
26+
public void setservo1StateIDLE() {
27+
servo1StateVar = servo1State.IDLE;
28+
}
29+
30+
switch (servo1StateVar) { // needs to be updated every loop
31+
case UP:
32+
// Add code here
33+
break;
34+
case DOWN:
35+
// Add code here
36+
break;
37+
case MID:
38+
// Add code here
39+
break;
40+
case IDLE:
41+
// Add code here
42+
break;
43+
}
44+
```
45+
This prevents the need for multiple if statements and makes the code cleaner and easier to read.
46+
To send a command, you would use the code ```setservo1StateUP();``` to set the servo to the UP state.
47+
This works because you send a command, and then when it gets updated, it will run the code to set the servo to the correct point using enums and a switch case.
48+
49+
**Do not** forget the break, or it will try to do all in one.
50+
51+
An easy way to set this up is to use this [website](https://gramgra07.github.io/SM-creator/) I made to generate code for you.

Writerside/topics/subsystem-control.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,7 @@ To create your own:
277277
3. Create setter functions to set values differently
278278
4. Create an update function that sets the values requested by the states
279279
5. All done, now just make sure to call your subsystem functions correctly and initialize everything well
280+
281+
OR
282+
283+
Use this handy website I created to generate code for a subsystem! [Subsystem Generator](https://gramgra07.github.io/SubsystemMaker/)

Writerside/v.tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
<toc-element toc-title="Advanced">
3030
<toc-element topic="external-hardware-classes.md"/>
3131
<toc-element topic="pidf.md"/>
32+
<toc-element topic="ServoStateMachines.md"/>
3233
<toc-element topic="subsystem-control.md"/>
34+
<toc-element topic="OpModeRegistrars.md"/>
3335
<toc-element topic="switching-to-kotlin.md"/>
3436
</toc-element>
3537
<toc-element toc-title=".etc">

0 commit comments

Comments
 (0)