Exemplo n.º 1
0
    def __init__(self):
        logging.info("Replicape initializing " + version)
        self.config = ConfigParser.ConfigParser()
        self.config.readfp(open('config/default.cfg'))

        # Make a list of steppers
        self.steppers = {}

        # Init the 5 Stepper motors (step, dir, fault, DAC channel, name)
        self.steppers["X"] = SMD("GPIO0_27", "GPIO1_29", "GPIO2_4", 0, "X")
        self.steppers["Y"] = SMD("GPIO1_12", "GPIO0_22", "GPIO2_5", 1, "Y")
        self.steppers["Z"] = SMD("GPIO0_23", "GPIO0_26", "GPIO0_15", 2, "Z")
        self.steppers["H"] = SMD("GPIO1_28", "GPIO1_15", "GPIO2_1", 3, "Ext1")
        self.steppers["E"] = SMD("GPIO1_13", "GPIO1_14", "GPIO2_3", 4, "Ext2")

        # Enable the steppers and set the current, steps pr mm and microstepping
        for name, stepper in self.steppers.iteritems():
            stepper.setCurrentValue(
                self.config.getfloat('Steppers', 'current_' + name))
            stepper.setEnabled(
                self.config.getboolean('Steppers', 'enabled_' + name))
            stepper.set_steps_pr_mm(
                self.config.getfloat('Steppers', 'steps_pr_mm_' + name))
            stepper.set_microstepping(
                self.config.getint('Steppers', 'microstepping_' + name))
            stepper.set_decay(0)

# Commit changes for the Steppers
        SMD.commit()

        # Find the path of the thermostors
        path = "/sys/bus/iio/devices/iio:device0/in_voltage"

        # init the 3 thermistors
        self.therm_ext1 = Thermistor(path + "4_raw", "MOSFET Ext 1",
                                     "B57561G0103F000")  # Epcos 10K
        self.therm_hbp = Thermistor(path + "6_raw", "MOSFET HBP",
                                    "B57560G104F")  # Epcos 100K
        self.therm_ext2 = Thermistor(path + "5_raw", "MOSFET Ext 2",
                                     "B57561G0103F000")  # Epcos 10K

        if os.path.exists("/sys/bus/w1/devices/28-000002e34b73/w1_slave"):
            self.cold_end_1 = W1(
                "/sys/bus/w1/devices/28-000002e34b73/w1_slave", "Cold End 1")

        # init the 3 heaters
        self.mosfet_ext1 = Mosfet(3)
        self.mosfet_ext2 = Mosfet(4)
        self.mosfet_hbp = Mosfet(5)

        # Make extruder 1
        self.ext1 = Extruder(self.steppers["E"], self.therm_ext1,
                             self.mosfet_ext1, "Ext1")
        self.ext1.setPvalue(0.1)
        self.ext1.setDvalue(0.3)
        self.ext1.setIvalue(0.0)

        # Make Heated Build platform
        self.hbp = HBP(self.therm_hbp, self.mosfet_hbp)

        # Make extruder 2.
        self.ext2 = Extruder(self.steppers["H"], self.therm_ext2,
                             self.mosfet_ext2, "Ext2")
        self.ext1.setPvalue(0.1)
        self.ext1.setDvalue(0.3)
        self.ext1.setIvalue(0.0)

        self.current_tool = "E"

        # Init the three fans
        self.fan_1 = Fan(1)
        self.fan_2 = Fan(2)
        self.fan_3 = Fan(0)
        self.fans = {0: self.fan_1, 1: self.fan_2, 2: self.fan_3}

        self.fan_1.setPWMFrequency(100)

        # Init the end stops
        self.end_stops = {}
        self.end_stops["Y1"] = EndStop("GPIO2_2", self.steppers, 1, "Y1")
        self.end_stops["X1"] = EndStop("GPIO0_14", self.steppers, 2, "X1")
        self.end_stops["Z1"] = EndStop("GPIO0_30", self.steppers, 3, "Z1")
        self.end_stops["Y2"] = EndStop("GPIO3_21", self.steppers, 4, "Y2")
        self.end_stops["X2"] = EndStop("GPIO0_31", self.steppers, 5, "X2")
        self.end_stops["Z2"] = EndStop("GPIO0_4", self.steppers, 6, "Z2")

        # Make a queue of commands
        self.commands = Queue.Queue(10)

        # Set up USB, this receives messages and pushes them on the queue
        #self.usb = USB(self.commands)
        self.pipe = Pipe(self.commands)
        self.ethernet = Ethernet(self.commands)

        # Init the path planner
        self.movement = "RELATIVE"
        self.feed_rate = 3000.0
        self.current_pos = {"X": 0.0, "Y": 0.0, "Z": 0.0, "E": 0.0, "H": 0.0}
        self.acceleration = 0.3
        Path.axis_config = int(self.config.get('Geometry', 'axis_config'))
        Path.max_speed_x = float(self.config.get('Steppers', 'max_speed_x'))
        Path.max_speed_y = float(self.config.get('Steppers', 'max_speed_y'))
        Path.max_speed_z = float(self.config.get('Steppers', 'max_speed_z'))
        Path.max_speed_e = float(self.config.get('Steppers', 'max_speed_e'))
        Path.max_speed_h = float(self.config.get('Steppers', 'max_speed_h'))

        self.path_planner = Path_planner(self.steppers, self.current_pos)
        self.path_planner.set_acceleration(self.acceleration)

        # Signal everything ready
        logging.info("Replicape ready")
        print "Replicape ready"