Prettifier
This commit is contained in:
parent
7616d4f93e
commit
b92fbe42af
4 changed files with 46 additions and 23 deletions
|
@ -67,7 +67,7 @@ class GCodeToMotors:
|
|||
Z_STEPS_PER_MM: float = 188.97
|
||||
Z_MOTOR_STEPS: int = 200
|
||||
|
||||
FAST_XY_FEEDRATE: float = 100 # in mm/s? Maybe we get mm/inch there too
|
||||
FAST_XY_FEEDRATE: float = 100 # in m/mn
|
||||
FAST_Z_FEEDRATE: float = 100
|
||||
|
||||
CURVE_SECTION_INCHES = curve_section = .019685
|
||||
|
@ -85,6 +85,7 @@ class GCodeToMotors:
|
|||
z_throttle : int = 0
|
||||
|
||||
target_feedrate: float = 0 # Target total head speed. For now in mm/s always
|
||||
feedrate: float = 0.
|
||||
|
||||
abs_mode: bool = False
|
||||
|
||||
|
@ -141,11 +142,13 @@ class GCodeToMotors:
|
|||
return self.FAST_XY_FEEDRATE
|
||||
|
||||
# Try to move to target_units using target_feedrate
|
||||
|
||||
# We honor the following semantics:
|
||||
# GCodeToMotors translates the GCode to high-level controls/theoretical position and targets
|
||||
# HARDWARE.probe() updates GCodeToMotors with the actual position
|
||||
# CONTROLLER() takes the current state and objective, then makes a movement decision
|
||||
# HARDWARE.realize() applies the current commands to the actual hardware
|
||||
|
||||
def move(self):
|
||||
#self.HARDWARE.probe(self)
|
||||
#while not self.CONTROLLER(self): # Allow controller to alter self
|
||||
|
@ -154,6 +157,13 @@ class GCodeToMotors:
|
|||
self.current_units = self.target_units.copy() # Too good to be true
|
||||
self.calculate_deltas()
|
||||
|
||||
def calculate_feedrate_delay(self, feedrate: float) -> float:
|
||||
distance: float = np.linalg.norm(self.delta_units)
|
||||
master_steps: float = max(self.delta_steps)
|
||||
|
||||
# Compute delay between steps in microseconds
|
||||
return ((distance * 600000000.) / feedrate) / master_steps
|
||||
|
||||
def instruction_converter(self, instruction: str) -> Optional[List[float]]:
|
||||
if instruction[0] == "/":
|
||||
return None
|
||||
|
@ -196,7 +206,7 @@ class GCodeToMotors:
|
|||
if code == 1:
|
||||
self.feedrate = search_string('F', instruction)
|
||||
if self.feedrate > 0:
|
||||
self.target_feedrate = self.calculate_feedrate_delay(self.feedrate)
|
||||
self.target_feedrate = self.feedrate
|
||||
else:
|
||||
self.target_feedrate = self.get_max_speed()
|
||||
else:
|
||||
|
@ -289,7 +299,7 @@ class GCodeToMotors:
|
|||
raise NotImplementedError("PAS DE SPLINE QUADRATIQUE J'AI LA FLEMME")
|
||||
|
||||
case 5.2, 5.3:
|
||||
raise NotImplementedError("Experimental")
|
||||
raise NotImplementedError("Experimental Unimplemented Feature")
|
||||
|
||||
case 6:
|
||||
# Not canonical, but parabolas maybe
|
||||
|
@ -317,7 +327,7 @@ class GCodeToMotors:
|
|||
|
||||
case 28:
|
||||
self.set_target(0., 0., 0.)
|
||||
self.move(self.get_max_speed())
|
||||
self.move()
|
||||
|
||||
case 30:
|
||||
fp = [0., 0., 0.]
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import GCode_Interpreterdc
|
||||
|
||||
class Controller:
|
||||
def __init__(self):
|
||||
|
@ -7,16 +6,17 @@ class Controller:
|
|||
def __call__(self, gtm, *args, **kwargs):
|
||||
return None
|
||||
|
||||
|
||||
# We control position, but the output of the controller is a set speed.
|
||||
# Therefore, we have proportional, differential and second differential terms.
|
||||
class PIDController(Controller):
|
||||
err_x, err_y, err_z = 0., 0., 0.
|
||||
derr_x, derr_y, derr_z = 0., 0., 0.
|
||||
d2err_x, d2err_y, d2err_z = 0., 0., 0.
|
||||
|
||||
def __init__(self, p, i, d):
|
||||
super().__init__()
|
||||
self.err_x, self.err_y, self.err_z = 0., 0., 0.
|
||||
self.derr_x, self.derr_y, self.derr_z = 0., 0., 0.
|
||||
self.d2err_x, self.d2err_y, self.d2err_z = 0., 0., 0.
|
||||
|
||||
self.p, self.i, self.d = p,i,d
|
||||
self.p, self.i, self.d = p, i, d
|
||||
|
||||
def __call__(self, gtm, *args, **kwargs):
|
||||
err_x_new, err_y_new, err_z_new = gtm.delta_steps
|
||||
|
@ -25,20 +25,20 @@ class PIDController(Controller):
|
|||
|
||||
self.err_x, self.err_y, self.err_z = err_x_new, err_y_new, err_z_new
|
||||
self.derr_x, self.derr_y, self.derr_z = derr_x_new, derr_y_new, derr_z_new
|
||||
self.d2err_x, self.d2err_y, self.d2err_z = d2err_x_new,d2err_y_new,d2err_z_new
|
||||
self.d2err_x, self.d2err_y, self.d2err_z = d2err_x_new, d2err_y_new, d2err_z_new
|
||||
|
||||
speed_cmd_x = self.p * self.derr_x + self.i * self.err_x + self.d * self.d2err_x
|
||||
speed_cmd_y = self.p * self.derr_y + self.i * self.err_y + self.d * self.d2err_y
|
||||
speed_cmd_z = self.p * self.derr_z + self.i * self.err_z + self.d * self.d2err_z
|
||||
|
||||
# It is the responsability of the coefficients to make sure this results in the desired feedrate
|
||||
gtm.x_throttle = gtm.target_feedrate/abs(speed_cmd_x)
|
||||
gtm.x_throttle = gtm.target_feedrate / abs(speed_cmd_x)
|
||||
gtm.x_direction = 1 if (speed_cmd_x > 0) else 0
|
||||
|
||||
gtm.y_throttle = gtm.target_feedrate/abs(speed_cmd_y)
|
||||
gtm.y_throttle = gtm.target_feedrate / abs(speed_cmd_y)
|
||||
gtm.y_direction = 1 if (speed_cmd_y > 0) else 0
|
||||
|
||||
gtm.z_throttle = gtm.target_feedrate/abs(speed_cmd_z)
|
||||
gtm.z_throttle = gtm.target_feedrate / abs(speed_cmd_z)
|
||||
gtm.z_direction = 1 if (speed_cmd_z > 0) else 0
|
||||
|
||||
if gtm.x_throttle > 65536:
|
||||
|
@ -50,3 +50,16 @@ class PIDController(Controller):
|
|||
if gtm.z_throttle > 65536:
|
||||
gtm.z_throttle = 0
|
||||
|
||||
|
||||
class Dezimpots(Controller):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def __call__(self, gtm, *args, **kwargs):
|
||||
print("Call Me")
|
||||
|
||||
gtm.x_direction = 1 if gtm.delta_steps[0] > 0 else 0
|
||||
gtm.y_direction = 1 if gtm.delta_steps[1] > 0 else 0
|
||||
gtm.z_direction = 1 if gtm.delta_steps[2] > 0 else 0
|
||||
|
||||
|
||||
|
|
16
hardware.py
16
hardware.py
|
@ -5,8 +5,9 @@ import GCode_Interpreterdc
|
|||
import simulator
|
||||
|
||||
class Hardware:
|
||||
def __init__(self):
|
||||
pass
|
||||
def __init__(self, bind):
|
||||
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.s.connect(bind)
|
||||
|
||||
def probe(self, gtm):
|
||||
return
|
||||
|
@ -17,9 +18,8 @@ class Hardware:
|
|||
|
||||
class SimuHardware(Hardware):
|
||||
def __init__(self, bind):
|
||||
Hardware.__init__(self)
|
||||
self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.s.connect(bind)
|
||||
Hardware.__init__(self, bind)
|
||||
|
||||
|
||||
def probe(self, gtm):
|
||||
self.s.send("request".encode())
|
||||
|
@ -70,8 +70,8 @@ class SimuHardware(Hardware):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
bind = "tmp.txt"
|
||||
# sim = simulator.Simulator(bind)
|
||||
sh = SimuHardware(bind)
|
||||
b = "tmp.txt"
|
||||
# sim = simulator.Simulator(b)
|
||||
sh = SimuHardware(b)
|
||||
gtm1 = GCode_Interpreterdc.GCodeToMotors
|
||||
sh.probe(gtm1)
|
||||
|
|
|
@ -9,7 +9,7 @@ from matplotlib.colors import LinearSegmentedColormap
|
|||
|
||||
def parse_speed(text):
|
||||
tl = text.split(' ')
|
||||
return int(tl[0]) * float(tl[1])
|
||||
return (2 * int(tl[0]) - 1) * float(tl[1])
|
||||
|
||||
|
||||
class Simulator:
|
||||
|
|
Loading…
Add table
Reference in a new issue