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

registers: support writing axis acceleration value #337

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gudnimg
Copy link
Collaborator

@gudnimg gudnimg commented Dec 23, 2024

  • Add support for changing the acceleration of each axis (pulley, selector or idler)
  • The read operation now returns the actual used value instead of the maximum allowed acceleration value.
  • Significantly improve the accuracy of axis length measurement (Reduced truncation error produced by axisUnitToTruncatedUnit) by using floating point multiplication. This only costs 14 bytes of Flash.

Fixes #333

Change in memory:
Flash: +224 bytes
SRAM: 0 bytes

Copy link

github-actions bot commented Dec 23, 2024

All values in bytes. Δ Delta to base

ΔFlash ΔSRAM Used Flash Used SRAM Free Flash Free SRAM
224 0 28356 1667 316 893

@DRracer
Copy link
Collaborator

DRracer commented Dec 23, 2024

🤔 does it really work? I supposed we didn't have those runtime accelerations used in the code.

@3d-gussner 3d-gussner force-pushed the acceleration-registers branch from b97c64c to 0f4e7d6 Compare December 23, 2024 17:53
Copy link

github-actions bot commented Dec 23, 2024

Automated Test Code Coverage Report

View details...

File Lines Exec Cover
src/application.cpp 169 14 8%
src/application.h 2 0 0%
src/hal/circular_buffer.h 52 52 100%
src/hal/eeprom.h 1 0 0%
src/hal/gpio.h 18 7 38%
src/hal/progmem.h 6 6 100%
src/hal/tmc2130.cpp 113 9 7%
src/hal/tmc2130.h 30 12 40%
src/logic/command_base.cpp 133 19 14%
src/logic/command_base.h 4 2 50%
src/logic/cut_filament.cpp 115 0 0%
src/logic/eject_filament.cpp 76 0 0%
src/logic/feed_to_bondtech.cpp 58 0 0%
src/logic/feed_to_bondtech.h 1 0 0%
src/logic/feed_to_finda.cpp 48 0 0%
src/logic/feed_to_finda.h 1 0 0%
src/logic/home.cpp 18 0 0%
src/logic/load_filament.cpp 82 0 0%
src/logic/load_filament.h 1 0 0%
src/logic/move_selector.cpp 21 0 0%
src/logic/no_command.h 2 0 0%
src/logic/retract_from_finda.cpp 26 0 0%
src/logic/retract_from_finda.h 1 0 0%
src/logic/set_mode.cpp 5 0 0%
src/logic/set_mode.h 1 0 0%
src/logic/start_up.cpp 38 26 68%
src/logic/start_up.h 4 4 100%
src/logic/tool_change.cpp 105 0 0%
src/logic/unload_filament.cpp 73 0 0%
src/logic/unload_to_finda.cpp 39 0 0%
src/logic/unload_to_finda.h 1 0 0%
src/modules/axisunit.h 21 19 90%
src/modules/buttons.cpp 11 11 100%
src/modules/buttons.h 7 5 71%
src/modules/crc.h 13 13 100%
src/modules/debouncer.cpp 28 24 85%
src/modules/debouncer.h 7 1 14%
src/modules/finda.cpp 7 3 42%
src/modules/finda.h 2 0 0%
src/modules/fsensor.cpp 6 6 100%
src/modules/fsensor.h 3 0 0%
src/modules/globals.cpp 44 9 20%
src/modules/globals.h 34 1 2%
src/modules/idler.cpp 86 17 19%
src/modules/idler.h 12 0 0%
src/modules/leds.cpp 42 32 76%
src/modules/leds.h 16 9 56%
src/modules/math.h 6 6 100%
src/modules/motion.cpp 59 40 67%
src/modules/motion.h 66 61 92%
src/modules/movable_base.cpp 68 18 26%
src/modules/movable_base.h 16 5 31%
src/modules/permanent_storage.cpp 142 25 17%
src/modules/protocol.cpp 216 184 85%
src/modules/protocol.h 72 70 97%
src/modules/pulley.cpp 30 7 23%
src/modules/pulley.h 7 0 0%
src/modules/pulse_gen.cpp 95 89 93%
src/modules/pulse_gen.h 53 51 96%
src/modules/selector.cpp 66 24 36%
src/modules/selector.h 5 0 0%
src/modules/speed_table.h 26 24 92%
src/modules/user_input.cpp 38 36 94%
src/modules/user_input.h 12 12 100%
src/modules/voltage.cpp 4 0 0%
src/registers.cpp 113 37 32%
src/unit.h 12 10 83%
TOTAL 2689 1000 37%

TOTAL: 2689 lines of code, 1000 lines executed, 37% covered.

@3d-gussner
Copy link
Collaborator

This PR makes #334 obsolete, right?

@3d-gussner
Copy link
Collaborator

3d-gussner commented Dec 24, 2024

M708 A0x0e X790 is rejected.

tail -f .octoprint/logs/serial.log|grep -E "[<|>]Re|[<|>]We|[<|>]Rd|[<|>]Wd|M70"
2024-12-24 14:12:31,597 - Send: M707 A0x0e
2024-12-24 14:12:31,602 - Recv: echo:MMU2:>Re*fc.
2024-12-24 14:12:31,606 - Recv: echo:MMU2:<Re A320*dc.
2024-12-24 14:12:43,590 - Send: M708 A0x0e X790
2024-12-24 14:12:43,643 - Recv: echo:MMU2:>We 316*92.
2024-12-24 14:12:43,645 - Recv: echo:MMU2:<We R*ce.
2024-12-24 14:12:55,310 - Send: M707 A0x0e
2024-12-24 14:12:55,315 - Recv: echo:MMU2:>Re*fc.
2024-12-24 14:12:55,319 - Recv: echo:MMU2:<Re A320*dc.

while M708 A0x0d X94 is accepted

tail -f .octoprint/logs/serial.log|grep -E "[<|>]Re|[<|>]We|[<|>]Rd|[<|>]Wd|M70"
2024-12-24 14:14:42,665 - Send: M707 A0x0d
2024-12-24 14:14:42,669 - Recv: echo:MMU2:>Rd*41.
2024-12-24 14:14:42,673 - Recv: echo:MMU2:<Rd A5f*cf.
2024-12-24 14:14:46,727 - Send: M708 A0x0d X94
2024-12-24 14:14:46,733 - Recv: echo:MMU2:>Wd 5e*d5.
2024-12-24 14:14:46,736 - Recv: echo:MMU2:<Wd A*aa.
2024-12-24 14:14:48,918 - Send: M707 A0x0d
2024-12-24 14:14:48,923 - Recv: echo:MMU2:>Rd*41.
2024-12-24 14:14:48,925 - Recv: echo:MMU2:<Rd A5e*da.

The read operation now returns the actual used value instead of the maximum allowed acceleration value.

Change in memory:
Flash: + 78 bytes
SRAM: 0 bytes
@gudnimg gudnimg force-pushed the acceleration-registers branch from 0f4e7d6 to 75a5ba3 Compare December 24, 2024 13:46
@gudnimg
Copy link
Collaborator Author

gudnimg commented Dec 24, 2024

Rebased to sync with main. No functional changes made.

@gudnimg gudnimg marked this pull request as draft December 24, 2024 14:03
@gudnimg
Copy link
Collaborator Author

gudnimg commented Dec 24, 2024

M708 A0x0e X790 is rejected.

tail -f .octoprint/logs/serial.log|grep -E "[<|>]Re|[<|>]We|[<|>]Rd|[<|>]Wd|M70"
2024-12-24 14:12:31,597 - Send: M707 A0x0e
2024-12-24 14:12:31,602 - Recv: echo:MMU2:>Re*fc.
2024-12-24 14:12:31,606 - Recv: echo:MMU2:<Re A320*dc.
2024-12-24 14:12:43,590 - Send: M708 A0x0e X790
2024-12-24 14:12:43,643 - Recv: echo:MMU2:>We 316*92.
2024-12-24 14:12:43,645 - Recv: echo:MMU2:<We R*ce.
2024-12-24 14:12:55,310 - Send: M707 A0x0e
2024-12-24 14:12:55,315 - Recv: echo:MMU2:>Re*fc.
2024-12-24 14:12:55,319 - Recv: echo:MMU2:<Re A320*dc.

while M708 A0x0d X94 is accepted

tail -f .octoprint/logs/serial.log|grep -E "[<|>]Re|[<|>]We|[<|>]Rd|[<|>]Wd|M70"
2024-12-24 14:14:42,665 - Send: M707 A0x0d
2024-12-24 14:14:42,669 - Recv: echo:MMU2:>Rd*41.
2024-12-24 14:14:42,673 - Recv: echo:MMU2:<Rd A5f*cf.
2024-12-24 14:14:46,727 - Send: M708 A0x0d X94
2024-12-24 14:14:46,733 - Recv: echo:MMU2:>Wd 5e*d5.
2024-12-24 14:14:46,736 - Recv: echo:MMU2:<Wd A*aa.
2024-12-24 14:14:48,918 - Send: M707 A0x0d
2024-12-24 14:14:48,923 - Recv: echo:MMU2:>Rd*41.
2024-12-24 14:14:48,925 - Recv: echo:MMU2:<Rd A5e*da.

@3d-gussner If you find time, can you double check you were using the correct firmware? I don't see how the write can be rejected. It should work now when we have a 'write' function defined.

I'll see if I can test this on my MK4S today or tomorrow.

For reference, this is the function which determines if its accepted or rejected. False means Rejected.

image

When reading or setting the value, the driver is expecting steps_t which is a axis scaled value.

This increases the memory footprint quite a bit. But now if you set 800mm/s2, you should get a similar value back.

Flash: +132 bytes
SRAM: 0 bytes
When converting 800mm/s2, it would be truncated to 795mm/s2 for the pulley. This is due to cutting out significant decimal digits.

Instead let's multiply in floating point, this needs quite a bit of resources. So to optimise against this, multiply with the recoprical. Then the cost is not more than 20 bytes.

Testing:
M707 A0x0e; Read Pulley Acceleration (default at boot up is 800mm/s2)
M708 A0x0e X790 ; Set Pulley Acceleration to 790mm/s2
M707 A0x0e; Read Pulley Acceleration (should be 790mm/s2)

The results before this commit:

M707 A0x0e -> returns 805
M708 A0x0e X790 ; Set Pulley Acceleration to 790mm/s2
M707 A0x0e; returns 795

After this commit:

M707 A0x0e -> returns 799
M708 A0x0e X790 ; Set Pulley Acceleration to 790mm/s2
M707 A0x0e; returns 789

NOTE:
axisUnitToTruncatedUnit is used in Idler homing, selector homing, and pulley positioning. I am not sure yet how this improvement will affect those areas.
@gudnimg
Copy link
Collaborator Author

gudnimg commented Dec 25, 2024

The unit tests need updating after the last commit, they encounter timeout since the tests don’t expect to see homing fail. For the acceleration registers this improved accuracy is only cosmetic. But it does impact idler/selector homing. I will continue to work on the unit tests to see if I can improve things.

I don’t see any homing issues on real hardware.

Writing and reading the acceleration registers work well on my end.

@3d-gussner
Copy link
Collaborator

@gudnimg After adding few more debug lines I can confirm that changing the accel register works. Thanks for the commit comment that writing 800 results in reading 799. ✔️

Lot of the tests are still failing. 🚧
Reducing the --timeout from 180 to 10 may has some false positive fails (protocol::WriteRequest 17.78 sec and protocol::ReadResponse Test time = 43.58 sec on my PC) but it is way faster to find which are failing.

@gudnimg
Copy link
Collaborator Author

gudnimg commented Dec 27, 2024

I can move aa20e01 into a separate PR. It is not strictly necessary for supporting writing acceleration register. Its only the read value which will be off by a few mm/s2.

Not sure how long it will take to resolve the unit tests. Its not trivial.

@gudnimg
Copy link
Collaborator Author

gudnimg commented Dec 27, 2024

I plotted the trunction error produced by axisUnitToTruncatedUnit for axis length. It looks like the idler is most affected by this, and can be off by ~25° at the axis limits!

Pulley:

pulley

Selector:

selector

Idler:

idler

@3d-gussner
Copy link
Collaborator

25° is a lot as we have 40° between two slots. On the MMU12x this not possible as there is 25.4° between the slots.

The idler is only put on hold, and resumed after a user event is seen.

We must ensure the idler is engaged before feeding to FINDA.
We never home Idler and Selector at the same time. I think we did early perhaps, but now the selector always waits
for the idler homing to be valid.
Add handling for HomingFailed which can cause the tests
to timeout.

Add checks for HomeForward and HomeBack
Before, the axis limits had an error of 25° so 225° would actually be measured as 250°.

Now after fixing axisUnitToTruncatedUnit to return a more accurate value, the new values are lower. Adjust the distances by 20° to offset previous error.
@gudnimg
Copy link
Collaborator Author

gudnimg commented Dec 27, 2024

Now the unit tests pass :)

@gudnimg gudnimg marked this pull request as ready for review December 27, 2024 22:51
@@ -64,7 +64,7 @@ void Idler::FinishMove() {
}

bool Idler::StallGuardAllowed(bool forward) const {
const uint8_t checkDistance = forward ? 220 : 200;
const uint8_t checkDistance = forward ? 200 : 180;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wonder if we can tighten these values closer to 225°

@DRracer
Copy link
Collaborator

DRracer commented Jan 2, 2025

So, it's working nicely on the real HW ... actually it's funny to watch very slow accelerations.
I'm still not entirely happy with the changes done to the unit tests, please hold on

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.

Write tor acceletation registers not possible.
3 participants