Skip to content

Commit

Permalink
control_mpc: docs and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerlz authored and dalegaard committed Jul 27, 2024
1 parent 4126efd commit 27b0e74
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 13 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ See the [Danger Features document](https://dangerklipper.io/Danger_Features.html

- [fan: reverse FAN](https://github.com/DangerKlippers/danger-klipper/pull/51) ([klipper#4983](https://github.com/Klipper3d/klipper/pull/4983))

- [heater: modify PID without reload](https://github.com/DangerKlippers/danger-klipper/pull/35)
- [heaters: modify PID without reload](https://github.com/DangerKlippers/danger-klipper/pull/35)

- [heater: velocity PID](https://github.com/DangerKlippers/danger-klipper/pull/47) ([klipper#6272](https://github.com/Klipper3d/klipper/pull/6272))
- [heaters: MPC temperature control](https://github.com/DangerKlippers/danger-klipper/pull/333)

- [heater: PID-Profiles](https://github.com/DangerKlippers/danger-klipper/pull/162)
- [heaters: velocity PID](https://github.com/DangerKlippers/danger-klipper/pull/47) ([klipper#6272](https://github.com/Klipper3d/klipper/pull/6272))

- [heater: expose heater thermistor out of min/max](https://github.com/DangerKlippers/danger-klipper/pull/182)
- [heaters: PID-Profiles](https://github.com/DangerKlippers/danger-klipper/pull/162)

- [heater/fan: new heated_fan module](https://github.com/DangerKlippers/danger-klipper/pull/259)
- [heaters: expose heater thermistor out of min/max](https://github.com/DangerKlippers/danger-klipper/pull/182)

- [heaters/fan: new heated_fan module](https://github.com/DangerKlippers/danger-klipper/pull/259)

- [gcode: jinja2.ext.do extension](https://github.com/DangerKlippers/danger-klipper/pull/26) ([klipper#5149](https://github.com/Klipper3d/klipper/pull/5149))

Expand Down Expand Up @@ -119,8 +121,6 @@ See the [Danger Features document](https://dangerklipper.io/Danger_Features.html
If you're feeling adventurous, take a peek at the extra features in the bleeding-edge-v2 branch [feature documentation](docs/Bleeding_Edge.md)
and [feature configuration reference](docs/Config_Reference_Bleeding_Edge.md):

- [heaters: mpc temperature control](https://github.com/DangerKlippers/danger-klipper/pull/268)

- [extruder/pa: do not smooth base extruder position, only advance](https://github.com/DangerKlippers/danger-klipper/pull/266)

- [core: non-critical-mcus](https://github.com/DangerKlippers/danger-klipper/pull/265)
Expand Down
25 changes: 20 additions & 5 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,8 @@ The extruder section is used to describe the heater parameters for the
nozzle hotend along with the stepper controlling the extruder. See the
[command reference](G-Codes.md#extruder) for additional information.
See the [pressure advance guide](Pressure_Advance.md) for information
on tuning pressure advance.
on tuning pressure advance. See [PID](PID.md) or [MPC](MPC.md) for more
detailed information about the control methods.

```
[extruder]
Expand Down Expand Up @@ -1022,12 +1023,14 @@ sensor_pin:
# be smoothed to reduce the impact of measurement noise. The default
# is 1 seconds.
control:
# Control algorithm (either pid, pid_v or watermark). This parameter must
# Control algorithm (either pid, pid_v, watermark or mpc). This parameter must
# be provided. pid_v should only be used on well calibrated heaters with
# low to moderate noise.
pid_Kp:
pid_Ki:
pid_Kd:
#
# If control: pid or pid_v
#pid_Kp:
#pid_Ki:
#pid_Kd:
# The proportional (pid_Kp), integral (pid_Ki), and derivative
# (pid_Kd) settings for the PID feedback control system. Klipper
# evaluates the PID settings with the following general formula:
Expand All @@ -1037,11 +1040,23 @@ pid_Kd:
# off and 1.0 being full on. Consider using the PID_CALIBRATE
# command to obtain these parameters. The pid_Kp, pid_Ki, and pid_Kd
# parameters must be provided for PID heaters.
#
# If control: watermark
#max_delta: 2.0
# On 'watermark' controlled heaters this is the number of degrees in
# Celsius above the target temperature before disabling the heater
# as well as the number of degrees below the target before
# re-enabling the heater. The default is 2 degrees Celsius.
#
# If control: mpc
# See MPC.md for details about these parameters.
#heater_power:
#cooling_fan:
#ambient_temp_sensor:
#filament_diameter: 1.75
#filament_density: 1.2
#filament_heat_capacity: 1.8
#
#pwm_cycle_time: 0.100
# Time in seconds for each software PWM cycle of the heater. It is
# not recommended to set this unless there is an electrical
Expand Down
2 changes: 1 addition & 1 deletion docs/Danger_Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- [`[z_tilt/quad_gantry_level] increasing_threshold`](./Config_Reference.md#z_tilt) allows you to customize the allowed variation when probing multiple times

## Heaters, Fans, and PID changes

- [Model Predictive Control](./MPC.md) is an advanced temperature control method that offers an alternative to traditional PID control.
- [Velocity PID](./PID.md) can be more accurate than positional PID, but is more susceptible to noisy sensors and may require larger smoothing times
- [`PID_PROFILE [LOAD/SAVE]`](./G-Codes.md#pid_profile) allows you to calibrate and save PID profiles at multiple temperatures and fan speeds, and later restore them. With some clever macros, automatic per-material pid tuning is within reach!
- [`SET_HEATER_PID HEATER= KP= KI= KD=`](./G-Codes.md#set_heater_pid) can update your PID parameters without a reload.
Expand Down
76 changes: 76 additions & 0 deletions test/klippy/mpc.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Config for extruder testing
[stepper_x]
step_pin: PF0
dir_pin: PF1
enable_pin: !PD7
microsteps: 16
rotation_distance: 40
endstop_pin: ^PE5
position_endstop: 0
position_max: 200
homing_speed: 50

[stepper_y]
step_pin: PF6
dir_pin: !PF7
enable_pin: !PF2
microsteps: 16
rotation_distance: 40
endstop_pin: ^PJ1
position_endstop: 0
position_max: 200
homing_speed: 50

[stepper_z]
step_pin: PL3
dir_pin: PL1
enable_pin: !PK0
microsteps: 16
rotation_distance: 8
endstop_pin: ^PD3
position_endstop: 0.5
position_max: 200

[fan]
pin: PD6

[extruder]
step_pin: PA4
dir_pin: PA6
enable_pin: !PA2
microsteps: 16
rotation_distance: 33.5
nozzle_diameter: 0.500
filament_diameter: 3.500
heater_pin: PB4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK5
control: mpc
heater_power: 50
cooling_fan: fan
filament_density: 1.20
filament_heat_capacity: 1.8
block_heat_capacity: 22.3110
sensor_responsiveness: 0.0998635
ambient_transfer: 0.155082
fan_ambient_transfer: 0.155082, 0.20156, 0.216441
min_temp: 0
max_temp: 210

[extruder_stepper my_extra_stepper]
extruder: extruder
step_pin: PH5
dir_pin: PH6
enable_pin: !PB5
microsteps: 16
rotation_distance: 28.2

[mcu]
serial: /dev/ttyACM0

[printer]
kinematics: cartesian
max_velocity: 300
max_accel: 3000
max_z_velocity: 5
max_z_accel: 100
15 changes: 15 additions & 0 deletions test/klippy/mpc.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# mpc
DICTIONARY atmega2560.dict
CONFIG mpc.cfg

# Extrude only
G1 E5
G1 E-2
G1 E7

# Home and extrusion moves
G28
G1 X20 Y20 Z1
G1 X25 Y25 E7.5

MPC_SET HEATER=extruder FILAMENT_DENSITY=1.15 FILAMENT_HEAT_CAPACITY=2.20

0 comments on commit 27b0e74

Please sign in to comment.