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

added sweeping compatibility #179

Merged
merged 4 commits into from
Dec 22, 2024
Merged

Conversation

Frix-x
Copy link
Owner

@Frix-x Frix-x commented Dec 22, 2024

Summary by Sourcery

Add support for sweeping vibration tests during resonance measurements.

New Features:

  • Introduce a sweeping motion during vibration tests to reduce noise and improve resonance peak identification.

Tests:

  • Update resonance tests to use the new sweeping vibration generator.

Copy link

sourcery-ai bot commented Dec 22, 2024

Reviewer's Guide by Sourcery

This pull request introduces sweeping compatibility to the resonance tester, enabling a new vibration test mode that adds a slow sweep motion to the existing pulse test. This helps to reduce noise and isolate the primary resonance frequency, especially useful for less rigid machines. It also includes a static frequency vibration generator for maintaining a fixed vibration frequency over a specified duration.

Sequence diagram for resonance testing with sweep mode

sequenceDiagram
    participant User
    participant Printer
    participant ResonanceTester
    participant Accelerometer

    User->>ResonanceTester: Start resonance test
    ResonanceTester->>Printer: Configure test parameters
    ResonanceTester->>Accelerometer: Start recording
    loop Sweep Test
        ResonanceTester->>Printer: Apply vibration with sweep motion
        Printer-->>Accelerometer: Measure vibrations
    end
    ResonanceTester->>Accelerometer: Stop recording
    Accelerometer-->>ResonanceTester: Return measurements
    ResonanceTester-->>User: Display results
Loading

State diagram for resonance testing modes

stateDiagram-v2
    [*] --> TestSelection
    TestSelection --> PulseOnly: Choose pulse-only
    TestSelection --> SweepMode: Choose sweep mode

    state PulseOnly {
        [*] --> FixedPosition
        FixedPosition --> Vibrating
        Vibrating --> DataCollection
        DataCollection --> [*]
    }

    state SweepMode {
        [*] --> SlowSweep
        SlowSweep --> Vibrating
        Vibrating --> NoiseReduction
        NoiseReduction --> DataCollection
        DataCollection --> [*]
    }

    note right of PulseOnly: Better for diagnostic
    note right of SweepMode: Better for final tuning
Loading

File-Level Changes

Change Details Files
Introduced a sweeping vibration test mode and a static frequency vibration generator.
  • Added SweepingVibrationGenerator class to implement the sweeping test logic.
  • Added StaticFrequencyVibrationGenerator class for fixed frequency vibration tests.
  • Added ResonanceTestManager class to manage and execute different test types, handling compatibility with older Klipper versions.
  • Refactored vibrate_axis and vibrate_axis_at_static_freq functions to use the ResonanceTestManager.
shaketune/helpers/resonance_test.py
Updated documentation to explain the new sweeping test mode.
  • Added a section explaining the benefits and usage of the sweeping test.
docs/is_tuning_generalities.md
Updated command implementations to use the new resonance test manager.
  • Modified calls to vibrate_axis to pass the res_tester object, enabling the use of the new test modes.
shaketune/commands/axes_shaper_calibration.py
shaketune/commands/compare_belts_responses.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Frix-x - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider consolidating the parameter handling logic between BaseVibrationGenerator and SweepingVibrationGenerator to reduce code duplication in the prepare_test methods.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 5 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

self.accel_per_hz = accel_per_hz
self.hz_per_sec = hz_per_sec
self.freq_start = min_freq
self.freq_end = max_freq
Copy link

Choose a reason for hiding this comment

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

issue (testing): Missing tests for the new classes and methods

The new BaseVibrationGenerator, SweepingVibrationGenerator, StaticFrequencyVibrationGenerator, and ResonanceTestManager classes, along with their methods, lack dedicated unit tests. It's crucial to add tests verifying their behavior, especially edge cases like zero frequency, zero acceleration, invalid axis directions, and interactions with the toolhead and gcode objects. Consider mocking these dependencies for isolated testing.

shaketune/helpers/resonance_test.py Show resolved Hide resolved
shaketune/helpers/resonance_test.py Show resolved Hide resolved
shaketune/helpers/resonance_test.py Show resolved Hide resolved
shaketune/helpers/resonance_test.py Show resolved Hide resolved
@@ -37,6 +37,12 @@ While you should usually try to focus on the toolhead/belts mechanical subsystem
1. **Diagnosis phase**: Begin with the nozzle tip mount to identify and troubleshoot mechanical issues to ensure the printer components are healthy and the assembly is well done and optimized.
1. **Filter selection phase**: If the graphs are mostly clean, you can transition to a mounting point near the toolhead's center of gravity for cleaner data on the main resonance, facilitating accurate Input Shaping filter settings. You can also consider the CANBus integrated accelerometer for its simplicity, especially if the toolhead is particularly rigid and minimally affected by wobble.

### Should I user the sweeping or pulse-only test?
Copy link

Choose a reason for hiding this comment

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

issue (typo): Typo: "user" should be "use".

Suggested change
### Should I user the sweeping or pulse-only test?
### Should I use the sweeping or pulse-only test?

Comment on lines +221 to +225
if test_seq:
max_accel = max(abs(a) for _, a, _ in test_seq)
else:
max_accel = old_max_accel # no moves, just default

Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): We've found these issues:

  • Replace if statement with if expression (assign-if-exp)
  • Low code quality found in ResonanceTestManager._run_test_sequence - 12% (low-code-quality)
Suggested change
if test_seq:
max_accel = max(abs(a) for _, a, _ in test_seq)
else:
max_accel = old_max_accel # no moves, just default
max_accel = max(abs(a) for _, a, _ in test_seq) if test_seq else old_max_accel


Explanation
The quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

@Frix-x Frix-x merged commit bcccdf0 into fix-sweeping-compat Dec 22, 2024
9 checks passed
@Frix-x Frix-x deleted the fix-sweeping-compat-2 branch December 22, 2024 20:37
Frix-x added a commit that referenced this pull request Dec 22, 2024
* fixed compatibility with the new version of Klipper for pulse-only test

* added sweeping compatibility (#179)

* added documentation about sweeping mode
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.

1 participant