Hallo zusammen,
ich möchte mich an die 3D-Drucker Steuerung via Python heranwagen (soweit es mir gelingt natürlich )
Ich werde hier immer wieder mal neuen Code einfügen, über Kommentare / Ideen oder Anregungen werde ich mich sehr sehr freuen
paar Anmerkungen vielleicht zum Code:
1. ich habe heute erst angefangen (28.03.)
2. Kommentare per "Blockkommentar" sind Funktionen
3. Kommentare per #Zeilenkommentar sind alles andere
4. Kommentare, welche einer Funktion unterstehen, sind eingerückt
5. Kommentare, die im Code selbst stehen, sind Ideen, die ich noch umsetzen muss
5. Parallele Prozesse werde ich über Threading verwirklichen
Bisher denke ich, werde ich pro "HardwareKomponente" eines 3D-Druckers eine LED anschließen, die dann entsprechend bei Aufruf leuchtet (also wenn das Heizbett eingeschaltet wird leuchtet LED1, wenn Filament durch Extruder läuft, LED2, 3 Richtungsmotoren: LED 3-5, HotEnd, usw.), da ich (noch) nicht vorhabe, tatsächlich einen 3D-Drucker so im "Real Life" zu bauen
Wie gesagt, bin noch am Anfang, darum bin ich über jeden hilfreichen Kommentar dankbar
Anbei gleich Version 1 meines Codes:
#!/usr/bin/env python
import threading
#import Queue as queue
import RPi.GPIO as gpio
gpio.setwarnings(False) #gpio initiation
gpio.setmode(gpio.BCM)
motorx = "4" #pin for motorx
motory = "17" #pin for motory
motorz = "27" #pin for motorz
motors = (motorx, motory, motorz) #list with motorpins
class motor (threading.Thread):
def __init__(self, motor_gpio_pin): """Initiation of motors (x,y,z) with position (0) for each"""
threading.Thread.__init__(self) #Initiation of Thread
self.gpio_pin = motor_gpio_pin #motors combined to their gpio_pin
def run(self, position): """run is called when thread "motor" is initiated"""
self.position = position
if self.position = "0": #motor moves to position (0)
gpio.out(self, True)
def move(self, length, speed): """move of motor"""
def emergency(self): """emergency stop"""
steps = {"x" : "0", "y" : "0", "z" : "0"} #Inputs for motors, start position, later on: dict for
velocity = {"x" : "0", "y" : "0", "z" : "0"} #These variables have to be changed
def controller(self, steps, velocity): """Controller for motors"""
for keys in steps: #match the values to motor directions
input_mx = steps['x']
input_my = steps['y']
input_mz = steps['z']
#Weitergabe von Schrittweite und Geschwindigkeit an Motoren
#Starten der Motoren (Thread-Initialisierung)
def emergency(): """Software-Emergency Stop for all pins"""
for i in range(1, 28): #all gpio.pins off
gpio.out(i, False)
def main(): """main"""
mx = motor() #motor x direction
my = motor() #motor y direction
mz = motor() #motor z direction
for i in motors: #motorpins initiation
gpio.setup(i, gpio.OUT)
gpio.out(i, False)
mx.start(0) """start of motors"""
my.start(0)
mz.start(0)
#wait_list = Queue.Queue() #Job-Queue
contoller() """controller start"""
if __name__=='__main__':
main()
Alles anzeigen