Skip to content

Repository files navigation

FRC 2026 Practice Code

Personal FRC Java practice project for learning WPILib Command-Based programming and developing robot mechanisms from simple simulation examples toward competition-ready implementations.

This is a learning project, not the official competition code for FRC Team 11019. Hardware directions, current limits, and mechanism behavior must be verified on the real robot before deployment.

Current Focus: Dual-Motor Intake

The current mechanism is a roller Intake powered by two Kraken X44 motors controlled through CTRE Phoenix 6:

  • Talon FX leader on CAN ID 10
  • Talon FX follower on CAN ID 11
  • Phoenix 6 VoltageOut control
  • Phoenix 6 Follower leader-follower control
  • Hold A to Intake and release to stop
  • Hold B to Outtake and release to stop
  • Runtime Intake and Outtake voltage adjustment through Elastic
  • Velocity, stator current, and supply current telemetry through SmartDashboard for AdvantageScope
  • Configurable neutral mode, motor direction, follower alignment, and stator current limit

The core Intake and Outtake behavior has been tested in WPILib simulation. The latest safety configuration builds successfully but still requires real-hardware validation.

Software

  • Java 17
  • WPILib 2026
  • GradleRIO
  • CTRE Phoenix 6 26.3.0
  • WPILib Command-Based framework
  • Elastic for operator-adjustable voltage values
  • AdvantageScope for telemetry visualization

Desktop support is enabled for simulation.

Project Structure

src/main/java/frc/robot/
├── Constants.java
├── Main.java
├── Robot.java
├── RobotContainer.java
├── commands/
│   └── IntakeCommand.java
└── subsystems/
    └── IntakeSubsystem.java

工程日志/
├── 2026.7.28.md
├── 2026.7.29.md
└── 2026.7.30.md
  • Constants.java stores hardware IDs, safe limits, controller settings, and dashboard keys.
  • RobotContainer.java creates the subsystem, initializes dashboard values, and defines button bindings.
  • IntakeCommand.java supplies the current target voltage and stops the Intake when interrupted.
  • IntakeSubsystem.java owns the Talon FX controllers, applies Phoenix 6 configuration, controls the motors, and publishes telemetry.
  • 工程日志/ contains bilingual daily engineering logs, with English first and Chinese second.

Intake Data Flow

Elastic target voltage
        ↓
RobotContainer
        ↓
IntakeCommand
        ↓
IntakeSubsystem
        ↓
Phoenix 6 VoltageOut
        ↓
Leader Talon FX → Follower Talon FX

Controls

Input Behavior
Hold A Run Intake using the positive Intake voltage
Release A Stop Intake
Hold B Run Outtake using the negative Outtake voltage
Release B Stop Intake

The values entered in Elastic are clamped to the range from 0 V to 12 V. Outtake is entered as a positive magnitude and converted to a negative voltage in code.

Dashboard and Telemetry

Elastic uses these SmartDashboard entries:

  • Intake/IntakeVoltage
  • Intake/OuttakeVoltage

AdvantageScope can display:

  • Leader and Follower velocity in rotations per second
  • Leader and Follower stator current
  • Leader and Follower supply current

Stator current is associated with motor torque and mechanism loading. Supply current is the current drawn from the robot battery. Current-limit values in this repository are conservative learning values and must be tuned using real mechanism data.

Build and Simulation

Install the WPILib 2026 development tools, then open this folder using WPILib VS Code.

Build the project:

./gradlew build

Run desktop simulation:

./gradlew simulateJava

On systems where the default Java runtime is not suitable, use the JDK bundled with WPILib 2026.

Real-Robot Validation Checklist

Before operating the Intake on real hardware:

  1. Confirm CAN IDs and device firmware in Phoenix Tuner X.
  2. Test the leader direction at low voltage.
  3. Confirm whether the follower should use Aligned or Opposed.
  4. Compare Coast and Brake behavior.
  5. Plot leader and follower voltage, velocity, stator current, and supply current.
  6. Determine a suitable stator current limit using repeated tests with the actual game piece.
  7. Verify emergency-stop access and keep people clear of the rollers.

Never use a hand to create a stall or jam during current-limit testing.

Roadmap

  • Configure telemetry update frequencies for real-hardware testing
  • Add measured motor voltage and commanded-voltage telemetry
  • Validate motor direction, follower alignment, and neutral mode on the real mechanism
  • Tune stator and supply current limits
  • Add game-piece detection and automatic Intake behavior
  • Add stall detection and jam protection
  • Refactor the Intake into a reusable competition-ready subsystem
  • Add drivetrain localization
  • Add Limelight vision fusion
  • Add Choreo autonomous routines

Learning Resources


FRC 2026 练习代码

这是一个个人 FRC Java 练习项目,用于学习 WPILib Command-Based 编程,并将机器人机构从简单的模拟示例逐步迭代为接近比赛级的实现。

这是学习项目,不是 FRC 11019 队的正式比赛代码。电机方向、电流限制和机构行为必须在部署前通过真实机器人验证。

当前重点:双电机 Intake

当前机构是由两台 Kraken X44 驱动、通过 CTRE Phoenix 6 控制的滚轮 Intake:

  • CAN ID 为 10 的 Talon FX 主电机
  • CAN ID 为 11 的 Talon FX 跟随电机
  • 使用 Phoenix 6 VoltageOut 控制
  • 使用 Phoenix 6 Follower 主从控制
  • 按住 A 执行 Intake,松开后停止
  • 按住 B 执行 Outtake,松开后停止
  • 通过 Elastic 实时调整 Intake 与 Outtake 电压
  • 通过 SmartDashboard 向 AdvantageScope 发布转速、Stator Current 和 Supply Current
  • 可配置 Neutral Mode、电机方向、Follower Alignment 和 Stator Current Limit

Intake 与 Outtake 的核心行为已经在 WPILib 模拟环境中测试。最新的安全配置已经成功构建,但仍需要在真实硬件上验证。

软件

  • Java 17
  • WPILib 2026
  • GradleRIO
  • CTRE Phoenix 6 26.3.0
  • WPILib Command-Based 框架
  • Elastic:调整驾驶员可配置的电压值
  • AdvantageScope:显示遥测数据

项目已经启用 Desktop Support,可以运行桌面模拟。

项目结构

src/main/java/frc/robot/
├── Constants.java
├── Main.java
├── Robot.java
├── RobotContainer.java
├── commands/
│   └── IntakeCommand.java
└── subsystems/
    └── IntakeSubsystem.java

工程日志/
├── 2026.7.28.md
├── 2026.7.29.md
└── 2026.7.30.md
  • Constants.java 保存硬件 ID、安全限制、控制器配置和 Dashboard Key。
  • RobotContainer.java 创建 Subsystem、初始化 Dashboard 数值并定义按键绑定。
  • IntakeCommand.java 持续提供目标电压,并在 Command 被中断时停止 Intake。
  • IntakeSubsystem.java 管理 Talon FX、应用 Phoenix 6 配置、控制电机并发布遥测数据。
  • 工程日志/ 保存双语的每日工程日志,英文版在前,中文版在后。

Intake 数据流

Elastic 目标电压
        ↓
RobotContainer
        ↓
IntakeCommand
        ↓
IntakeSubsystem
        ↓
Phoenix 6 VoltageOut
        ↓
Talon FX 主电机 → Talon FX 跟随电机

控制方式

输入 行为
按住 A 使用正向 Intake 电压运行
松开 A 停止 Intake
按住 B 使用负向 Outtake 电压运行
松开 B 停止 Intake

Elastic 中输入的数值会被限制在 0 V12 V。Outtake 在 Elastic 中输入正数大小,再由代码转换为负电压。

Dashboard 与遥测

Elastic 使用以下 SmartDashboard 条目:

  • Intake/IntakeVoltage
  • Intake/OuttakeVoltage

AdvantageScope 可以显示:

  • Leader 与 Follower 转速,单位为 rotations per second
  • Leader 与 Follower 的 Stator Current
  • Leader 与 Follower 的 Supply Current

Stator Current 与电机扭矩和机构负载相关;Supply Current 是控制器从机器人电池取得的电流。仓库中的 Current Limit 是保守的学习数值,必须根据真实机构数据进行调整。

构建与模拟

安装 WPILib 2026 开发工具,然后使用 WPILib VS Code 打开项目文件夹。

构建项目:

./gradlew build

运行桌面模拟:

./gradlew simulateJava

如果系统默认 Java 不适用,请使用 WPILib 2026 自带的 JDK。

真机验证清单

在真实硬件上运行 Intake 前:

  1. 在 Phoenix Tuner X 中确认 CAN ID 与设备固件。
  2. 使用低电压测试 Leader 方向。
  3. 确认 Follower 应使用 Aligned 还是 Opposed
  4. 对比 CoastBrake 的行为。
  5. 绘制 Leader 与 Follower 的电压、转速、Stator Current 和 Supply Current。
  6. 使用真实比赛物体进行重复测试,确定合适的 Stator Current Limit。
  7. 确保能够立即执行紧急停止,并让人员远离滚轮。

进行 Current Limit 测试时,禁止用手制造堵转或卡住机构。

后续路线

  • 为真机测试配置遥测更新频率
  • 添加实际电机电压和请求电压遥测
  • 在真实机构上验证电机方向、Follower Alignment 和 Neutral Mode
  • 调整 Stator Current Limit 与 Supply Current Limit
  • 添加比赛物体检测和自动 Intake
  • 添加堵转检测和卡球保护
  • 将 Intake 重构为可复用的比赛级 Subsystem
  • 添加底盘定位
  • 添加 Limelight 视觉融合
  • 添加 Choreo 自动流程

学习资料

About

FRC 2026 Code for Personal Practice

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages