Commit Graph

354 Commits

Author SHA1 Message Date
3d-gussner 072b3f8300 Temp Model cal. menu 2022-10-26 13:34:27 +02:00
3d-gussner f2fe9a51ee rename `Extruder fan` to `Hotend fan` 2022-10-17 13:49:18 +02:00
Alex Voinea 629fc9d0f1
Merge pull request #3638 from wavexx/tm_cal_click
TM: Consume LCD click after calibration
2022-10-06 14:29:40 +02:00
Yuri D'Elia 1d3ee1caba build: Add Configuration_var.h as a configuration wrapper
Instead of including Configuration_prusa.h directly, include
Configuration_var which then includes the proper variant file though a
preprocessor macro.

This allows to keep the existing build system intact, but also redefine
at compile time the final header without having to make copies on the
file system.
2022-10-05 01:26:26 +02:00
Yuri D'Elia 31ea48246a TM: Consume LCD click after calibration
Consume any pending LCD click after the temperature model calibration.
Since we're already in the status menu, the usual consume action is not
done automatically here.
2022-09-30 12:24:54 +02:00
3d-gussner 74e15ac233 Rename EN_ONLY to EN_FARM
remove DEBUG/DEVEL/ALPHA/BETA lcd warning
2022-09-29 16:39:02 +02:00
Alex Voinea 43db24e4fe IR_sensor_analog voltage readings 2022-09-16 10:08:39 +02:00
Alex Voinea 45e43137a5 Filament sensor refactoring initial 2022-09-16 10:07:49 +02:00
3d-gussner ee6821eb0e Add missing MSG_ c= r= 2022-09-14 11:33:24 +02:00
Yuri D'Elia 9dbee61b74 TM: Remove an unnecessary fabsf call
Ironically gcc was stripping that one for us already.
2022-09-02 15:59:29 +02:00
Yuri D'Elia 9b9ce1733c TM: Allow to keep model checking enabled during autotuning
Allow running the model checking during autotuning, with the only
exception being the parameter estimation stage where we alter the same
value which is used by the checker (done to conserve memory/code).

With previous changes the model checker will disable/enable itself when
passing through an unavailable R vector entry, allowing to start the
calibration by checking only the stages where the part fan is disabled.

The C/R0 values should be stable enough to provide a fail-safe mechanism
for printers of the same variant right from the factory.
2022-09-02 15:59:29 +02:00
Yuri D'Elia ff459a6427 TM: Handle dynamic parameter changing
Instead of assuming the model state is always valid, allow NAN values to
pass-through the various check/estimation stages.

This allows running the model checker with incomplete parameters (for
example, missing entries in the R vector) and resume automatically.
2022-09-02 15:59:29 +02:00
Yuri D'Elia 54e5702f30 TM: Move initial R0 initialization closer to usage 2022-09-02 15:59:29 +02:00
Yuri D'Elia 9b5ef75b68 Correctly translate thermal model LCD messages 2022-09-02 15:59:29 +02:00
Yuri D'Elia 331de988f7 TM: Avoid an useless float promotion 2022-09-02 15:59:29 +02:00
Alex Voinea bef7b086e3 Isolate the entire farm and statistics code 2022-08-30 13:57:43 +02:00
Alex Voinea 7d597eb8b0 Move farm mode to separate file 2022-08-30 13:57:43 +02:00
Yuri D'Elia cf1edc85c3 Set a few function attributes to conserve space 2022-08-25 16:50:06 +02:00
Yuri D'Elia 7c8539a9f9 Report correct fan speeds in M155 during calibration 2022-08-25 16:15:51 +02:00
Alex Voinea f2f136e014 Use timer3 instead of timer5 on miniRambo 2022-08-24 10:18:45 +03:00
Yuri D'Elia 35708a61fe No longer disable temperature management in xyzcal
We already disable the heaters upon entering, and the new temperature
isr doesn't perform any direct movement until we return to the main
loop.

This allows us to remove direct control of the soft_pwm interrupt from
the header, which is dangerous.
2022-08-23 17:19:23 +02:00
Yuri D'Elia b672be90b2 Do not overwrite saved values if TM error occurs while paused 2022-08-21 14:53:42 +02:00
Yuri D'Elia d8d085287e Re-enable bed temperature automatically for transitory errors 2022-08-21 14:49:12 +02:00
Yuri D'Elia 30dccb3252 Switch to ATOMIC sections instead of cli/sei/CRITICAL_SECTION 2022-08-21 14:49:12 +02:00
Yuri D'Elia 41abe1689c Block LCD during temperature model autocalibration 2022-07-25 17:30:22 +02:00
Yuri D'Elia 79161f829e Remove last_alert_sent_to_lcd and simplify mintemp alert automaton
Thanks to LCD message priorities this not needed anymore and it's just
overhead.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 374b829fb6 Generalize menu_block_entering_on_serious_errors for menu lockout
Call this variable menu_block_mask instead. We don't need to know the
exact reason of why we're locking the menu.

We will be able to reuse this to prevent menu entry during more
activities in a cleaner way than testing for each condition as it's
currently done for both menu entry and longpress.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 49a288e6cf Restore the "MINTEMP * fixed" message
Set the LCD messages with the correct priority
2022-07-25 17:30:22 +02:00
Yuri D'Elia e77a5345a2 Do not show "THERMAL ANOMALY" with "M310 B0"
This allows us to use "M310 B0 W0.01" as a way to report the current
error continuosly on the serial without 1) more code and 2) without
preventing regular usage.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 1eb7871bab Also save fan speeds during a thermal error pause
Similarly to temperatures, the fan speed is overwritten and needs to be
restored appropriately.
2022-07-25 17:30:22 +02:00
Yuri D'Elia eccfcd7424 Save/restore temperatures during a thermal pause
Re-used saved_* vars (as normally used during the paused state) to
backup the original values when a thermal error occurs.
2022-07-25 17:30:22 +02:00
Yuri D'Elia b9fc73c4c3 TM: Pause the print and allow recovery from a thermal error
Do not allow resuming until all thermal and fan errors are clear.

Call the appropriate resume function when resuming a printing depending
on the saved_print state (is saved_print is available, then we always
need to resume from the saved state even when printing via usb).

Clear the Stopped state when resuming, so that commands can be accepted
again.
2022-07-25 17:30:22 +02:00
Yuri D'Elia f454d1ecf2 TM autotune: fix off-by-one in fan power levels 2022-07-25 17:30:22 +02:00
Yuri D'Elia 5dc0d5f7fa TM autotune: fail if value is outside of the boundaries
Ensure we never fall into the boundary values provided by the min/max
limits.

Save/restore the initial guess value, so that a convergence failure
restores the initial model state.
2022-07-25 17:30:22 +02:00
Yuri D'Elia f835537e88 Exclude TempErrorSource::ambient for boards without a thermistor 2022-07-25 17:30:22 +02:00
Yuri D'Elia b3ca70a007 Show thermal warnings using the new LCD_MESSAGE_INFO priority
Add a new LCD_MESSAGE_INFO priority which can be overridden by regular
status updates, but only if a certain amount of time has passed.

Assign a time stamp to all message updates, so that the time since the
last update can be determined. Also switch the message type to Status,
so that the message always becomes visibile.

Always show status or info messages when printing via SD if the message
is recent enough.
2022-07-25 17:30:22 +02:00
Yuri D'Elia dc2d596f40 Do not allow lcd_updatestatus to be called directly
Enfoce the usage of lcd_setalertstatuspgm and lcd_setstatus so what we
consistently have alert severities properly set.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 6751586db6 Cleanup original thermal error handlers.
Remove useless repeated calls to disable heaters and turn on the fans,
since this is done at a higher level.

Avoid repeating messages on the serial. Do it just once.

Make a critical alert sound unconditionally.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 50c71924a2 Include fan measurements when estimating resistance 2022-07-25 17:30:22 +02:00
Yuri D'Elia ea0840dee9 Refuse to run TM calibration if the printer is not idle 2022-07-25 17:30:22 +02:00
Yuri D'Elia 0680c0b428 Refresh the lcd periodically during calibration 2022-07-25 17:30:22 +02:00
Yuri D'Elia 47d2e9e61c Handle failures during calibration
Break out of the autotuning if a thermal error condition is detected and
attempt to restore a safe initial state irregardless of the error
handlers.

Also error out if the estimation fails to converge.
2022-07-25 17:30:22 +02:00
Yuri D'Elia cc96a47e7f Implement temperature model autotuning
Calibrate C/R values via univariate minimization using golden section.
This is done in several passes:

- Bootstrap C by setting an initial high R value
- Calibrate R at the requested working temperature
- Cooldown
- Refine C to the final value
- Estimate R losses for a subset of fan speeds
- Interpolate remaining values to speed-up the process

This results in robust values which are tailored to the current
filtering constants, and avoid having to sample for an extended
time to reach the required resolution.

The refining pass could avoid cooldown if the recording buffer was at
least twice as large, so that we could record both the heating and the
steady-state, saving _considerable_ time.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 14622bc577 Actually disable the temperature manager in TempMgrGuard 2022-07-25 17:30:22 +02:00
Yuri D'Elia 8620059067 Allow to disable the model warning beeping
Mostly useful for debugging
2022-07-25 17:30:22 +02:00
Yuri D'Elia 6832ec7648 Allow to save/restore temperature model settings
This currently bypasses the ConfigurationStore, which doesn't fit the
malin model nicely.

temp_model is using it's own private copy directly.

But maybe we should change this in the future.
2022-07-25 17:30:22 +02:00
Yuri D'Elia b0b2ff5f9e Rewrite/modularize the model checker
- Allow all parameters to be changed at runtime through M310
- Move the model prototypes into a separate temp_model.h header
- Allow the checked to be enabled/disabled at runtime
- Introduce a warning threshold
2022-07-25 17:30:22 +02:00
Yuri D'Elia fabf511b97 Add the ability to log continuously
TEMP_MODEL_LOGGING enables D70 to record precisely each cycle of the
temperature regulation for offline model simulation
2022-07-25 17:30:22 +02:00
Yuri D'Elia 690affe5a2 Further enhance thermal error priorities
When triggering a thermal error, allow higher-priority errors to
override the initial error source.

This allows a fatal error such as maxtemp to trigger to a full stop even
if thermal runaway has already been triggered.

Reorder error types according to their priority.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 8220d0196b Lock onto the first error source until cleared
Do not overwrite the error source if the error flag is already set.

As checks are performed in priority order, this ensures min/maxtemp
user-level handlers are triggered even if the thermal model can detect
an issue in the same cycle.

This restores MAXTEMP handling, which was simply shadowed.
2022-07-25 17:30:22 +02:00
Yuri D'Elia f82048977a Start PWM timers _after_ initializing min/maxtemp ranges
This would otherwise cause check_temp_raw() to operate on unitialized
values and trigger failures too early.
2022-07-25 17:30:22 +02:00
Yuri D'Elia f1d88ebd40 Protect pid_tuning_finished behind temperature.cpp
Setting pid_tuning_finished can result in the heaters stuck to full
power. As a result, we need to ensure that when PID management is
disabled, heaters are also.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 442b2e16de Set pid_tuning_finished globally to true
Use pid_tuning_finished as a flag to prevent automatic PID management.
As a result, set the default start-up state to true and adjust the
dependent code accordingly.
2022-07-25 17:30:22 +02:00
Yuri D'Elia 92418e9d1b Do not perform PID management while autotune is running 2022-07-25 17:30:22 +02:00
Yuri D'Elia c15d599f71 Convert two PID_autotune strings to PROGMEM 2022-07-25 17:30:22 +02:00
Yuri D'Elia 0c1c350a93 Simplify one expression 2022-07-25 17:30:22 +02:00
Yuri D'Elia 70093fc9dc Allow to redefine basic model constants 2022-07-25 17:30:22 +02:00
Yuri D'Elia a15f2807d9 Allow to continue printing with TEMP_MODEL_CHECK_WARN_ONLY for debugging 2022-07-25 17:30:22 +02:00
Yuri D'Elia 929843e295 Switch two divisions to faster multiplications 2022-07-25 17:30:22 +02:00
Yuri D'Elia bc53bd5305 Make the error threshold be sample-rate invariant 2022-07-25 17:30:22 +02:00
Yuri D'Elia 3eda8b61ee Include the model checker with hard-coded constants 2022-07-25 17:30:22 +02:00
Yuri D'Elia 61575995e0 Isolate temp runaway checks from PID management 2022-07-25 17:30:22 +02:00
Yuri D'Elia 026733e75f Improve comments 2022-07-25 17:30:22 +02:00
Yuri D'Elia 283d5566f1 Limit the rate manage_heater() as it did previously
Avoid running the user-level error handlers too fast.
2022-07-25 17:30:22 +02:00
Yuri D'Elia de77a47906 Correct handling of preheat/runaway errors
As for min/maxtemp, flag the error in the isr, then handle it in the
user code calling the original handler.
2022-07-25 17:30:22 +02:00
Yuri D'Elia bd9a6acd59 Correct handling of min/maxtemp
- Flag the error condition from the temp_mgr_isr
- Handle the error state from the user code

Currently only handles min/maxtemp and relays the error to the original
handler (which is a poor fit for the current design).
2022-07-25 17:30:22 +02:00
Yuri D'Elia 4a0203d691 Isolate oTimer4minTempHeater/Bed into check_min_temp 2022-07-25 17:30:22 +02:00
Yuri D'Elia 7659844012 Reimplement disable_heater to take immediate effect
Split off setIsrTargetTemperatures and temp_mgr_pid() so that we can
propagate the target temperatures instantaneously down the pid/pwm chain
during emergencies.

This reduces the amount of code in disable_heater() itself, making it
a bit more maintenable.

The bed still isn't disabled on-the-spot yet, due to the heatbed_pwm
automaton. To be improved later.
2022-07-25 17:30:22 +02:00
Yuri D'Elia e070bc6455 Remove obsolete and commented variables 2022-07-25 17:30:22 +02:00
Yuri D'Elia 7d82cd641e Rename ADC callback 2022-07-25 17:30:22 +02:00
Yuri D'Elia bcd8496113 Introduce a new set of temperature values for the PID regulation
*_temperature_raw: buffer for the ADC ISR (read by temp ISR)
*_temperature_isr: latest temperatures for PID regulation (copied from
  _raw values)
*_temperature: latest temperature for user code

The flow:
  - ADC ISR (async)
    - perform oversampling
    - call ADC callback: copy to _raw (async)
  - temp ISR (timer)
    - convert to C (_isr values)
  - user code (async)
      - check temp_meas_ready
      - call updateTemperature()
        - copy from _isr to current
        - syncronize target temperatures

This removes PINDA value averaging (if needed, should be re-implemented
by averaging in user code where needed)
2022-07-25 17:30:22 +02:00
Yuri D'Elia 65cf8e541a Isolate current/target temperature in pid_heater/bed functions 2022-07-25 17:30:22 +02:00
Yuri D'Elia 9e826afee9 Switch regulation interval to 270ms 2022-07-25 17:30:22 +02:00
Yuri D'Elia c6d0494cbc Split temperature management into it's own ISR
Use a new low-priority "temp_mgr_isr" running at constant rate for
temperature management.

This is done so that the temperatures are sampled at a constant
independent interval *and* with reduced jitter. Likewise for actual
PID management.

This will require further adjustment for the min/max/runaway display,
which cannot be done directly into this function anymore (the code will
need to disable heaters but flag for display to be handled in
manage_heaters).
2022-07-25 17:30:21 +02:00
Yuri D'Elia 2ca16a06cd Rename tp_init to soft_pwm_init for consistency 2022-07-25 17:30:21 +02:00
Yuri D'Elia 38b3e53f67 Syntax/comment cleanup 2022-07-25 17:30:21 +02:00
Yuri D'Elia 932fcbb33f Simplify soft_pwm_isr even further
Isolate the PWM management into soft_pwm_core
2022-07-25 17:30:21 +02:00
Yuri D'Elia dfd8fee712 Isolate babystep to a separate function 2022-07-25 17:30:21 +02:00
Yuri D'Elia bd28007312 Rename check_fans>readFanTach manageFans>checkFans 2022-07-25 17:30:21 +02:00
Yuri D'Elia 383319dbac Rename temperature_isr to soft_pwm_isr 2022-07-25 17:30:21 +02:00
Yuri D'Elia 16b9acf8bc Decouple temperature ISR from ADC readings
Read from ADC as fast as possible using the ADC interrupt to get
more accurate instantaneous readings.

Decouple the temperature_isr from the adc reading interval, so that
the two can run independently for future use.
2022-07-25 17:30:21 +02:00
Yuri D'Elia e87188e7e3 Ensure ADC and thermistor tables use the same oversampling
The current code assumes that values are directly comparable
2022-07-25 17:30:21 +02:00
Yuri D'Elia 2535d072c4 Do not recursively enter temperature_isr
Disable the interrupt source instead, which avoids the added latency of
reentering the isr in the first place.
2022-07-25 17:30:21 +02:00
Yuri D'Elia 82e221e3c7 Remove ADC pullup checks
Setting pullups on the ADC should trigger the model-based check, making
this redundant and wasteful.

Keep the DEBUG_PULLUP_CRASH menu so that we can verify this behavior in
the future.
2022-07-25 17:30:21 +02:00
Yuri D'Elia f8de274db3 Split fan checks out of temperature.cpp 2022-07-18 17:53:27 +02:00
Yuri D'Elia e37435b53f Merge remote-tracking branch 'upstream/MK3_3.11.1' into mk311_sync 2022-07-04 16:14:23 +02:00
Yuri D'Elia 5b3441b2bd Fix AMBIENT_RAW_*_TEMP define names
The max/min temperature check were incorrectly using
HEATER_AMBIENT_RAW_*_TEMP (non-existing) instead of the correct
AMBIENT_RAW_*_TEMP (this is not a heater afterall).

This doesn't change the current behavior, since the check defaulted to
the correct path for the MK3+ configuration anyway.
2022-04-29 16:54:39 +02:00
Alex Voinea e3f48ead9f
Merge pull request #3440 from gudnimg/optimise-checkFanSpeed
Optimise `checkFanSpeed()` Flash use
2022-04-21 14:04:23 +02:00
Alex Voinea b52597f1b2
Merge branch 'MK3_3.11.1' into MK3_3.10.2 2022-04-07 14:05:34 +02:00
Guðni Már Gilbert c62c412cc3 Remove unused setting PID_ADD_EXTRUSION_RATE
Even if the setting was turned on, it doesn't do anything useful.
2022-03-30 19:03:41 +01:00
Guðni Már Gilbert d42ef4784c Optimise checkFanSpeed()
Changes save 28 bytes of flash
2022-03-06 12:54:24 +00:00
Alex Voinea 4ec8781df2 Fix usb print timer 2022-02-13 22:52:49 +01:00
Alex Voinea fb1c8ee0a3 Change the pullup test 2022-02-08 10:53:47 +01:00
Alex Voinea c06ec9d05b Add pullup error test to define 2022-02-07 13:56:46 +01:00
Alex Voinea b7806bf25f Crash if pullups get enabled on the thermistor inputs 2022-02-01 12:34:07 +01:00
Alex Voinea 67e6361ff1 Fix temperature runaway variable types (merge conflict) 2022-01-30 13:16:05 +01:00
Guðni Már Gilbert 9bf45773f9 Merge remote-tracking branch 'upstream/MK3' into rebase-testing-ground-v2 2022-01-30 11:43:16 +00:00
Guðni Már Gilbert a940c364c9 Create enum class for heating_status variable 2022-01-30 11:39:27 +00:00
Alex Voinea fb10b4398e Merge pull request #6 from gudnimg/gudni-PR1
Purged some `int`s for `uint8_t` when using the axis enum
2022-01-30 11:30:25 +00:00
Guðni Már Gilbert f81db56793 temp_runaway_check() parameter _heater_id should be uint8_t
Saves 58 bytes of flash
2022-01-30 11:22:45 +00:00