Skip to content
ftcerror24501Public

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoHive — FTC BioBuzz 3D Autonomous Simulator by Error Team

AutoHive — FTC BioBuzz 3D Autonomous Simulator

AutoHive is a single-file, browser-based FTC (FIRST Tech Challenge) autonomous simulator and digital twin for the BioBuzz game. Write your autonomous in Java (LinearOpMode), blocks, or JavaScript, press ▶, and watch a virtual robot drive a 3D BioBuzz field, read AprilTags with a virtual camera, spin up a flywheel and shoot wiffle balls into the hive — before the real robot ever moves.

Built by Error Team, developed with Mir Bedirhan Berekatoglu.

Keywords: FTC simulator · FTC autonomous simulator · FTC digital twin · FTC BioBuzz · FIRST Tech Challenge · LinearOpMode · AprilTag · Three.js · biobuzz-digital-twin


The BioBuzz game

BioBuzz is a bee-and-hive themed robot game. The field and game pieces this simulator models are:

Game element Details
Hive stand A tall stand carrying four hexagonal cells: two red and two blue (one raised and one lowered per alliance)
AprilTags Every cell carries AprilTags (IDs 30–45, four per cell) so robots can locate and range their target
Pollen balls 40 yellow wiffle balls
Alliance balls 8 red and 8 blue wiffle balls
Flower towers 4 green flower towers
Trays 2 black trays

In AutoHive the goal of an autonomous run is to find your alliance's raised hive cell with the camera, align, and land yellow balls in it. A ball that lands in your raised cell turns green and is counted as a hit.


Features

  • Full 3D field (Three.js r128) with shadows, hemisphere + sun lighting, hive stand, cells and AprilTag textures.
  • Three ways to code: Java LinearOpMode, drag-and-drop blocks that generate Java, and a small JavaScript API.
  • Real FTC SDK feel: hardwareMap.get(...), DcMotor/DcMotorEx, CRServo/Servo, IMU, ElapsedTime, telemetry, AprilTagProcessor.getDetections().
  • Virtual robot webcam: a live POV inset (4:3) with an on-screen detection read-out, or switch to your real webcam.
  • Ball physics: ballistic flight, floor bounce, wall bounce, ball-to-ball and ball-to-robot collisions, cell hit detection.
  • Robot tipping: shoot too many times and the robot falls over (configurable).
  • Camera modes: free orbit, chase-robot, top-down. Speed 1× / 2× / 4×.
  • Load your own robot: drop in a .glb / .gltf model (Draco supported).
  • Zero install: one .html file, open it in a browser.

Quick start

  1. Open index.html (the simulator file) in a modern browser. For the real webcam, open it directly in the browser and allow camera access.
  2. Pick Red or Blue alliance.
  3. Write or paste your OpMode in the Java tab (a working default is included).
  4. Press ▶ Start. Watch the robot, the telemetry card and the robot-camera inset.
  5. Tune wheel size, track width, motor names, hood angle and more in Robot settings.

Example OpMode

@Autonomous(name = "AutoHiveDemo")
public class AutoHiveDemo extends LinearOpMode {
    @Override
    public void runOpMode() {
        DcMotorEx left  = hardwareMap.get(DcMotorEx.class, "left_drive");
        DcMotorEx right = hardwareMap.get(DcMotorEx.class, "right_drive");
        DcMotorEx shooter = hardwareMap.get(DcMotorEx.class, "shooter");
        CRServo feeder = hardwareMap.get(CRServo.class, "feeder");
        right.setDirection(DcMotor.Direction.REVERSE);   // like the real robot

        waitForStart();
        left.setPower(0.5); right.setPower(0.5);
        sleep(1200);
        left.setPower(0);   right.setPower(0);

        shooter.setPower(0.55);
        sleep(1500);
        for (int i = 0; i < 3 && opModeIsActive(); i++) {
            feeder.setPower(1); sleep(250);
            feeder.setPower(0); sleep(700);
        }
    }
}

How it works (code walkthrough)

AutoHive is deliberately one self-contained file. Everything below lives in a single <script>.

flowchart LR
  A[Java / Blocks / JS] -->|j2js transpiler| B[async JavaScript]
  B --> C[FTC SDK mocks<br/>hardwareMap, IMU, telemetry]
  C --> D[Robot state R<br/>tank drive model]
  D --> E[step dt<br/>physics + shooter]
  E --> F[Ball physics<br/>cells, walls, robot]
  D --> G[detect<br/>virtual AprilTag camera]
  G --> C
  E --> H[Three.js render<br/>main view + robot POV]
Loading

1. Units and coordinates

Everything is in inches. The field is 144 × 144 in (−72…72). x points east (blue side), z south (toward the audience), y up. The red robot starts at (−63, 36) facing the field, the blue robot at (63, −36). Gravity is 386.09 in/s².

2. Hive geometry

CL describes the four hive cells: their position (x = ±12.75, z = ±16.5), alliance, whether they are the raised cell, their height (58.2 in raised / 44.2 in lowered) and the four AprilTag IDs on each. The stand legs sit at ±24.73 in and are collision obstacles for the robot.

3. Robot model (tank drive)

Each step the commanded left/right power eases toward the target wheel speed (first-order lag, ~0.12 s), then:

  • forward speed = average of both sides
  • turn rate = (vr − vl) / trackWidth × 0.75 (the 0.75 factor models tank-drive scrub)
  • the robot is clamped inside the field and pushed out of the stand legs

Defaults: 96 mm wheels, 280 RPM motors, 16.8 in track width, 537.7 ticks/rev.

4. Virtual camera and AprilTags

detect() places a camera 13 in high with a 35° pitch, ±31° horizontal and ±20° vertical field of view. A cell is detected only if it is inside the FOV and faces the camera (cos > 0.2). It returns the same fields real FTC code expects: id, bearing, range, elevation, plus ftcPose.x/y/z for the AprilTagProcessor mock. Tag textures are drawn procedurally onto a canvas from 36-bit codes, so no image assets are needed.

5. Shooter and ballistics

A flywheel turns RPM; exit speed is 0.45 × π × 0.096 m × rpm / 60 (efficiency × flywheel circumference). Balls leave the robot at a fixed 55° hood angle. The default OpMode contains rpmFor(d), which inverts the projectile equation to compute the RPM needed to reach the target cell from the measured horizontal distance and height — the same maths a real team would put on the robot.

6. Ball physics

Four sub-steps per frame: gravity, floor bounce (restitution 0.45 with friction), field walls (0.5 bounce), ball-to-ball collision resolution, ball-to-robot push-out, and cell hit tests. Balls that settle in your raised cell turn from yellow to green and increment the hit counter.

7. Java → JavaScript transpiler

j2js() is a compact, regex-based translator for the LinearOpMode subset teams actually write: it strips package/import/annotations, removes access modifiers, converts methods to async function, typed locals to let, for (T x : xs) to for…of, casts, new int[n], ArrayList, and inserts await before every call to a user method, sleep, waitForStart, opModeIsActive, isStopRequested and idle.

⚠️ It supports a practical subset of Java, not the full language. If something fails to translate, the error appears in telemetry.

8. Simulated time

sleep(ms) does not use real time. It registers a resolver on the simulation clock, so 2× and 4× speed, pausing and instant stopping all behave deterministically. An autonomous period is capped at 30 s of sim time.

9. FTC SDK mocks

A Proxy-based sandbox provides hardwareMap, motors (power, direction, run modes, RUN_TO_POSITION, encoder position, velocity), IMU yaw, ElapsedTime, telemetry.addData/addLine/update, AprilTagProcessor, VisionPortal and friends. Unknown classes degrade gracefully instead of crashing.

10. Blocks → Java

The block editor stores a tree of blocks (drive, turn, wait, shooter, feeder, shoot N, align to tag, shoot by distance, repeat, loop) and genBlocks() emits a complete, copy-pasteable FTC LinearOpMode class, including vision imports only when a vision block is used.


Robot settings

Setting Default
Wheel diameter 96 mm
Motor RPM 280
Track width 16.8 in
Ticks / rev 537.7
Motor names left_drive, right_drive, shooter, feeder
Hood angle 55°
Flywheel efficiency / diameter 0.45 / 96 mm
Tip over after N shots 8 (0 = off)
Align tolerance / min power 1.5° / 0.08

JavaScript API (legacy)

robot.drive(fwd, turn) · robot.tank(l, r) · robot.tags() · robot.heading() · robot.shooter(rpm) · robot.rpm() · robot.feeder(0|1) · robot.travel() · robot.time() · robot.telemetry(k, v) · robot.alliance · await sleep(ms) · active()


The visual effects

In the simulator: soft real-time shadows and hemisphere lighting, a second render pass for the robot-POV camera, balls that change colour when they score, and an animated robot tip-over.

In the banner (autohive-banner.svg, pure SVG + CSS/SMIL, no scripts, works inside a GitHub <img>):

  • RGB-split glitch bursts on the title (a nod to Error Team)
  • A moving light sweep over a honeycomb background
  • A mini BioBuzz field: the robot follows a marching-ants trajectory, scans an AprilTag, and fires three yellow balls that turn green on a hit while a live hit counter ticks up
  • A flying bee, a glowing gradient border and a telemetry ticker

Credits and sources

  • Error Team — project and banner
  • Mir Bedirhan Berekatoglu — development
  • Built on and inspired by biobuzz-digital-twin by camels-hump-coders
  • 3D rendering by three.js

FIRST® and FIRST® Tech Challenge are trademarks of FIRST. AutoHive is an independent community project and is not affiliated with or endorsed by FIRST.