chaussettes
This commit is contained in:
parent
cb2cace3e0
commit
a10f0daf5e
4 changed files with 42 additions and 25 deletions
|
@ -3,8 +3,9 @@ from typing import *
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import controller
|
import controller
|
||||||
|
import hardware
|
||||||
|
|
||||||
Point = NewType("point", List[float, float, float])
|
Point = NewType("point", List[float])
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyPep8Naming
|
# noinspection PyPep8Naming
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
from GCode_Interpreterdc import GCodeToMotors
|
import GCode_Interpreterdc
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __call__(self, gtm, *args, **kwargs):
|
def __call__(self, gtm, *args, **kwargs):
|
||||||
assert isinstance(gtm, GCodeToMotors)
|
assert isinstance(gtm)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class PIDController(Controller):
|
# class PIDController(Controller):
|
||||||
def __call__(self, gtm, *args, **kwargs):
|
# def __call__(self, gtm, *args, **kwargs):
|
||||||
self.
|
# self.
|
||||||
|
|
||||||
|
|
||||||
|
|
39
hardware.py
39
hardware.py
|
@ -1,35 +1,31 @@
|
||||||
import socket
|
import socket
|
||||||
|
import os
|
||||||
|
|
||||||
from GCode_Interpreterdc import GCodeToMotors
|
import GCode_Interpreterdc
|
||||||
|
import simulator
|
||||||
|
|
||||||
class Hardware:
|
class Hardware:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def probe(self, gtm: GCodeToMotors):
|
def probe(self, gtm):
|
||||||
return
|
return
|
||||||
|
|
||||||
def realize(self, gtm: GCodeToMotors):
|
def realize(self, gtm):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
class SimuHardware(Hardware):
|
class SimuHardware(Hardware):
|
||||||
def __init__(self, bind):
|
def __init__(self, bind):
|
||||||
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
super().__init__()
|
||||||
self.s.setblocking(False)
|
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
self.s.bind(bind)
|
self.s.connect(bind)
|
||||||
|
|
||||||
def probe(self, gtm):
|
def probe(self, gtm):
|
||||||
self.s.send("request")
|
self.s.send("request".encode())
|
||||||
self.s.listen()
|
encoder_x = int(socket.SocketIO(self.s, "rw").readline())
|
||||||
while 1:
|
encoder_y = int(socket.SocketIO(self.s, "rw").readline())
|
||||||
try:
|
encoder_z = int(socket.SocketIO(self.s, "rw").readline())
|
||||||
encoder_x = (int)(socket.SocketIO(self.s).readline())
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
encoder_y = (int)(socket.SocketIO(self.s).readline())
|
|
||||||
encoder_z = (int)(socket.SocketIO(self.s).readline())
|
|
||||||
|
|
||||||
last_x, last_y, last_z = gtm.current_steps
|
last_x, last_y, last_z = gtm.current_steps
|
||||||
# We are now at some position which realizes the encoder positions
|
# We are now at some position which realizes the encoder positions
|
||||||
|
@ -54,7 +50,7 @@ class SimuHardware(Hardware):
|
||||||
curr_z / gtm.Z_STEPS_PER_MM])
|
curr_z / gtm.Z_STEPS_PER_MM])
|
||||||
|
|
||||||
def realize(self, gtm):
|
def realize(self, gtm):
|
||||||
self.s.send("realize")
|
self.s.send("realize".encode())
|
||||||
|
|
||||||
if gtm.throttle_x == 0:
|
if gtm.throttle_x == 0:
|
||||||
self.s.send(gtm.x_direction + " 0")
|
self.s.send(gtm.x_direction + " 0")
|
||||||
|
@ -70,3 +66,12 @@ class SimuHardware(Hardware):
|
||||||
self.s.send(gtm.z_direction + " 0")
|
self.s.send(gtm.z_direction + " 0")
|
||||||
else:
|
else:
|
||||||
self.s.send(gtm.z_direction + " " + gtm.FAST_Z_FEEDRATE / gtm.z_throttle)
|
self.s.send(gtm.z_direction + " " + gtm.FAST_Z_FEEDRATE / gtm.z_throttle)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
bind = "tmp.txt"
|
||||||
|
# sim = simulator.Simulator(bind)
|
||||||
|
sh = SimuHardware(bind)
|
||||||
|
gtm1 = GCode_Interpreterdc.GCodeToMotors
|
||||||
|
sh.probe(gtm1)
|
||||||
|
|
15
simulator.py
15
simulator.py
|
@ -1,8 +1,19 @@
|
||||||
|
import socket
|
||||||
import hardware
|
import hardware
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
class Simulator:
|
class Simulator:
|
||||||
def __init__(self, port):
|
def __init__(self, bind):
|
||||||
self.socket = port
|
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
try:
|
||||||
|
os.remove(bind)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
self.s.bind(bind)
|
||||||
|
self.s.listen()
|
||||||
|
while True:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue