chaussettes

This commit is contained in:
mpboyer 2025-01-13 18:09:02 +01:00
parent cb2cace3e0
commit a10f0daf5e
4 changed files with 42 additions and 25 deletions

View file

@ -3,8 +3,9 @@ from typing import *
import numpy as np
import controller
import hardware
Point = NewType("point", List[float, float, float])
Point = NewType("point", List[float])
# noinspection PyPep8Naming

View file

@ -1,16 +1,16 @@
from GCode_Interpreterdc import GCodeToMotors
import GCode_Interpreterdc
class Controller:
def __init__(self):
pass
def __call__(self, gtm, *args, **kwargs):
assert isinstance(gtm, GCodeToMotors)
assert isinstance(gtm)
return None
class PIDController(Controller):
def __call__(self, gtm, *args, **kwargs):
self.
# class PIDController(Controller):
# def __call__(self, gtm, *args, **kwargs):
# self.

View file

@ -1,35 +1,31 @@
import socket
import os
from GCode_Interpreterdc import GCodeToMotors
import GCode_Interpreterdc
import simulator
class Hardware:
def __init__(self):
pass
def probe(self, gtm: GCodeToMotors):
def probe(self, gtm):
return
def realize(self, gtm: GCodeToMotors):
def realize(self, gtm):
return
class SimuHardware(Hardware):
def __init__(self, bind):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.setblocking(False)
self.s.bind(bind)
super().__init__()
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.s.connect(bind)
def probe(self, gtm):
self.s.send("request")
self.s.listen()
while 1:
try:
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())
self.s.send("request".encode())
encoder_x = int(socket.SocketIO(self.s, "rw").readline())
encoder_y = int(socket.SocketIO(self.s, "rw").readline())
encoder_z = int(socket.SocketIO(self.s, "rw").readline())
last_x, last_y, last_z = gtm.current_steps
# 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])
def realize(self, gtm):
self.s.send("realize")
self.s.send("realize".encode())
if gtm.throttle_x == 0:
self.s.send(gtm.x_direction + " 0")
@ -70,3 +66,12 @@ class SimuHardware(Hardware):
self.s.send(gtm.z_direction + " 0")
else:
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)

View file

@ -1,8 +1,19 @@
import socket
import hardware
import os
class Simulator:
def __init__(self, port):
self.socket = port
def __init__(self, bind):
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: