Skip to main content

3D robot in AdvantageScope

Ciprix shows the team's CAD in AdvantageScope with moving parts following the real mechanisms (RobotVisualizer and MechanismPoses, in ciprix-core). It works the same way in simulation, on the robot and in log replay, because the poses come from the subsystems' inputs.

Create an advantagescope/ folder at the root of the robot project:

advantagescope/
Robot_MyRobot/
config.json robot configuration (hand-written, versioned)
model.glb the chassis and everything that doesn't move (exported from CAD)
model_0.glb the intake (moving part 0)
config.generated.json generated by the simulation, not versioned

1. Export the CAD​

  1. Leave the robot assembly in the mechanisms' start position, the same one the code treats as zero angle or zero height.
  2. The assembly's origin should be the center of the chassis, on the ground. If it isn't, adjust position in config.json and add the same value to each zeroedPosition.
  3. Export the chassis without the moving parts as model.glb (binary glTF).
  4. Export each moving part as a separate file, model_0.glb, model_1.glb and so on, in the same position it's in on the assembly (don't move the origin). In Onshape, one way is to suppress the other parts before exporting.

The official conversion guide is at Converting Onshape & STEP Files to glTF and the config.json format is at Custom Assets.

Large .glb files slow AdvantageScope down. If one passes roughly 50 MB, simplify the model (no bolts, no small holes) and consider not versioning the .glb files (or using Git LFS).

2. Register the part in code​

Each moving part is registered once, with its model number and the point it rotates around. The minimal templates/skeleton doesn't ship a visualizer, while the examples/arm-elevator example has a complete RobotContainer.configureVisualizer() with an elevator carriage and a carriage-mounted arm. Add the registration to your own RobotContainer:

// model_0.glb: the intake, rotating around the pivot axis.
RobotVisualizer.component(
0,
MechanismPoses.pivot(IntakeConstants.PIVOT_AXIS, Axis.PITCH, intake::getPivotAngle),
IntakeConstants.PIVOT_AXIS);
  • PIVOT_AXIS: a point on the rotation axis, measured in the CAD in meters (X forward, Y to the left, Z up, from the center of the chassis on the ground).
  • Axis.PITCH with a positive angle raises the front; Axis.YAW rotates counter-clockwise as seen from above (turrets).
  • For elevators use MechanismPoses.slider(start, direction, subsystem::getHeight), and for a part mounted on another part (an arm on an elevator carriage) use MechanismPoses.attach(parent, child).

3. Generate the config.json​

Run the simulation once (./gradlew simulateJava). It writes Robot_MyRobot/config.generated.json with one component per registered part, already carrying the zeroedPosition that brings each part's axis to the origin (that's how AdvantageScope expects a "zeroed" part). Copy the components list into config.json.

The default rotations (x 90°, then z 90°) work for models exported from Onshape. If the robot shows up lying down or rotated, adjust rotations and zeroedRotations together.

4. View in AdvantageScope​

  1. In AdvantageScope, use App > Use Custom Assets Folder (on macOS the menu is called AdvantageScope) and pick this advantagescope/ folder, the one containing Robot_MyRobot. That way the model updates along with each git pull.
  2. Open a 3D Field tab, drag the robot's pose (RealOutputs/Subsystems/Drivetrain/Odometry/Pose) and pick the team's model (the name in config.json).
  3. Drag RealOutputs/Visualizer/Components onto the robot and pick Components.

If a part rotates around the wrong point, PIVOT_AXIS doesn't match the CAD. If it rotates the wrong way, flip the sign of the angle the subsystem reports.