-
Notifications
You must be signed in to change notification settings - Fork 2
Add support for writing joystick data as action #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -45,6 +45,12 @@ class Episode: | |||||||||
| left_actions: ArrayLike = field(default_factory=list) | ||||||||||
| left_observation_timestamps: ArrayLike = field(default_factory=list) | ||||||||||
| left_observations: ArrayLike = field(default_factory=list) | ||||||||||
| joystick_x_timestamps: ArrayLike = field(default_factory=list) | ||||||||||
| joystick_xs: ArrayLike = field(default_factory=list) | ||||||||||
| joystick_y_timestamps: ArrayLike = field(default_factory=list) | ||||||||||
| joystick_ys: ArrayLike = field(default_factory=list) | ||||||||||
| joystick_button_timestamps: ArrayLike = field(default_factory=list) | ||||||||||
| joystick_buttons: ArrayLike = field(default_factory=list) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class EpisodeWriter: | ||||||||||
|
|
@@ -94,6 +100,24 @@ def finish(self): | |||||||||
| self._episode.left_observation_timestamps, | ||||||||||
| self._episode.left_observations, | ||||||||||
| ) | ||||||||||
| if self._episode.joystick_xs: | ||||||||||
| self._write_joystick_values( | ||||||||||
| self._base_directory / "action" / "joystick" / "x.parquet", | ||||||||||
| self._episode.joystick_x_timestamps, | ||||||||||
| self._episode.joystick_xs, | ||||||||||
| ) | ||||||||||
| if self._episode.joystick_ys: | ||||||||||
| self._write_joystick_values( | ||||||||||
| self._base_directory / "action" / "joystick" / "y.parquet", | ||||||||||
| self._episode.joystick_y_timestamps, | ||||||||||
| self._episode.joystick_ys, | ||||||||||
| ) | ||||||||||
| if self._episode.joystick_buttons: | ||||||||||
| self._write_joystick_values( | ||||||||||
| self._base_directory / "action" / "joystick" / "button.parquet", | ||||||||||
| self._episode.joystick_button_timestamps, | ||||||||||
| self._episode.joystick_buttons, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| def cancel(self): | ||||||||||
| """Cancel this episode.""" | ||||||||||
|
|
@@ -110,6 +134,16 @@ def _write_positions(self, output_path, timestamps, positions): | |||||||||
| ) | ||||||||||
| pq.write_table(table, output_path) | ||||||||||
|
|
||||||||||
| def _write_joystick_values(self, output_path, timestamps, values): | ||||||||||
| output_path.parent.mkdir(parents=True, exist_ok=True) | ||||||||||
| table = pa.table( | ||||||||||
| { | ||||||||||
| "timestamp": pa.array(timestamps, type=pa.timestamp("ns")), | ||||||||||
| "value": pa.concat_arrays(values), | ||||||||||
| } | ||||||||||
| ) | ||||||||||
| pq.write_table(table, output_path) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class DatasetWriter: | ||||||||||
| """Write a dataset.""" | ||||||||||
|
|
@@ -196,6 +230,7 @@ def _collect_dynamic_metadata(metadata, args, node): | |||||||||
| metadata["frequencies"] = { | ||||||||||
| "action": { | ||||||||||
| "arms": {}, | ||||||||||
| "joystick": {}, | ||||||||||
| }, | ||||||||||
| "obs": { | ||||||||||
| "arms": {}, | ||||||||||
|
|
@@ -213,6 +248,9 @@ def _collect_dynamic_metadata(metadata, args, node): | |||||||||
| if type == "observation": | ||||||||||
| type = "obs" | ||||||||||
| metadata["frequencies"][type]["arms"][side] = frequency | ||||||||||
| elif name.startswith("joystick_"): | ||||||||||
| target = name.split("_", 1)[1] | ||||||||||
| metadata["frequencies"]["joystick"][target] = frequency | ||||||||||
|
||||||||||
| metadata["frequencies"]["joystick"][target] = frequency | |
| metadata["frequencies"]["action"]["joystick"][target] = frequency |
Copilot
AI
Apr 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new joystick frequency mapping in _collect_dynamic_metadata isn’t covered by tests. Since this file already has pytest coverage for FrequencyDetector, consider adding a small test that builds a minimal node_config()/dataflow_descriptor() stub with a joystick_x (or similar) input and asserts the resulting metadata["frequencies"]["action"]["joystick"] entries, to prevent regressions like wrong nesting/KeyErrors.
| metadata["frequencies"]["joystick"][target] = frequency | |
| metadata["frequencies"]["action"]["joystick"][target] = frequency |
Copilot
AI
Apr 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that joystick streams are being recorded under action/joystick/*, the generated metadata['frequencies'] structure never includes joystick inputs (only arm_ and camera_). Consider extending _collect_dynamic_metadata to populate an action.joystick section (and include joystick inputs in the node config) so dataset consumers can discover joystick action rates consistently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Joystick action persistence is new behavior but there are no tests exercising
EpisodeWriter.finish()for the joystick streams (parquet written, row counts matching timestamps, expected schema/types). Since this module already has pytest coverage forFrequencyDetector, adding a small tempfile-based test would help prevent regressions.