Skip to content

Add Python lesson 7: RobotPy in our robot code, with browser exercises - #19

Merged
MBimrose merged 4 commits into
mainfrom
claude/peaceful-lovelace-5dsi0d
Nov 10, 2026
Merged

MBimrose merged 4 commits into
mainfrom
claude/peaceful-lovelace-5dsi0d

Conversation

@MBimrose

Copy link
Copy Markdown
Member

Summary

A new lesson, 7. RobotPy in Our Robot Code (docs/Code/Python Tutorials/07 robotpy in our code.md). It goes through the RobotPy code from Robot-2024-Public, Robot-2025-Public and Robot-2026 (tracking-hub), file by file:

  • robot.py and CoroutineRobot
  • subsystems
  • Phoenix 6
  • const.py
  • wpimath geometry and control
  • oi.py bindings
  • @commandify coroutines
  • autos
  • the dashboard
  • the Python features the code uses

The exercises run in the browser, with the same widget as lessons 1–6: 9 graded exercises and a "Try it" block.

How it works

  • assets/py/robotpy/ holds a small plain-Python copy of the parts of wpilib, wpimath, commands2 and phoenix6 that our code uses. It also has an exact copy of wpilibextra from Robot-2026, and cz_sim helpers for the checks.
  • An exercise with library: robotpy loads that copy before the student's code. python-worker.js downloads the files listed in manifest.json one time and re-imports them for each run, so every run starts with a fresh scheduler.
  • _config.yml now has an include entry for __init__.py and _sim.py, which Jekyll otherwise leaves out.

Checks

  • tools/validate-exercises.py understands library: and treats "Try it" blocks as code that only has to run. That clears 18 old false failures; the 2 that remain were already on main.
  • tools/validate-robotpy-browser.py --robotpy PATH runs every lesson 7 check with the browser copy and with the real RobotPy 2026. All 9 exercises agree.
  • tools/e2e/tests/robotpy-lesson.spec.mjs checks the page in Chromium. It passed locally, with Pyodide 0.29.4 served from npm because the CDN is blocked in that environment.
  • node tools/check-ste.js shows no hard findings on the new page.

Also

  • Lesson 6 links to lesson 7, and the Python Tutorials index lists it.
  • The Tutorials page documents the library: option and the new tool.

Generated by Claude Code

Link the interactive Learn Git Branching tutorial in the Getting Started
section and the Additional Resources list so students can practice Git
commands hands-on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019dqu5om52cZsRn7kinP82t
A tutorial page that goes through the RobotPy code from Robot-2024-Public,
Robot-2025-Public and Robot-2026 (tracking-hub), file by file: robot.py and
CoroutineRobot, subsystems, Phoenix 6, const.py, wpimath geometry and
control, the OI bindings, commandify coroutines, autos and command groups,
the dashboard, and the Python features the code uses.

practice/robotpy is a set of eight exercises with pytest checks that run
against the real RobotPy 2026 libraries, plus a small practice robot that
runs with "robotpy sim" and "robotpy test". tools/validate-robotpy-practice.py
checks that each starter fails and each solution passes.

Behaviors checked with RobotPy 2026 while writing this:
- whenHeld with a plain function runs one time; a generator runs each loop
- a command in two groups raises IllegalCommandUse
- calling a commandify command gives a broken command (TypeError when run)
- periodic() runs while disabled
- CoroutineRobot stores robotInit on the instance, which hides the hook that
  "robotpy test" uses, so robot tests time out. The practice pack copy of
  wpilibextra makes these class methods.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019dqu5om52cZsRn7kinP82t
The lesson 7 exercises now use the same in-page Python exercise widget as
lessons 1 to 6, instead of a local pytest practice pack.

The real RobotPy libraries cannot load in Pyodide, so assets/py/robotpy is a
small plain-Python copy of the parts our code uses: wpilib, wpimath,
commands2 and phoenix6, plus an exact copy of wpilibextra from Robot-2026 and
a cz_sim helper for the checks. An exercise with `library: robotpy` loads it
before the student's code, and the worker imports it fresh for every run.

- python-worker.js: download a library manifest once, write the files into
  Pyodide, and forget the modules before each run
- python-exercise.html / .js: pass the library URL to the worker
- _config.yml: include __init__.py and _sim.py, which Jekyll leaves out
- 10 exercises in _data/exercises/py7_*.yml (one Try it block)
- validate-exercises.py: understands `library:`, and treats Try it blocks
  (no tests, no solution) as code that only has to run
- validate-robotpy-browser.py: runs every lesson 7 check with the browser
  copy and with the real RobotPy 2026; both must agree
- e2e test for the lesson 7 page
- the local practice pack (practice/robotpy) and its tools are removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019dqu5om52cZsRn7kinP82t
@MBimrose
MBimrose merged commit b458e6c into main Nov 10, 2026
1 check passed
MBimrose pushed a commit that referenced this pull request Nov 10, 2026
…no changes)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019dqu5om52cZsRn7kinP82t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants