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 clunking sound from solenoids (#15) #203

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jonathanperret
Copy link
Contributor

@jonathanperret jonathanperret commented Sep 30, 2024

Problem

Fixes #15.

Proposed solution

The "clunking" sound that is occasionnally heard when using AYAB is caused by all solenoid armatures being released simultaneously when all solenoids are turned off.

This does not happen with Brother electronics because they default to keeping solenoids on.

This PR changes AYAB's behavior to match that behavior of the Brother electronics.

Note that this required abandoning the third-party library used to drive the I/O expanders (Adafruit_MCP23008) since
part of its non-skippable initialization code was forcing all outputs to off. It turns out the amount of code needed to directly drive the MCP23008 expanders using the Arduino Wire library is only a dozen lines of code anyway.

Summary by CodeRabbit

Release Notes

  • New Features

    • Removed dependency on the Adafruit MCP23008 library, streamlining solenoid control.
  • Bug Fixes

    • Updated solenoid initialization to ensure all solenoids remain ON by default, preventing noise during operation.
  • Tests

    • Adjusted initial state assertion in solenoid tests to reflect new default state of 0xffffU.
  • Chores

    • Cleaned up build configuration by removing unused library references from test setup.

@jonathanperret jonathanperret self-assigned this Sep 30, 2024
Copy link

coderabbitai bot commented Sep 30, 2024

Walkthrough

The pull request introduces several changes primarily focused on the removal of the Adafruit MCP23008 library and its associated functionality. The .gitmodules file reflects the removal of the library reference, while the codebase has been updated to eliminate dependencies on this library. The solenoid control logic has been altered to utilize I2C communication directly, with changes to method signatures and the introduction of new methods for GPIO operations. Additionally, build configurations have been streamlined by removing unused variables and references.

Changes

Files Change Summary
.gitmodules Removed submodule reference for libraries/Adafruit_MCP23008; libraries/PacketSerial unchanged.
lib/Adafruit_MCP23008 Removed subproject commit related to the Adafruit MCP23008 library.
src/ayab/solenoids.cpp Modified solenoid control logic to utilize I2C directly; updated method signatures and added new methods.
src/ayab/solenoids.h Removed Adafruit MCP23008 library inclusion; modified variable initialization and added new methods.
static_analysis.sh Corrected path for the Wire library in clang-tidy command line arguments.
test/CMakeLists.txt Removed unused external library variables and adjusted build configuration for test executables.
test/test_solenoids.cpp Updated initial state assertion for solenoidState in test cases.

Assessment against linked issues

Objective Addressed Explanation
Clunking sound from the solenoids (Issue #15) The changes do not address the clunking sound issue directly.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 78468f9 and 90a296c.

📒 Files selected for processing (7)
  • .gitmodules (1 hunks)
  • lib/Adafruit_MCP23008 (0 hunks)
  • src/ayab/solenoids.cpp (5 hunks)
  • src/ayab/solenoids.h (1 hunks)
  • static_analysis.sh (1 hunks)
  • test/CMakeLists.txt (0 hunks)
  • test/test_solenoids.cpp (1 hunks)
💤 Files with no reviewable changes (2)
  • lib/Adafruit_MCP23008
  • test/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (5)
  • .gitmodules
  • src/ayab/solenoids.cpp
  • src/ayab/solenoids.h
  • static_analysis.sh
  • test/test_solenoids.cpp

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@jonathanperret jonathanperret added this to the 1.0.0 milestone Sep 30, 2024
Copy link

@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: 4

🧹 Outside diff range and nitpick comments (2)
test/test_solenoids.cpp (1)

53-53: Approved: Initial solenoid state change aligns with PR objectives.

This change correctly updates the test to expect all solenoids to be active (0xffffU) upon initialization, which aligns with the PR objective of preventing the clunking sound by keeping solenoids engaged by default. This new behavior mimics the Brother electronics as described in the PR summary.

Consider adding the following additional tests to ensure comprehensive coverage of the new behavior:

  1. Test turning off specific solenoids and verify they remain off.
  2. Test turning all solenoids off and ensure they don't produce the clunking sound (you may need to mock the hardware interaction for this).
  3. Test the behavior when restarting a pattern to ensure solenoids remain engaged.

These additional tests will help validate that the new implementation correctly addresses the issue in various scenarios.

src/ayab/solenoids.cpp (1)

28-34: Use constexpr instead of #define for constants

Using constexpr variables provides type safety and better scoping compared to preprocessor #define directives.

Consider changing the macros to constexpr constants:

-#define MCP23008_ADDRESS 0x20
-#define MCP23008_IODIR 0x00
-#define MCP23008_GPIO 0x09
+constexpr uint8_t MCP23008_ADDRESS = 0x20;
+constexpr uint8_t MCP23008_IODIR = 0x00;
+constexpr uint8_t MCP23008_GPIO = 0x09;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 85d0842 and 1135e26.

📒 Files selected for processing (7)
  • .gitmodules (1 hunks)
  • lib/Adafruit_MCP23008 (0 hunks)
  • src/ayab/solenoids.cpp (5 hunks)
  • src/ayab/solenoids.h (1 hunks)
  • static_analysis.sh (1 hunks)
  • test/CMakeLists.txt (0 hunks)
  • test/test_solenoids.cpp (1 hunks)
💤 Files with no reviewable changes (2)
  • lib/Adafruit_MCP23008
  • test/CMakeLists.txt
🔇 Additional comments (2)
.gitmodules (1)

1-3: LGTM! Removal of Adafruit_MCP23008 submodule aligns with PR objectives.

The removal of the Adafruit_MCP23008 submodule from the .gitmodules file is in line with the PR objectives. This change:

  1. Addresses the clunking sound issue by removing the library that was forcing all outputs to turn off.
  2. Simplifies the codebase by eliminating a third-party dependency.
  3. Allows for direct control of the MCP23008 expanders using the Arduino Wire library.

The remaining PacketSerial submodule is unchanged, which is appropriate if it's still needed for the project.

Let's verify that the Adafruit_MCP23008 library has been completely removed from the project:

src/ayab/solenoids.cpp (1)

107-110: LGTM: Correct implementation of writeGPIO method

The writeGPIO function correctly writes the lower and higher bytes of the solenoid state to the appropriate I2C addresses, ensuring proper control over the solenoids.

src/ayab/solenoids.h Show resolved Hide resolved
src/ayab/solenoids.h Outdated Show resolved Hide resolved
src/ayab/solenoids.cpp Show resolved Hide resolved
src/ayab/solenoids.cpp Show resolved Hide resolved
The "clunking" sound that is occasionnally heard when using AYAB
is caused by all solenoid armatures being released simultaneously
when all solenoids are turned off.

This does not happen with Brother electronics because they default
to keeping solenoids on.

This commit changes AYAB's behavior to match that behavior of the
Brother electronics. Note that this required abandoning the third-party
library used to drive the I/O expanders (Adafruit_MCP23008) since
part of its non-skippable initialization code was forcing all outputs
to off. It turns out the amount of code needed to directly drive the
MCP23008 expanders using the Arduino Wire library is only a dozen
lines of code anyway.

Fixes AllYarnsAreBeautiful#15.
@jonathanperret jonathanperret removed this from the 1.0.0 milestone Sep 30, 2024
@dl1com dl1com added this to the next milestone Sep 30, 2024
@VIPQualityPost
Copy link

So much clutter from coderabbit here... is there some action item from me? Or why am I marked for review?

@jonathanperret jonathanperret removed the request for review from VIPQualityPost October 4, 2024 08:07
@jonathanperret
Copy link
Contributor Author

So much clutter from coderabbit here... is there some action item from me? Or why am I marked for review?

Sorry, I thought you might be interested in looking at this, but no action is required. Agree that coderabbit is a bit much.

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.

Clunking sound from the solenoids
3 participants