Skip to content
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

Fix hardware test dialog #693

Merged
merged 12 commits into from
Aug 13, 2024

Conversation

jonathanperret
Copy link
Contributor

@jonathanperret jonathanperret commented Jul 30, 2024

This PR fixes the hardware test dialog, in simulation as well as with an actual Arduino connected. Note that this requires a recent firmware build as stack overflow issues prevented the firmware from reliably entering test mode without crashing.

Summary by CodeRabbit

  • New Features

    • Introduced new command options including setSingleCmd, setAllCmd, readEOLsensorsCmd, readEncodersCmd, autoReadCmd, and autoTestCmd.
    • Expanded the command list in the Hardware Test Dialog to improve user interaction with new functionalities.
  • Bug Fixes

    • Enhanced error handling in the write_API6 method to prevent potential issues when the serial connection is invalid.
  • Improvements

    • Streamlined command handling methods for better clarity and functionality.
    • Updated button interactions to support new commands and improve usability.

The engine would get stuck in RUN_TEST state waiting for a message
from the firmware that might never come. And there would be no way
to exit that waiting loop from the UI.

By returning to the main loop, we give the UI a chance to exit test
mode.
The previous code waited for an `indState` message but the current
firmware doesn't seem to be sending this. So the REQUEST_TEST state
only has to emit `reqTest` and transition to CONFIRM_TEST. Maybe the
state could be removed entirely.
The firmware definitely expects all commands to be wrapped in SLIP
packets.
The write_API6 method is only used by the hardware test commands,
this is why this oversight went undetected.
There was a race condition caused by `HardwareTestDialog.reject` trying to end testing
by forcing `__control.state` to `FINISHED` from the UI thread.
If this occurred as the thread was about to enter `Control.operate`, the
engine FSM would immediately jump from state `FINISHED` to state
`CONNECT`, so `Engine.run` would never
get a chance to notice the `FINISHED` state and exit its processing loop.

This was causing random hangs when exiting the hardware test dialog.

By making `FINISHED` a "dead-end" state, we make sure `Engine.run` eventually exits its
loop, and the thread terminates.
There is no such property. The statement was always raising an error that was silently ignored.
Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Walkthrough

The recent changes enhance command management and error handling in the Ayab engine's communication and FSM components. The Token enumeration has been reorganized and expanded, while the write_API6 method now accepts a broader data type, improving robustness. Simplifications in the FSM methods streamline control flow, and updates to command handling in the mock and hardware test files improve clarity and user interaction. Overall, these modifications refine the system's functionality and usability.

Changes

Files Change Summary
src/main/python/main/ayab/engine/communication.py Updated Token enumeration with new commands and redefined existing ones. Altered write_API6 to accept `bytes
src/main/python/main/ayab/engine/engine_fsm.py Simplified _API6_request_test, _API6_run_test, and _API6_finished methods, removing error handling and streamlining control flow.
src/main/python/main/ayab/engine/hw_test_communication_mock.py Renamed command handling methods for clarity, simplified implementations, and standardized command outputs, enhancing semantic understanding.
src/main/python/main/ayab/hw_test.py Expanded commands list, updated button handling and dialog interactions, and aligned with new command structures for improved user experience.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2e4adef and 8e45d02.

Files selected for processing (4)
  • src/main/python/main/ayab/engine/communication.py (2 hunks)
  • src/main/python/main/ayab/engine/engine_fsm.py (2 hunks)
  • src/main/python/main/ayab/engine/hw_test_communication_mock.py (4 hunks)
  • src/main/python/main/ayab/hw_test.py (4 hunks)
Additional comments not posted (17)
src/main/python/main/ayab/engine/hw_test_communication_mock.py (7)

53-53: LGTM! Enhanced debugging information.

The added output message improves the debugging information by indicating the called command.


74-84: LGTM! Improved command help output.

The updated help command output includes new commands and standardizes the format, enhancing clarity and consistency.


92-95: LGTM! Improved method clarity and maintainability.

The method renaming and simplification enhance clarity and maintainability.


100-101: LGTM! Improved method clarity and maintainability.

The method renaming and simplification enhance clarity and maintainability.


103-104: LGTM! Improved method clarity and maintainability.

The method renaming and simplification enhance clarity and maintainability.


106-108: LGTM! Clear mechanism to stop auto-read and auto-test functionalities.

The new method provides a clear mechanism to disable auto-read and auto-test functionalities, enhancing clarity and maintainability.


Line range hint 114-136: LGTM! Improved method clarity and robustness.

The method renaming and additional validation enhance clarity and robustness.

src/main/python/main/ayab/hw_test.py (5)

46-58: LGTM! Updated commands list.

The updated commands list reflects the new command structure and improves clarity by removing unused commands.


80-89: LGTM! Simplified button creation logic.

The updated button creation logic simplifies the process and ensures proper configuration.


145-146: LGTM! Proper state reset for autoRead and autoTest buttons.

The updated reject method ensures proper state reset for the autoRead and autoTest buttons.


156-163: LGTM! Enhanced control flow for button interactions.

The updated __button_pushed method enhances control flow by allowing a more dynamic response to button states.


169-171: LGTM! Aligned with new command structure.

The updated __set_solenoid method aligns with the new command structure and ensures proper command handling.

src/main/python/main/ayab/engine/communication.py (2)

50-60: LGTM! Updated Token enumeration.

The updated Token enumeration reflects a logical restructuring of command identifiers, suggesting a potential expansion of functionality or reorganization of command handling.


245-249: LGTM! Enhanced robustness and flexibility in write_API6 method.

The modified write_API6 method enhances robustness by allowing greater flexibility in the types of data that can be passed and ensuring proper operation under different conditions.

src/main/python/main/ayab/engine/engine_fsm.py (3)

208-210: Verify robustness of the simplified _API6_request_test method.

The method has been simplified to directly call control.com.req_test_API6(), set the state to State.CONFIRM_TEST, and log the state change. Ensure that control.com.req_test_API6() handles all necessary checks and error reporting internally to maintain robustness.


235-237: Verify processing of test results in _API6_run_test.

The method has been simplified to call control.check_serial_API6() without any conditional checks or loops. Ensure that control.check_serial_API6() processes all incoming messages and handles necessary actions to maintain the correct processing of test results.


237-239: Verify impact of removed exception handling and state transition in _API6_finished.

The method has removed exception handling around stopping the timer and the state transition to State.CONNECT. Ensure that the timer's state is no longer critical at this point in the flow and that the cleanup process is handled correctly without these elements.

@X-sam
Copy link
Member

X-sam commented Aug 10, 2024

Looks good and works well, thanks for getting this sorted!
Some comments-
Beep doesn't seem to work (I assume that's a problem for ayab-firmware though)
We need to add a stop button to the dialog- while quit does issue stop, it's kinda annoying to have to reopen the window if you want to switch test commands.
Quit should probably be Close, as it's a modal not its own app.

@jonathanperret
Copy link
Contributor Author

jonathanperret commented Aug 11, 2024

Looks good and works well, thanks for getting this sorted! Some comments- Beep doesn't seem to work (I assume that's a problem for ayab-firmware though)

It is, I’ll look into it over there.

We need to add a stop button to the dialog- while quit does issue stop, it's kinda annoying to have to reopen the window if you want to switch test commands.

If you’re talking about the “autoXxx” buttons, they’re supposed to stay highlighted while that test is running, and you can stop the test (i.e. emit stopCmd) by re-clicking the same button to toggle it. Isn’t that happening for you?

Quit should probably be Close, as it's a modal not its own app.

Good catch, I’ll fix this.

@X-sam
Copy link
Member

X-sam commented Aug 11, 2024 via email

Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8e45d02 and 76aaac5.

Files selected for processing (1)
  • src/main/python/main/ayab/hw_test.py (4 hunks)
Additional comments not posted (4)
src/main/python/main/ayab/hw_test.py (4)

46-55: LGTM: Expanded commands list.

The addition of new commands (readEOLsensors, readEncoders, autoRead, autoTest) enhances the functionality of the hardware test dialog as intended.


77-87: LGTM: Improved button creation process.

The direct instantiation of buttons and the use of setAutoDefault(False) enhance the clarity and functionality of the button creation process.


153-160: LGTM: Enhanced button action handling.

The updates to handle checkable buttons and the new commands improve the user interaction and feedback within the dialog.


166-168: LGTM: Improved solenoid control operation.

The change to setSingle and the use of Token.setSingleCmd.value enhance the specificity and clarity of solenoid operations.

@jonathanperret
Copy link
Contributor Author

Quit should probably be Close, as it's a modal not its own app.

Good catch, I’ll fix this.

On second thought… I didn't have the dialog in front of me when I replied, sorry. quit here is one of the test command buttons, the command is called quit in the API so it would be inconsistent to call it close IMHO. It's not even in the proper place for a dialog "Close" button. I'll concede that the fact it also closes the window is somewhat confusing. Though the window can always be closed using the regular close button in the title bar.

Likewise with the autoTest/autoRead buttons, I agree it's not very discoverable that they are toggles.

The thing is, I didn't design any of this UI. I just tried to make it work while changing as little of it as possible, because I'm afraid tweaking the UI is not going to help us get a release out soon.

How about using this as it is now for the next release, it can't be worse than the current broken test mode that simply hangs?

@X-sam
Copy link
Member

X-sam commented Aug 11, 2024 via email

Copy link
Member

@X-sam X-sam left a comment

Choose a reason for hiding this comment

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

This working is super helpful for debugging, turns out!

@dl1com dl1com merged commit 889c638 into AllYarnsAreBeautiful:1.0.0-dev Aug 13, 2024
2 checks passed
@jonathanperret jonathanperret deleted the fix-hw-test branch August 14, 2024 06:51
@jonathanperret
Copy link
Contributor Author

  • Beep doesn't seem to work (I assume that's a problem for ayab-firmware though)

@X-sam the fix for this is here, enjoy: AllYarnsAreBeautiful/ayab-firmware#199

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.

3 participants