"IF" and "THEN" commands (NOOB question)

Hello everyone,

I just started using Octoprint (and the RasPi) for the first time last week, so please forgive me if this question can not be done, or if it was asked before.

Could it be possible for Octoprint do run a kind of "IF" and "THEN" while printing? I'll give an idea I had that would use the GPIO inputs, and determine what Octoprint needs to do. Lets use E3D's tool-changing 3D printer as an example. Lets run a print that uses all 4 tools. And about half way through, there is a power outage. so now the printer is stopped, and it has a random tool locked in to the carriage. If the print is restarted, the printer will assume there is no tool locked in the carriage and try to pick up the first tool to start printing. But since there is a tool in the carriage from the power outage, the printer will crash.

My thinking to stop this is to use "IF" and "THEN" commands that are controlled using the GPIO inputs. First Octoprint would home X and Y, then using the GPIO inputs, notice what tool storage location is empty, then run the tool docking gcode.

Something like; (please excuse the format, I dont know the code for the RasPi yet)

docked = high
not_docked = low


IF tool_0 = not_docked
   RUN TOOL NUMBER 0 DOCKING GCODE

IF tool_1 = not_docked
   RUN TOOL NUMBER 1 DOCKING GCODE

IF tool_2 = not_docked
   RUN TOOL NUMBER 2 DOCKING GCODE

IF tool_3 = not_docked
   RUN TOOL NUMBER 3 DOCKING GCODE

The IF and THEN could also be used to confirm the tool is locked to the carriage before it starts (or continues) printing.

IF carriage_locked = not_docked
   STOP PRINT
   SHOW WARNING

Thanks for any input. And i'm looking forward to learning more
AJ

OctoPrint doesn't have a general purpose command language with conditionals like IF THEN ELSE.

Since there aren't any E3D tool-changing printers in the wild yet, it would be hard to speculate but I'll guess there will be enhancements to the firmware that will include a command to restore the printer to a known state.

After a power outage, most printers don't even remember where they are in X, Y, and Z and must re-home to establish their bearings.

Thank you for the reply,

What about creating a plugin that could add some conditional checks that are determined by GPIO inputs? I'm asking because I want to learn how to code for Octoprint (and RasPi), but I have to have a good project to learn with, or I loose interest. I don't want to try and tackle making a plugin, just to find out that it cant be done.