Skip to content

Commit ddb3892

Browse files
committed
Added guides
1 parent 7b7d5c2 commit ddb3892

9 files changed

Lines changed: 505 additions & 25 deletions

File tree

astro.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export default defineConfig({
3232
{
3333
label: 'Guides',
3434
items: [
35-
{ label: 'Example Guide', slug: 'guides/example' },
35+
{ label: '1. Installation', slug: 'guides/installation' },
36+
{ label: '2. Basic Usage', slug: 'guides/basic-usage' },
37+
{ label: '3. Modules & Commands', slug: 'guides/writing-modules-commands' },
38+
{ label: '4. TeleOp OpModes', slug: 'guides/teleop-opmodes' },
39+
{ label: '5. Auto OpModes', slug: 'guides/auto-opmodes' },
3640
],
3741
},
3842
{
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Writing Auto OpModes
3+
description: Learn how to write Autonomous OpModes in CoreControl.
4+
---
5+
6+
import { Tabs, TabItem } from '@astrojs/starlight/components';
7+
8+
Autonomous OpModes in CoreControl are structured around two main commands: an `initCommand` (runs during initialization) and a `startCommand` (runs when the match starts). This structure encourages a clean, command-based approach to autonomous programming.
9+
10+
## Basic Structure
11+
12+
To create an Autonomous OpMode, extend `CoreAuto`.
13+
14+
<Tabs>
15+
<TabItem label="Kotlin">
16+
```kotlin
17+
@Autonomous(name = "Red Auto")
18+
class RedAuto : CoreAuto(
19+
// Register modules
20+
modules = arrayOf(Drivetrain, Intake, Lift),
21+
22+
// Command to run during initialization
23+
initCommand = instant {
24+
Lift.resetEncoders()
25+
Intake.closeClaw()
26+
},
27+
28+
// Command to run when the match starts
29+
startCommand = sequentially(
30+
// Drive to position
31+
DriveToPosition(10.0, 0.0),
32+
// Score pixel
33+
Lift.goToPosition(1000),
34+
Intake.openClaw(),
35+
wait(0.5),
36+
Lift.goToPosition(0),
37+
// Park
38+
DriveToPosition(0.0, 24.0)
39+
)
40+
)
41+
```
42+
</TabItem>
43+
<TabItem label="Java">
44+
```java
45+
@Autonomous(name = "Red Auto")
46+
public class RedAuto extends CoreAuto {
47+
48+
public RedAuto() {
49+
super(
50+
// Register modules
51+
new CoreModule[]{Drivetrain.INSTANCE, Intake.INSTANCE, Lift.INSTANCE},
52+
53+
// Command to run during initialization
54+
new InstantCommand(() -> {
55+
Lift.INSTANCE.resetEncoders();
56+
Intake.INSTANCE.closeClaw();
57+
}),
58+
59+
// Command to run when the match starts
60+
sequentially(
61+
// Drive to position
62+
new DriveToPosition(10.0, 0.0),
63+
// Score pixel
64+
Lift.INSTANCE.goToPosition(1000),
65+
Intake.INSTANCE.openClaw(),
66+
wait(0.5),
67+
Lift.INSTANCE.goToPosition(0),
68+
// Park
69+
new DriveToPosition(0.0, 24.0)
70+
)
71+
);
72+
}
73+
}
74+
```
75+
</TabItem>
76+
</Tabs>
77+
78+
## Key Concepts
79+
80+
1. **Init Command**: Use `initCommand` to perform setup tasks like resetting encoders, closing claws, or initializing vision pipelines. This command runs once when you press INIT.
81+
2. **Start Command**: Use `startCommand` to define your main autonomous sequence. This command runs once when you press PLAY.
82+
3. **Command Groups**: Use `sequentially`, `inParallel`, and `racing` to combine simple commands into complex behaviors.
83+
4. **No Loop Logic**: Unlike TeleOp, you generally do not need to override `onMainLoop` in `CoreAuto`. The command scheduler handles everything for you.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
title: Basic Usage & Project Structure
3+
description: Learn how to structure your CoreControl project and get started with basic usage.
4+
---
5+
6+
import { Tabs, TabItem } from '@astrojs/starlight/components';
7+
8+
CoreControl encourages a modular and organized project structure. This guide will show you how to set up your project and start using the library effectively.
9+
10+
## Project Structure
11+
12+
We recommend organizing your code by feature or subsystem. A common structure for an FTC robot project using CoreControl looks like this:
13+
14+
```
15+
TeamCode/
16+
├── src/main/java/org/firstinspires/ftc/teamcode/
17+
│ ├── modules/ # Contains all your robot modules
18+
│ │ ├── Drivetrain.java # Drivetrain module
19+
│ │ ├── Intake.java # Intake module
20+
│ │ ├── Lift.java # Lift module
21+
│ │ └── Robot.java # Main Robot module (optional, for grouping)
22+
│ ├── commands/ # Contains custom commands (optional)
23+
│ │ ├── AutoDriveCommand.java
24+
│ │ └── ScorePixelCommand.java
25+
│ ├── opmodes/ # Contains your OpModes
26+
│ │ ├── TeleOp.java # Main TeleOp
27+
│ │ └── AutoRed.java # Autonomous OpMode
28+
│ └── utils/ # Utility classes
29+
```
30+
31+
This structure keeps your code clean and easy to navigate. Each module is self-contained in its own file within the `modules` package.
32+
33+
## Creating Your First Module
34+
35+
Let's create a simple `Intake` module.
36+
37+
<Tabs>
38+
<TabItem label="Kotlin">
39+
```kotlin
40+
package org.firstinspires.ftc.teamcode.modules
41+
42+
import com.andreidurlea.corecontrol.modulesFeature.Module
43+
import com.qualcomm.robotcore.hardware.DcMotor
44+
45+
object Intake : Module() {
46+
private lateinit var motor: DcMotor
47+
48+
override fun onInit() {
49+
// hardwareMapEverywhere is globally available!
50+
motor = hardwareMapEverywhere.get(DcMotor::class.java, "intake")
51+
}
52+
53+
fun setPower(power: Double) {
54+
motor.power = power
55+
}
56+
}
57+
```
58+
</TabItem>
59+
<TabItem label="Java">
60+
```java
61+
package org.firstinspires.ftc.teamcode.modules;
62+
63+
import com.andreidurlea.corecontrol.modulesFeature.Module;
64+
import com.qualcomm.robotcore.hardware.DcMotor;
65+
import com.andreidurlea.corecontrol.miscellaneous.GlobalObjects;
66+
67+
public class Intake extends Module {
68+
public static final Intake INSTANCE = new Intake();
69+
private DcMotor motor;
70+
71+
@Override
72+
public void onInit() {
73+
// hardwareMapEverywhere is globally available!
74+
motor = GlobalObjects.hardwareMapEverywhere.get(DcMotor.class, "intake");
75+
}
76+
77+
public void setPower(double power) {
78+
motor.setPower(power);
79+
}
80+
}
81+
```
82+
</TabItem>
83+
</Tabs>
84+
85+
## Using Modules in an OpMode
86+
87+
Now, let's use this module in a TeleOp OpMode.
88+
89+
<Tabs>
90+
<TabItem label="Kotlin">
91+
```kotlin
92+
package org.firstinspires.ftc.teamcode.opmodes
93+
94+
import com.andreidurlea.corecontrol.opModesFeature.CoreTeleOp
95+
import org.firstinspires.ftc.teamcode.modules.Intake
96+
97+
@TeleOp(name = "My TeleOp")
98+
class MyTeleOp : CoreTeleOp(Intake) { // Register the module here!
99+
100+
override fun onMainLoop() {
101+
if (gamepad1.a) {
102+
Intake.setPower(1.0)
103+
} else {
104+
Intake.setPower(0.0)
105+
}
106+
}
107+
}
108+
```
109+
</TabItem>
110+
<TabItem label="Java">
111+
```java
112+
package org.firstinspires.ftc.teamcode.opmodes;
113+
114+
import com.andreidurlea.corecontrol.opModesFeature.CoreTeleOp;
115+
import org.firstinspires.ftc.teamcode.modules.Intake;
116+
117+
@TeleOp(name = "My TeleOp")
118+
public class MyTeleOp extends CoreTeleOp {
119+
120+
public MyTeleOp() {
121+
super(Intake.INSTANCE); // Register the module here!
122+
}
123+
124+
@Override
125+
public void onMainLoop() {
126+
if (gamepad1.a) {
127+
Intake.INSTANCE.setPower(1.0);
128+
} else {
129+
Intake.INSTANCE.setPower(0.0);
130+
}
131+
}
132+
}
133+
```
134+
</TabItem>
135+
</Tabs>
136+
137+
By registering `Intake` in the `CoreTeleOp` constructor, its `onInit` method is automatically called when you press INIT on the Driver Station. You don't need to manually initialize it!

src/content/docs/guides/example.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/content/docs/guides/index.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Guides
3+
description: Step-by-step guides for using CoreControl.
4+
---
5+
6+
Welcome to the CoreControl Guides. These tutorials will help you get started with the library and master its features.
7+
8+
## Getting Started
9+
10+
* [Installation Guide](/guides/installation/): Learn how to add CoreControl to your project.
11+
* [Basic Usage & Project Structure](/guides/basic-usage/): Understand the recommended project structure and create your first module.
12+
13+
## Core Concepts
14+
15+
* [Writing Modules & Commands](/guides/writing-modules-commands/): Learn how to write reusable modules and custom commands.
16+
* [Writing TeleOp OpModes](/guides/teleop-opmodes/): Create driver-controlled OpModes with ease.
17+
* [Writing Auto OpModes](/guides/auto-opmodes/): Build powerful autonomous routines using command sequences.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Installation Guide
3+
description: A quick guide on how to install the CoreControl library in your FIRST Tech Challenge project.
4+
---
5+
6+
This guide will walk you through the steps to install the CoreControl library in your FIRST Tech Challenge project.
7+
8+
## Option 1: Start fresh with CoreControl Quickstart
9+
10+
The easiest way to get started with CoreControl is to use our Quickstart repository, which comes pre-configured with everything you need.
11+
12+
1. Go to the [CoreControl Quickstart GitHub repository](https://github.com/CoreControlLib/CoreControlQuickstart).
13+
2. Click on the "Code" button and select "Download ZIP" or clone the repository using GitHub Desktop.
14+
3. Open the downloaded project in Android Studio.
15+
4. Read the `FeatureList` file in the repository to understand the included features. You can find it at `TeamCode/src/main/java/org/firstinspires/ftc/teamcode/FeatureList.java`.
16+
17+
## Option 2: Add CoreControl to an existing project
18+
19+
If you already have a FIRST Tech Challenge project and want to add CoreControl to it, follow these steps:
20+
21+
1. Open your existing project in Android Studio.
22+
2. Open the `build.gradle` file located in the `TeamCode` module of your project.
23+
3. Add the following lines to the `repositories` section to include the CoreControl Maven repository:
24+
25+
```groovy
26+
repositories {
27+
maven {
28+
url "https://remote.corecontrollib.com"
29+
}
30+
}
31+
```
32+
33+
4. Add the following line to the `dependencies` section:
34+
35+
```groovy
36+
dependencies {
37+
implementation 'com.andreidurlea:corecontrol:1.1.0.1'
38+
}
39+
```
40+
41+
5. Sync your project with Gradle files.

0 commit comments

Comments
 (0)