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

Normalising Fan PWM power #6307

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

Conversation

kubaracek
Copy link

@kubaracek kubaracek commented Aug 1, 2023

What this does

It makes it possible to set 1% for a fan such as CPAP with a large off_below value and the fan will run at its lowest power at this setting

image

Why

Fans with quite high value for off_below (CPAP for example) are currently in klipper bit tricky to operate and people use several tricks either in slicer/gcode/macros to scale the values as requesting a 10% fan for cpap that might start at 16% or 30% gets ignored by klipper and fan stays off. When fan is properly configured in klipper and I request a fan to run at 1% of its speed I expect it to actually move, which is not the case currently. So the slicer/gcode needs to have a 'low level' knowledge of my hardware (when my fan actually will kick-in).

The value is actually currently partially scaled but between 0 and max_power. It's a bit odd.

How

This normalises the value between off_below and max_power.
When off_below would be set to 0.3 and max_power to 1.0 a 10% increment would have a value of 0.7 so requesting 10% of a fan will result in a value of off_below + 0.7 = 0.37 and not 0.1 as it does currently which effectively has no effect.

Normalizing the value according to fan setting such that the CPAP and similar fans will kick in even at 1% so the whole range can be used in same fashion as with any other fan where off_below=0

Note

These two notes bellow were addressed by renaming the parameter.

When testing this. Mainsail has a logic in place where they use off_below as a minimal setting for the fan using the fan slider, so setting the fan to say 2% will automatically set it to 30%
I will create a separate PR in Mainsail to remove this logic as it will no longer be needed.

After such update, users with off_below > 0 who will not change their M106 to lower the value will have their fans a bit louder, heh. They will generaly expect that their cpap might kick-in at around 16-30% so that's what they will have their lowest value set to in slicer and such. After the update it will be an actual 16-30% fan speed.

@kubaracek kubaracek changed the title Fan PWM power scaling Normalising Fan PWM power Aug 1, 2023
@JamesH1978
Copy link
Collaborator

Thank you for submitting a PR, please could you refer to point 3 in the "what to expect" section in https://github.com/Klipper3d/klipper/blob/master/docs/CONTRIBUTING.md and add a signed-off-by line.

Also you need to fix your whitespaces/length of line to pass build checks

Thanks
James

@kubaracek kubaracek force-pushed the feat/pwm-scaling branch 3 times, most recently from 14cbd54 to f46d357 Compare August 1, 2023 20:08
@kubaracek
Copy link
Author

kubaracek commented Aug 1, 2023

@JamesH1978 It should be fine now. Let me just test everything once more and I think it's ready unless you have some objections.

@Sineos
Copy link
Collaborator

Sineos commented Aug 1, 2023

You might want to cross check with:
#5360
#4720
#3937
#3208
#2165

@kubaracek
Copy link
Author

kubaracek commented Aug 1, 2023

@Sineos Thanks. I looked into the implementations and they modify a lot the 'input' value parameter which then stores scaled value as last_value. This would cause troubles for say Mainsail and other UIs as if you set a slider to say 10% it would get translated to 50% if that makes sense. So the slider would be just jumping around. I'm only changing what actually goes to self.mcu_fan.set_pwm function and leave the input value unchanged. Which also keeps the logic of kickstarting.

Renaming the value if we decide not to keep it to min_power would make sense though

I'm also inviting @dewi-ni-je for hopefully final discussion! As he seems to be the most vocal about the change :))
Ah I cannot invite him, maybe he's inactive?

@kubaracek
Copy link
Author

kubaracek commented Aug 1, 2023

I went though the discussions again. It doesn't seem like anybody has a problem with this per-se more so the way it was implemented that there were too many variables.

So do we agree to rename the off_power to min_power and scale the value between min_power and max_power while keeping the logic as I did -> no change to the value itself that is returned back but only scale the value that actually goes to the self.mcu_fan.set_pwm fn

Renaming the value has that added benefit that the user has to review the setting if it's set. Plus it deals with the off_bellow handling that mainsail is doing. I will create a separate PR to mainsail also to remove the dead code

@kdb424
Copy link

kdb424 commented Aug 1, 2023

I would very much like to see a min/max power, and scale between them. Currently "50%" doesn't mean anything related to "50%" relevant to the fan, but relevant to pwm speed. For bare pins, that makes sense, but in the context of fans, I'd like to see 50% mean 50% of the available fan curve. Consider me onboard with this change in concept. Will actively be checking back to code review and do testing on my printers.

@Sineos
Copy link
Collaborator

Sineos commented Aug 2, 2023

There is only one person you need to convince and this is @KevinOConnor 😉

@kubaracek kubaracek force-pushed the feat/pwm-scaling branch 8 times, most recently from 2a9046b to 9020849 Compare August 2, 2023 18:28
@kubaracek
Copy link
Author

kubaracek commented Aug 2, 2023

I've renamed the off_below to min_power and updated any references to it.

IMG_1371_MOV.mp4

@kubaracek kubaracek force-pushed the feat/pwm-scaling branch 4 times, most recently from 41984a4 to aeab8c1 Compare August 2, 2023 19:54
docs/Config_Changes.md Outdated Show resolved Hide resolved
@dewi-ny-je
Copy link

Isn't this something that can be implemented as macro? why a native way?

@kubaracek
Copy link
Author

kubaracek commented Aug 4, 2023

Isn't this something that can be implemented as macro? why a native way?

I wrote in description of the PR. I can't see any reason why in the context of Fan values below certain treshold should be ignored while M106 S255 being scaled to max_power such that the command will result in pwm of 0.7. What I'm configuring in klipper is a safe duty cycle range for my fan.
The client that communicates with klipper shouldn't have such a 'low level' - hardware knowledge of what's my safe fan range. Client requests min fan power, server delivers min fan power.

So the question to ask really is what use do you have for this not to be scaled.
So it's either not to scale any value at all or scale it fully. Now we have something in between.

So now, either we handle values above max_power the same way as we do with off_bellow == ignore them (or clip) OR we normalise the safe duty cycle range such that this PR suggest.

I'm "happy" to implemented a scale_pwm: true/false flag to the fan setting but frankly then we should remove the scaling that happens on the upper bond already.
But I can't really see a point in doing that. As what benefit would it have?

@Sineos
Copy link
Collaborator

Sineos commented Aug 4, 2023

IMO this is a good change:

  • From a developer's perspective, it is clear that a PWM range is between 0 and 255, regardless of any capping at the upper or lower limits, and it is also clear to the developer that any capping will shift the resulting duty cycle.
  • From a user's perspective, this is not very intuitive as the user sees it from the fan's perspective and expects 50% to be 50% fan speed and not something in between.

@freakydude
Copy link
Contributor

... and in addition,

  • it removes (or reduces) the slicer setting dependencies to the installed fans or their configuration

@kubaracek
Copy link
Author

kubaracek commented Aug 5, 2023

Indeed. Also searching for M106 the internet says Set Fan Speed not Set fan PWM. So PWM in this context should be abstracted away from the client

Scale value for fan input based on fan's `min_power` and `max_power`.
As an example, when fan's min_power is set to `0.2`, requesting 1% of fan should translate to roughly `0.2`
This makes it possible to operate fans such as CPAP which generally need
quite high min_power (between 16-30%) operatable at 1%

This also renamed off_below to min_power

Signed-off-by: Jakub Racek <me@jakubracek.net>
This was referenced Aug 11, 2023
@github-actions
Copy link

Thank you for your contribution to Klipper. Unfortunately, a reviewer has not assigned themselves to this GitHub Pull Request. All Pull Requests are reviewed before merging, and a reviewer will need to volunteer. Further information is available at: https://www.klipper3d.org/CONTRIBUTING.html

There are some steps that you can take now:

  1. Perform a self-review of your Pull Request by following the steps at: https://www.klipper3d.org/CONTRIBUTING.html#what-to-expect-in-a-review
    If you have completed a self-review, be sure to state the results of that self-review explicitly in the Pull Request comments. A reviewer is more likely to participate if the bulk of a review has already been completed.
  2. Consider opening a topic on the Klipper Discourse server to discuss this work. The Discourse server is a good place to discuss development ideas and to engage users interested in testing. Reviewers are more likely to prioritize Pull Requests with an active community of users.
  3. Consider helping out reviewers by reviewing other Klipper Pull Requests. Taking the time to perform a careful and detailed review of others work is appreciated. Regular contributors are more likely to prioritize the contributions of other regular contributors.

Unfortunately, if a reviewer does not assign themselves to this GitHub Pull Request then it will be automatically closed. If this happens, then it is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available.

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

Copy link

@kdb424 kdb424 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Workin as intended.

@github-actions
Copy link

github-actions bot commented Sep 5, 2023

Unfortunately a reviewer has not assigned themselves to this GitHub Pull Request and it is therefore being closed. It is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available.

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

@github-actions github-actions bot closed this Sep 5, 2023
@KevinOConnor KevinOConnor reopened this Sep 10, 2023
@trofen
Copy link
Contributor

trofen commented Sep 19, 2023

What if to leave both "off_below" and "min_power"? This will ensure backward compatibility and both parameters are still different in meaning and may be useful.

@surikatec
Copy link

Is this implemented in newest klipper version? (Trying that but can't find it.)

@JamesH1978
Copy link
Collaborator

@surikatec no this is an open PR, it is not implemented or merged

@github-actions
Copy link

github-actions bot commented Oct 5, 2023

Unfortunately a reviewer has not assigned themselves to this GitHub Pull Request and it is therefore being closed. It is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available.

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

@github-actions github-actions bot closed this Oct 5, 2023
@KevinOConnor KevinOConnor reopened this Oct 9, 2023
@github-actions
Copy link

Unfortunately a reviewer has not assigned themselves to this GitHub Pull Request and it is therefore being closed. It is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available.

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

@github-actions github-actions bot closed this Oct 24, 2023
@KevinOConnor KevinOConnor reopened this Oct 25, 2023
Copy link

github-actions bot commented Nov 9, 2023

Unfortunately a reviewer has not assigned themselves to this GitHub Pull Request and it is therefore being closed. It is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available.

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

@github-actions github-actions bot closed this Nov 9, 2023
@KevinOConnor KevinOConnor reopened this Nov 9, 2023
Copy link

Unfortunately a reviewer has not assigned themselves to this GitHub Pull Request and it is therefore being closed. It is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available.

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

@github-actions github-actions bot closed this Nov 23, 2023
@freakydude
Copy link
Contributor

freakydude commented Nov 23, 2023

What tasks are open here?

@KevinOConnor KevinOConnor reopened this Nov 26, 2023
@KoenVanduffel
Copy link

It looks like this thing has stalled. I was looking for exactly this and manually copied the fan.py into my RatOs setup. Works like a charm.
A quick check gave me this result: with min_power: 0.2 and max power: 1 my 4 pin 4028 reports following rpm: 1% fan it runs 1200 rpm, 25% = 5600 rpm, 50% = 11000 rpm, 75% = 16100 rpm and 100% 24900 rpm. Great that is plenty linear (and probably the linearity of the fan itself).

@kubaracek
Copy link
Author

kubaracek commented Jan 23, 2024

Thanks for testing, it stalled on merging. There isn't anybody assigned to this with the rights to merge this unfortunately.
I don't think there is anything more to discuss or code for this. There's some other klipper clone project that merged this and from the community of cpap in Voron and RatRig there're people merging this themself to their self-built klipper.

@stablestud
Copy link

stablestud commented May 14, 2024

people merging this themself to their self-built klipper

And yes I'm unfortunately doing it aswell, shame that this simple feature is not in klipper...

@KoenVanduffel comment regarding developer and user perspective is very good and its confusing for most people. Marlin does that quite well with FAN_MIN_PWM and FAN_MAX_PWM

@KevinOConnor can you please merge this or #4720?
Looking at the amount of issues and opened PRs - this feature is quite in demand

@willpuckett
Copy link
Contributor

willpuckett commented May 18, 2024

Chiming in to support this PR. It seems this would align the way fans work with most users expected behhavior, and would simplify/reduce the need to explicitly configure slicer settings for low fan speeds.

In the event that some users wish to keep the current fan setup, perhaps a "scaled_fan" class could be added to wrap the regular fan and add the scaled fan functionality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.