|
| 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! |
0 commit comments