Skip to content

Commit

Permalink
Add calibration fields to MPC_SET (#447)
Browse files Browse the repository at this point in the history
This allows for changing your MPC calibration values on the fly.

Co-authored-by: Frank Tackitt <[email protected]>
  • Loading branch information
kageurufu and kageurufu authored Dec 3, 2024
1 parent ec42614 commit 0c7c613
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/MPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ MPC_CALIBRATE HEATER=heater_bed FAN_BREAKPOINTS=5

These calibrated model parameters need to be saved to the _SAVE_CONFIG_ block manually or by using the `SAVE_CONFIG` command.

## Updating calibration parameters at runtime

Similar to [`SET_HEATER_PID`](G-Codes.md#set_heater_pid), you can update your MPC calibration profile at runtime.

`MPC_SET HEATER=<heater_name> [BLOCK_HEAT_CAPACITY=0.0] [SENSOR_RESPONSIVENESS=0.0] [AMBIENT_TRANSFER=0.0] [FAN_AMBIENT_TRANSFER=0.01,0.02,0.03]`

# BACKGROUND

## MPC Algorithm
Expand Down
22 changes: 22 additions & 0 deletions klippy/extras/control_mpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ def cmd_MPC_SET(self, gcmd):
"FILAMENT_HEAT_CAPACITY", self.const_filament_heat_capacity
)

self.const_block_heat_capacity = gcmd.get_float(
"BLOCK_HEAT_CAPACITY", self.const_block_heat_capacity
)
self.const_sensor_responsiveness = gcmd.get_float(
"SENSOR_RESPONSIVENESS", self.const_sensor_responsiveness
)
self.const_ambient_transfer = gcmd.get_float(
"AMBIENT_TRANSFER", self.const_ambient_transfer
)

if gcmd.get("FAN_AMBIENT_TRANSFER", None):
try:
self.const_fan_ambient_transfer = [
float(v)
for v in gcmd.get("FAN_AMBIENT_TRANSFER").split(",")
]
except ValueError:
raise gcmd.error(
f"Error on '{gcmd._commandline}': unable to parse FAN_AMBIENT_TRANSFER\n"
"Must be a comma-separated list of values ('0.05,0.07,0.08')"
)

temp = gcmd.get("FILAMENT_TEMP", None)
if temp is not None:
temp = temp.lower().strip()
Expand Down

0 comments on commit 0c7c613

Please sign in to comment.