Update tutorial action switch frequency#345
Merged
Merged
Conversation
Update the create_robot and create_sensor tutorial scripts to use an explicit action switch interval and add a regression test for the shared cadence.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the simulation tutorial loops in create_robot.py and create_sensor.py to use an explicit shared ACTION_SWITCH_INTERVAL (and a derived cycle length) instead of hard-coded modulo conditions, and adds a regression test intended to keep that interval consistent.
Changes:
- Introduces
ACTION_SWITCH_INTERVALandACTION_CYCLE_STEPS, and refactors loop conditionals to usecycle_step. - Adjusts the tutorials’ action switch cadence to a consistent interval-based schedule.
- Adds a test that parses the tutorial scripts to validate the expected interval constant.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| scripts/tutorials/sim/create_robot.py | Refactors action switching logic to use shared interval/cycle constants. |
| scripts/tutorials/sim/create_sensor.py | Refactors action switching logic to use shared interval/cycle constants (and triggers sensor capture on switches). |
| tests/sim/test_tutorial_action_switch_frequency.py | Adds a regression test for the tutorial action switch interval constant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| CONTROL_PARTS = { | ||
| "arm": [ | ||
| "JOINT[1-6]", # Matches JOINT1, JOINT2, ..., JOINT6 | ||
| "joint[1-6]", # Matches JOINT1, JOINT2, ..., JOINT6 |
| CONTROL_PARTS = { | ||
| "arm": [ | ||
| "JOINT[1-6]", # Matches JOINT1, JOINT2, ..., JOINT6 | ||
| "joint[1-6]", # Matches JOINT1, JOINT2, ..., JOINT6 |
Comment on lines
+39
to
+56
|
|
||
|
|
||
| def test_create_robot_tutorial_uses_shared_action_switch_interval() -> None: | ||
| module = _parse_module("create_robot.py") | ||
|
|
||
| assert ( | ||
| _find_constant_value(module, "ACTION_SWITCH_INTERVAL") | ||
| == EXPECTED_ACTION_SWITCH_INTERVAL | ||
| ) | ||
|
|
||
|
|
||
| def test_create_sensor_tutorial_uses_shared_action_switch_interval() -> None: | ||
| module = _parse_module("create_sensor.py") | ||
|
|
||
| assert ( | ||
| _find_constant_value(module, "ACTION_SWITCH_INTERVAL") | ||
| == EXPECTED_ACTION_SWITCH_INTERVAL | ||
| ) |
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR updates the
scripts/tutorials/sim/create_robot.pyandscripts/tutorials/sim/create_sensor.pytutorials to use an explicit shared action-switch interval, instead of hard-coded modulo values in the simulation loop.It also adds a regression test to verify that both tutorial scripts keep the expected switch interval constant.
Dependencies: None.
Issue reference: None.
Type of change
Screenshots
Not applicable.
Checklist
black .command to format the code base.Verification
pytest tests/sim/test_tutorial_action_switch_frequency.py -v2 passed in 1.38s