Skip to content

Restructure example docs - #138

Open
ratheron wants to merge 3 commits into
mainfrom
fix.docs
Open

ratheron wants to merge 3 commits into
mainfrom
fix.docs

Conversation

@ratheron

Copy link
Copy Markdown
Collaborator

With this PR, the docs contain all examples (tested with new test). To make it less crowded (#131), the docs are strucuted as the example folders. Also, instead of having the information per example twice, we only have the docstring, which is also written into the docs during building (new script for that). Since the code of some examples is long, the code is now collapsible.

Additionally, I added some quality of life fixes, such as a --plot flag with no plotting when running regularly (would crash in the base env) and unifying the naming inside the examples (all now use trajectory() for the reference and similar changes).

This PR turned out longer than intended. Most of it is just shifting things around though. If I should split this into multiple PRs, lmk.

@ratheron
ratheron requested a review from amacati October 13, 2026 21:19
@amacati

amacati commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

As we discussed before, the videos should not be included in this PR. We can add the CI job to generate them on the fly in a follow-up

@ratheron

Copy link
Copy Markdown
Collaborator Author

Done

Comment thread docs/examples/index.md
```{ .python notest }
--8<-- "examples/environments/figure8.py"
```
The runnable examples are grouped by topic, following the folders in `examples/`. Start with [hover](control.md#hover) if you're new, or jump to the group that matches your use case. Run an example from the repository root with `python examples/<group>/<script>.py`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The runnable examples are grouped by topic, following the folders in `examples/`. Start with [hover](control.md#hover) if you're new, or jump to the group that matches your use case. Run an example from the repository root with `python examples/<group>/<script>.py`.
The runnable examples are grouped by topic, following the folders in `examples/`. Start with [hover](control.md#hover) if you're new, or jump to the group that matches your use case. Run an example from the repository root with `pixi run python examples/<group>/<script>.py`.


The body rate controller keeps the attitude terms of the Mellinger controller, which level the
drone at its current yaw and counteract the commanded rates. The example sets their `kR` and `ki_m`
gains to zero to track the body rates.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gains to zero to track the body rates.
gains to zero to freely track the body rates.

commands = np.stack([trajectory(t) for t in times])
reference = commands[:, 0, 0, 0:3]
trajectory = [np.asarray(sim.data.states.pos[0, 0])]
positions = [np.asarray(sim.data.states.pos[0, 0])]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we fix unnecessary asarray uses while we are reworking the docs?

Comment on lines +3 to +4
The goal position is set through the reset options, and the `JaxToNumpy` wrapper converts between
NumPy actions and JAX observations.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The goal position is set through the reset options, and the `JaxToNumpy` wrapper converts between
NumPy actions and JAX observations.
The `JaxToNumpy` wrapper converts between NumPy actions and JAX observations.

Comment thread examples/jax/gradient.py

Because the simulator is built entirely from JAX operations, `jax.grad` can differentiate through
it. Starting the drone in the air keeps it away from the floor, so the floor-clipping stage never
fires and gradients flow freely through the entire trajectory.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fires and gradients flow freely through the entire trajectory.
applies and gradients flow freely through the entire trajectory.

Comment on lines +4 to +5
Two drones circle the hall center while facing each other. Requires splax
(`pip install "crazyflow[splats]"`) and a CUDA GPU.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Two drones circle the hall center while facing each other. Requires splax
(`pip install "crazyflow[splats]"`) and a CUDA GPU.
Requires splax (`pip install "crazyflow[splats]"`) and a CUDA GPU.

@@ -1,17 +1,22 @@
"""Animate the splat depth camera of a drone flying an elliptical lap through the flight hall.
"""Example where a drone flies a lap through a hall and renders gaussian splat depth images.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Example where a drone flies a lap through a hall and renders gaussian splat depth images.
"""Fly a lap through a hall and renders gaussian splat depth images.

Comment on lines +3 to +5
`build_render_splat_rgbd_fn` compiles an RGB-D renderer that is a pure function of `sim.data`. The
depth is measured along the optical axis and clipped to `max_range`. Requires splax
(`pip install "crazyflow[splats]"`) and a CUDA GPU.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`build_render_splat_rgbd_fn` compiles an RGB-D renderer that is a pure function of `sim.data`. The
depth is measured along the optical axis and clipped to `max_range`. Requires splax
(`pip install "crazyflow[splats]"`) and a CUDA GPU.
`build_render_splat_rgbd_fn` compiles an RGB-D renderer that is a pure function of `sim.data`.
Requires splax (`pip install "crazyflow[splats]"`) and a CUDA GPU.

Comment on lines +4 to +6
baseline pose, and its photometric error is differentiated over small z and yaw offsets. The
resulting gradients match the gradient of the squared pose error in sign and shape. Requires splax
(`pip install "crazyflow[splats]"`) and a CUDA GPU.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
baseline pose, and its photometric error is differentiated over small z and yaw offsets. The
resulting gradients match the gradient of the squared pose error in sign and shape. Requires splax
(`pip install "crazyflow[splats]"`) and a CUDA GPU.
baseline pose, and its photometric error is differentiated over small z and yaw offsets.
Requires splax (`pip install "crazyflow[splats]"`) and a CUDA GPU.

Comment on lines +63 to +70
def test_examples_in_docs():
"""Every example script has a section in the example docs, and every section has a script."""
directive = re.compile(r'^--8<-- example "examples/(.+)"$', re.MULTILINE)
pages = DOCS_EXAMPLES_DIR.glob("*.md")
documented = {path for page in pages for path in directive.findall(page.read_text())}
scripts = {path.relative_to(EXAMPLES_DIR).as_posix() for path in EXAMPLES_DIR.rglob("*.py")}
assert not scripts - documented, f"Missing from docs/examples: {sorted(scripts - documented)}"
assert not documented - scripts, f"Stale in docs/examples: {sorted(documented - scripts)}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here? We are already testing the examples outside the docs, aren't we?

This branch has not been deployed

No deployments
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