#PRINT_START paired with user input macros

1 messages · Page 1 of 1 (latest)

ebon dune
#

I want to set up a system that asks if I want to heat soak the bed before starting a print (for times if I need to restart a print and the bed is already hot so resoaking isn't necessary). I have everything working the way I want to, but the way the code executes makes it not work the right way and in the right order that I originally thought. Here's how I have it setup:

print_start macro:

#   Use PRINT_START for the slicer starting script - please customise for your slicer of choice
gcode:
    {% set BED_TEMP = params.BED|float or params.BED_TEMP|default(110)|float %} # Setup bed temp parameter and give it a default value
    {% set EXTRUDER_TEMP = params.EXTRUDER|float or params.EXTRUDER_TEMP|default(260)|float %} # Setup extruder temp parameter and give it a default value
    M140 S{BED_TEMP} # Start bed heating using the declared or default value
    STATUS_HEATING
    M190 S{BED_TEMP} # Wait for bed to reach temperature
    HEATSOAK_QUESTION

heatsoaking macros (first one sets up question gui, other ones execute based on response to first one called in print_start):

gcode:
    RESPOND TYPE=command MSG="action:prompt_begin Question"
    RESPOND TYPE=command MSG="action:prompt_text Would you like to heatsoak the printer?"
    RESPOND TYPE=command MSG="action:prompt_footer_button Yes (10 minutes)|HEATSOAK_TEN|primary"
    RESPOND TYPE=command MSG="action:prompt_footer_button Yes (20 minutes)|HEATSOAK_TWENTY|warning"
    RESPOND TYPE=command MSG="action:prompt_footer_button No|HEATSOAK_NO|error"
    RESPOND TYPE=command MSG="action:prompt_show"

[gcode_macro HEATSOAK_TEN]
gcode:
    M118 Heat soaking for 10 minutes
    RESPOND type="command" msg="action:prompt_end"
    STATUS_BUSY
    G4 P600000
    G32                            ; home all axes and level gantry
    G90                            ; absolute positioning
    G1 Z20 F3000
    STATUS_HEATING
    M109 S{EXTRUDER_TEMP}
    SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=1
    STATUS_PRINTING

[gcode_macro HEATSOAK_TWENTY]
gcode:
    M118 Heat soaking for 20 minutes
    RESPOND type="command" msg="action:prompt_end"
    STATUS_BUSY
    G4 P1200000
    G32                            ; home all axes and level gantry
    G90                            ; absolute positioning
    G1 Z20 F3000
    STATUS_HEATING
    M109 S{EXTRUDER_TEMP}
    SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=1
    STATUS_PRINTING

[gcode_macro HEATSOAK_NO]
gcode:
    RESPOND type="command" msg="action:prompt_end"
    G32                            ; home all axes and level gantry
    G90                            ; absolute positioning
    G1 Z20 F3000
    STATUS_HEATING
    M109 S{EXTRUDER_TEMP}
    SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=1
    STATUS_PRINTING

The problem I have is that since the print_start macro is technically finished after it runs the heatsoak_question macro, it tries to continue the print process even though theres other things I want to happen first. I'm not sure how I would put these in the slicer starting gcode in a way to make this work but if someone else has a better idea on how to execute this, I'm all ears.

Thanks

past fern
#

I think the simplest would just be to make a "print_start_part2" and have all of the response macros end by calling that.

ebon dune
past fern
ebon dune
#

The pause wouldn't work since the extruder isn't heated up yet. Where is the pause macro coded? Maybe I could make my own that does mostly the same thing

zinc mauve
#

Getting a 'wait' to occur in print_start is kinda difficult. I just did something similar and got help on the klipper discord (sorry, linking it against the rules). If you go there and look at the macro-support channel you will see where I got some help. The person that helped had a 'wait for probe attach' as a starting point for my macro which was a 'loop extruder commands until filament sensor triggers'. Maybe go check that out and ask that same person for help, I think their original script has some ideas that would help you to wait for the prompt input. You need for loops and if statements inside the for loop, and nested macros to make sure the if statements get evaluated every loop.

#

Look for the 'looping filament load within print start' post

ebon dune
zinc mauve
#

Nope not in the standard klipper. May be some branch that does it not sure. It evaluates all conditions in a single macro at runtime. That’s why you have to nest if statements in a separate macro that gets called by a for loop

ebon dune
#

Yeah the loop format is definitely new to me, I'll see if I can understand how it works

zinc mauve
#

The key thing is that the for loop always runs its full number of loops. But initially, the loops contain a time delay inside an if condition. Then, when the if condition is no longer met (you got the user input), it bypasses that and the rest of the for loops run as quick as possible and the for finishes immediately

ebon dune
#

Interesting, that should be what I need

past fern
ebon dune
cyan tartan
#

Why can't the suggestion that Shiftingtech made work?

  1. PRINT_START calls HEATSOAK_QUESTION and ends.
  2. HEATSOAK_QUESTION calls HEATSOAK_* based on the answer.
  3. HEATSOAK_*calls START_PRINTING.
past fern
cyan tartan
#

If the prompt stuff works even remotely sanely, it has to pause. Otherwise, it's just useless.

past fern
#

Which yes, seems extremely odd, but...

cyan tartan
past fern
past fern
cyan tartan
#

Which begs the question how did they implement it. May be, I'll pop over to the Mainsail discord and ask.

past fern
#

And it would need to be klipper that paused and waited

cyan tartan
cyan tartan
cyan tartan
ebon dune
zinc mauve
#

That’s interesting. Based on the examples, it looks like the implementation of while loops will reevaluate the conditions of if statements inside the while each loop (standard klipper for loops don’t do this). That plus the CONTINUE and BREAK makes it fairly useful

ebon dune
#

How would I add something like that to my printer?

cyan tartan
ebon dune
#

Ah ok, thanks

zinc mauve
#

Yeah it looks good I’m going to try it out. I have a “run extruder until filament switch triggers” macro as well as something like the print start dialog box that it would be useful for

#

It should save me from being too dumb of a programmer to figure out the complicated ways around the for / if / delayed gcode restrictions

past fern
#

so I just put together a simple test of my version, using pause_base and resume_base, and that seems to work quite nicely as well

#

you can tell from the fact that the bed heater doesn't turn on until after you choose to continue, that it is waiting correctly

#

(of course, this assumes that your original pause/resume funtions are named *_base: this is the standard from the stock mainsail macros. you...may have something else)

cyan tartan
# past fern

Yeah, this is even easier. It would require that the pause/resume section is configured to not execute any gcode, right?

past fern
cyan tartan
ebon dune
#

The problem I have now is that setting the extruder temperature using the parameter set by the slicer doesn't work because it isn't a defined value. How do I tell it to use the extruder value from the print_start macro so it is referencing the right variable?

#

like with this part

M109 S{EXTRUDER_TEMP}

past fern
#

the issue being that you're trying to heat the extruder in part 2?

ebon dune
#

yeah

past fern
#

you should store it into a variable (in part 1), then part 2 can access the variable

#

see

ebon dune
#

so if I put this in print_start:

    SET_GCODE_VARIABLE MACRO=print_start VARIABLE=extruder_temp VALUE={EXTRUDER}```

then call it later, that should work?
#

or I guess it would be value=EXTRUDER_TEMP

past fern
#

that, and you need to create the variable with the variable_extruder_temp: 0 bit at the beginning

#

but sounds like you have the right idea, yes

ebon dune
#

ah I didn't see that part, ok cool let me try it out

#

it came back with this:

The value 'print_start' is not valid for MACRO

past fern
#

can I see the whole thing?

ebon dune
#

I'm guessing its referring to this part

#

M109 S{printer["gcode_macro print_start"].extruder_temp}

#

or do you just want the whole config file?

past fern
#

no, it's clearly referring to the SET_GCODE_VARIABLE

#

since that's where MACRO is a thing

#

but I need context

#

can I see the whole print_start macro?

ebon dune
#
variable_extruder_temp: 0
gcode:
    {% set BED_TEMP = params.BED|float or params.BED_TEMP|default(110)|float %} # Setup bed temp parameter and give it a default value
    {% set EXTRUDER_TEMP = params.EXTRUDER|float or params.EXTRUDER_TEMP|default(260)|float %} # Setup extruder temp parameter and give it a default value
    SET_GCODE_VARIABLE MACRO=print_start VARIABLE=extruder_temp VALUE={EXTRUDER_TEMP}
    M140 S{BED_TEMP} # Start bed heating using the declared or default value
    STATUS_HEATING
    M190 S{BED_TEMP} # Wait for bed to reach temperature
    HEATSOAK_QUESTION```
past fern
#

I'm not sure about this, but I've got a sneaking suspicion it might be a case sensitivity thing. since its [gcode_macro PRINT_START] try using PRINT_START on the SET_GCODE_VARIABLE line as well

ebon dune
#

now it says this

#

Error evaluating 'gcode_macro HEATSOAK_NO:gcode': jinja2.exceptions.UndefinedError: 'extras.gcode_macro.GetStatusWrapper object' has no attribute 'gcode_macro print_start'

#
gcode:
    RESPOND type="command" msg="action:prompt_end"
    G32                            ; home all axes and level gantry
    STATUS_HEATING
    M109 S{printer[""gcode_macro PRINT_START""].extruder_temp}
    SET_FILAMENT_SENSOR SENSOR=filament_sensor ENABLE=1
    STATUS_PRINTING```
#

oh I see, one sec

past fern
#

the extra quotes are likely messing it up

ebon dune
#

it has 2 quotes

#

yeah I was copy pasting and I guess I missed that

#

ok it doesn't error anymore. Now its just leveling and then hopefully itll start

#

hell yeah, it works now

#

I guess I forgot to put the resume_base in the rest of the code sections, but when I pressed the resume button it went to the front left corner and kinda hit the acrylic wall and then started the print fine. Is that just where the resume makes it go?

ebon dune
#

it also doesn't seem to go to that place every time which is strange

#

can I customize where it goes after doing the resume_base or is that baked in?

cyan tartan
ebon dune
cyan tartan
ebon dune
past fern