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

Adjustable precision in M105 temperature report #20602

Merged
merged 4 commits into from
Jan 5, 2021
Merged

Adjustable precision in M105 temperature report #20602

merged 4 commits into from
Jan 5, 2021

Conversation

FanDjango
Copy link
Contributor

@FanDjango FanDjango commented Dec 30, 2020

This PR does not fix a bug. It is entirely cosmetic and low priority

This concerns

// For serial echo, the number of digits after the decimal point
//#define SERIAL_FLOAT_PRECISION 4

When it is enabled by removing the comments, a possible problem ensues.

There are a few places in the code where SERIAL_ECHO(...) is used to display a value of type float.

Thus, for example, the temperature status messages look like this:

Recv:  T:21.17 /0.0000 B:21.04 /0.0000 @:0 B@:0
Recv:  T:21.00 /0.0000 B:20.82 /0.0000 @:0 B@:0
Recv:  T:21.07 /0.0000 B:20.96 /0.0000 @:0 B@:0

SERIAL_ECHO is pretty baseline and does not respect SERIAL_FLOAT_PRECISION.

I have not looked at the other (few) places where this constellation also exists.

Since there are only a few places, it seems simpler to recode them instead of messing with serial.h and overloading SERIAL_ECHO to handle floats correctly, just like SERIAL_ECHOPAIR and its brethren do.

So here is the proposed change to temperature.cpp, the first such occurence I have noticed.

The temperature message then looks like this:

Recv:  T:21.1523 /0.0000 B:20.9765 /0.0000 @:0 B@:0
Recv:  T:21.2695 /0.0000 B:21.2109 /0.0000 @:0 B@:0
Recv:  T:21.3281 /0.0000 B:21.0546 /0.0000 @:0 B@:0

@FanDjango
Copy link
Contributor Author

FanDjango commented Dec 30, 2020

I am aware that this message especially is very important to many clients, such as Octoprint.

Although Octoprint seems happy enough with all the above shown formats as well as the default one, this might not be true for others.

So an alternative thought, also easy to code a change for, is to have the temperature message stay at 2 digit precision, regardless of the precision setting in the configuration.

In that case, the title of this PR should then be "DONT respect PRECISION in temperature message" and the code needs to be changed in the other direction.

I don't know if anyone even uses this configuration option. In many places in the code where it is deemed necessary, an echo of a float will have an explicit precision set for it, also ignoring the configured precision.

I would like to invite comments and discussion on this.

@thisiskeithb
Copy link
Member

I don't know if anyone even uses this configuration option.

SERIAL_FLOAT_PRECISION 4 is used by BigTreeTech's TFT firmware.

@FanDjango
Copy link
Contributor Author

I don't know if anyone even uses this configuration option.

SERIAL_FLOAT_PRECISION 4 is used by BigTreeTech's TFT firmware.

Well, I am not 100% sure, but it looks as if they are getting this format:
T:21.17 /0.0000 B:21.04 /0.0000 @:0 B@:0

And depending on their code, changing this (for better or worse) might break things.

@sjasonsmith
Copy link
Contributor

@thisiskeithb would you be able to test this with their TFT display, to see if it works there?

And depending on their code, changing this (for better or worse) might break things.

The RepRap Wiki M105 has this to say:

Note that temperatures can be reported as integers or floats. There sadly are a lot of interpretations of how an M105 response should look like across firmware variants, making parsing them potentially tricky.

If clients understand a variety of firmware's responses, they will hopefully use proper numeric parsing techniques and not rely on fixed-width output.

@sjasonsmith
Copy link
Contributor

I looked a little closer at the code. I had no idea that SERIAL_ECHO behaved completely differently from SERIAL_ECHOPAIR.

That is a very unfortunate bit of naming confusion, since their names imply they would do the same thing, just for one versus multiple items.

From my perspective, I am fine with your change as a simple solution to this. @thinkyhead would have to state whether those two macros behave differently intentionally or should be re-worked to have the same result.

@FanDjango
Copy link
Contributor Author

I should add, this is definitely a candidate to put on a back burner. I just came across it by chance. Given previous reactions when message formats changed, I would be leery of ad-hoc actions.

Sadly, there is no "back-burner" list of things that "we know about, but more important things have precedence". This would be a candidate for such a list. And if it ever becomes important, bingo, it's there and ready for some kind of action.

@sjasonsmith
Copy link
Contributor

I should add, this is definitely a candidate to put on a back burner.

It is a simple change, so it should hopefully be easy to get a "Yes/No" answer quickly.

@thisiskeithb
Copy link
Member

It is a simple change, so it should hopefully be easy to get a "Yes/No" answer quickly.

I've asked someone more familiar with the TFT code to give it a test/review. I'll let you know what I hear!

@thinkyhead
Copy link
Member

It may be argued that temperature fluctuations under 0.01 degrees are completely irrelevant, and the 'float precision' setting might just be too broad if it will apply to everything, including areas where it really doesn't matter. That said, we also don't want to apply a precision of 1 to output where that would be too little precision. So, wherever the float-precision setting is applied, it should probably be bracketed in constrain().

@FanDjango
Copy link
Contributor Author

So, wherever the float-precision setting is applied, it should probably be bracketed in constrain()

So an alternative thought, also easy to code a change for, is to have the temperature message stay at 2 digit precision, regardless of the precision setting in the configuration.

Most places already are constrained.

Only a few "would need to be" looked at. What irritated me, was

SERIAL_FLOAT_PRECISION 4 is used by BigTreeTech's TFT firmware.

especially because I would strongly assume that they have been getting the strange mixed format up to now.

Either both values have the same precision or both are constrained to 2 dp's regardless of settings, the mixed one grates on the eyes.

@thinkyhead thinkyhead merged commit dc3cfd0 into MarlinFirmware:bugfix-2.0.x Jan 5, 2021
@thinkyhead thinkyhead changed the title Respect PRECISION in temperature message Adjustable precision in M105 temperature report Jan 5, 2021
tharts pushed a commit to tharts/Marlin that referenced this pull request Jan 6, 2021
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
susisstrolch pushed a commit to susisstrolch/Marlin that referenced this pull request Jan 8, 2021
… into bugfix-2.0.x

* 'bugfix-2.0.x' of https://github.com/MarlinFirmware/Marlin: (105 commits)
  [cron] Bump distribution date (2021-01-08)
  Fix M48 output (MarlinFirmware#20713)
  Improved MKS Robin support (MarlinFirmware#19333)
  Preheat before Power Loss Recovery homing (MarlinFirmware#20697)
  [cron] Bump distribution date (2021-01-07)
  Custom build_flags by feature (MarlinFirmware#20692)
  [cron] Bump distribution date (2021-01-06)
  Multi-Z stepper inverting (MarlinFirmware#20678)
  Fix Azteeg X3 macro typo (MarlinFirmware#20681)
  Define SANGUINOLOLU 1.1 enable pins (MarlinFirmware#20682)
  No BTN_ENC_EN on Anet 10 (MarlinFirmware#20684)
  Temperature report followup (MarlinFirmware#20687)
  Adjustable precision in M105 temperature report (MarlinFirmware#20602)
  Don't apply hotend_offset.z to Z soft endstops (MarlinFirmware#20675)
  Indent tool_change_prime
  Clarify solenoid active / magnet-on state
  Defer "quiet probing" till the last Z bump (MarlinFirmware#20610)
  Solenoid cleanups
  [cron] Bump distribution date (2021-01-05)
  Remove untranslated strings
  ...
lclrcarvalho added a commit to lclrcarvalho/Marlin that referenced this pull request Jan 8, 2021
lclrcarvalho added a commit to lclrcarvalho/Marlin that referenced this pull request Jan 8, 2021
dpreed pushed a commit to dpreed/Marlin_2.0.x that referenced this pull request Feb 5, 2021
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
kpishere pushed a commit to kpishere/Marlin that referenced this pull request Feb 19, 2021
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
zillarob pushed a commit to zillarob/Marlin that referenced this pull request Feb 25, 2021
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
W4tel-BiDi pushed a commit to W4tel-BiDi/Marlin that referenced this pull request Apr 5, 2021
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
thinkyhead added a commit to thinkyhead/Marlin that referenced this pull request Apr 29, 2021
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
thinkyhead added a commit that referenced this pull request Apr 30, 2021
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
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.

4 participants