Jump to content

troyproffitt

Member
  • Posts

    4
  • Joined

  • Last visited

Posts posted by troyproffitt

  1. I ended up figuring out how to create the script on my own.  I also added some additional functionality by providing parameters for min / max servo range values and also letting the user provide the pin value on the M42 command.

    Hope this helps others that are trying to use a berdair or other servo type air source:

     

    # Copyright (c) 2020 Ultimaker B.V.
    # Cura is released under the terms of the LGPLv3 or higher.
    # Created by Wayne Porter
    
    from ..Script import Script
    
    class convertFantoServo(Script):
        def __init__(self):
            super().__init__()
    
        def getSettingDataString(self):
            return """{
                "name": "Convert Fan to Servo",
                "key": "convertFantoServo",
                "metadata": {},
                "version": 2,
                "settings":
                {
                   "minServo":
                    {
                        "label": "Servo Min Travel Value.",
                        "description": "Servo Min Travel Value.",
                        "type": "str",
                        "default_value": ".4"
                    },
                    "maxServo":
                    {
                        "label": "Servo Max Travel Value.",
                        "description": "Servo Max Travel Value.",
                        "type": "str",
                        "default_value": ".7"
                    },
                    "servoPin":
                    {
                        "label": "Servo pin assigned in M42.",
                        "description": "What pin on the controller board your servo is connected to.",
                        "type": "str",
                        "default_value": "8"
                    }
                }
            }"""
    
        def execute(self, data):
            minServo = float(self.getSettingValueByKey("minServo"))
            maxServo = float(self.getSettingValueByKey("maxServo"))
            servoPin = self.getSettingValueByKey("servoPin")
            servoRange = maxServo - minServo
            conversionVal = 255 / round(servoRange, 3)
            for layer in data:
                # Check that a layer is being printed
                lines = layer.split("\n")
                for line in lines:
                    if "M106" in line:
                        index = data.index(layer)
                        getFanval = line.replace("M106 S", "")
                        check_fan_speed = (float(getFanval) / conversionVal) + minServo
                        layer = "M42 P" + servoPin + " S" + str(round(check_fan_speed, 3)) + "\n" + layer
                        data[index] = layer
                        break
            return data

     

  2. I am attempting to use a CPAP fan as a parts cooler for my 3d printer.  Since it needs a controller to function (ESC), on my Duet WIFI 2, I cannot just plug it into the fan0 port on the controller board.  Good news is that I was able to re-purpose one of the heater pins to behave like a servo and then I can use an M42 command to turn on / off the CPAP fan and increase / decrease the fan speed.  For example

    CPAP fan at 0%

    M42  P8 S0.4

    CPAP fan at 100%

    M42  P8 S0.7

     

    What I am hoping to accomplish is to re-use the post processing script InsertAtLayerChange to convert the fan_speed value from the M106 (or possibly reference the CURA keyword cool_fan_speed) to an M42 command.  Here is my math to get the appropriate range:

     

    M42 P8 S({cool_fan_speed}/250)+.4)

     

    I'd like this to be evaluated at every layer.  I am not familiar with the Python syntax, but I was hoping someone could help me figure out how to modify the current Insert at Layer Change script to add in this additional functionality.

     

    Here is the original script:

    # Copyright (c) 2020 Ultimaker B.V.
    # Cura is released under the terms of the LGPLv3 or higher.
    # Created by Wayne Porter
    
    from ..Script import Script
    
    class InsertAtLayerChange(Script):
        def __init__(self):
            super().__init__()
    
        def getSettingDataString(self):
            return """{
                "name": "Insert at layer change",
                "key": "InsertAtLayerChange",
                "metadata": {},
                "version": 2,
                "settings":
                {
                    "insert_location":
                    {
                        "label": "When to insert",
                        "description": "Whether to insert code before or after layer change.",
                        "type": "enum",
                        "options": {"before": "Before", "after": "After"},
                        "default_value": "before"
                    },
                    "gcode_to_add":
                    {
                        "label": "G-code to insert.",
                        "description": "G-code to add before or after layer change.",
                        "type": "str",
                        "default_value": ""
                    }
                }
            }"""
    
        def execute(self, data):
            gcode_to_add = self.getSettingValueByKey("gcode_to_add") + "\n"
            for layer in data:
                # Check that a layer is being printed
                lines = layer.split("\n")
                for line in lines:
                    if ";LAYER:" in line:
                        index = data.index(layer)
                        check_fan_speed = data.index(cool_fan_speed)
                        if self.getSettingValueByKey("insert_location") == "before":
                            layer = gcode_to_add + layer
                        else:
                            layer = layer + gcode_to_add 
    
                        data[index] = layer
                        break
            return data

     

    Thanks for your help,

    -Troy

×
×
  • Create New...