This commit is contained in:
Sélène Corbineau 2025-01-15 09:53:30 +01:00
parent b3a2095ade
commit 7263d98842
6 changed files with 49 additions and 25295 deletions

View file

@ -36,20 +36,20 @@ class GCodeToMotors:
self.CONTROLLER = ctrl
self.HARDWARE = hw_interface
X_STEPS_PER_INCH = x_units = 4800
X_STEPS_PER_MM: float = 188.97
X_STEPS_PER_INCH = 4800
X_STEPS_PER_MM = x_units = 188.97
X_MOTOR_STEPS: float = 200
Y_STEPS_PER_INCH = y_units = 4800
Y_STEPS_PER_MM: int = 188.97
Y_STEPS_PER_INCH = 4800
Y_STEPS_PER_MM = y_units = 188.97
Y_MOTOR_STEPS: int = 200
Z_STEPS_PER_INCH = z_units = 4800
Z_STEPS_PER_MM: float = 188.97
Z_STEPS_PER_INCH = 4800
Z_STEPS_PER_MM = z_units = 188.97
Z_MOTOR_STEPS: int = 200
FAST_XY_FEEDRATE: float = 100 # in m/mn
FAST_Z_FEEDRATE: float = 100
FAST_XY_FEEDRATE: float = 1 # in m/mn
FAST_Z_FEEDRATE: float = 1
CURVE_SECTION_INCHES = curve_section = .019685
CURVE_SECTION_MM: float = .5
@ -87,8 +87,7 @@ class GCodeToMotors:
return steps_per_unit * units
def calculate_deltas(self):
self.delta_units = list(map(lambda t: abs(t[0] - t[1]), zip(self.target_units, self.current_units)))
self.delta_steps = list(map(lambda t: abs(t[0] - t[1]), zip(self.target_steps, self.current_steps)))
self.delta_units = list(map(lambda t: (t[0] - t[1]), zip(self.target_units, self.current_units)))
self.current_steps[0] = self.to_steps(self.x_units, self.current_units[0])
self.current_steps[1] = self.to_steps(self.y_units, self.current_units[1])
@ -97,6 +96,8 @@ class GCodeToMotors:
self.target_steps[0] = self.to_steps(self.x_units, self.target_units[0])
self.target_steps[1] = self.to_steps(self.y_units, self.target_units[1])
self.target_steps[2] = self.to_steps(self.z_units, self.target_units[2])
self.delta_steps = list(map(lambda t: (t[0] - t[1]), zip(self.target_steps, self.current_steps)))
self.x_direction = (self.target_units[0] >= self.current_units[0])
self.y_direction = (self.target_units[1] >= self.current_units[1])

View file

@ -60,15 +60,22 @@ class DummyController(Controller):
feed = gtm.feedrate
dx, dy, dz = gtm.delta_units
feed_x = feed * dx/(dx**2 + dy**2 + dz**2)
feed_y = feed * dy/(dx**2 + dy**2 + dz**2)
feed_z = feed * dz/(dz**2 + dy**2 + dz**2)
feed_x = feed * dx/(dx**2 + dy**2 + dz**2)**0.5
feed_y = feed * dy/(dx**2 + dy**2 + dz**2)**0.5
feed_z = feed * dz/(dz**2 + dy**2 + dz**2)**0.5
print("feed (m/min) : ", feed)
print("current : ", gtm.current_units)
print("target : ", gtm.target_units)
print("deltas: ", dx, dy, dz)
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
feed_x,feed_y,feed_z = abs(feed_x), abs(feed_y), abs(feed_z)
print("Feeds (m/min) : ", feed_x, feed_y, feed_z)
print("dirs : ", gtm.x_direction, gtm.y_direction, gtm.z_direction)
gtm.x_throttle = 0 if feed_x == 0. else np.floor(gtm.FAST_XY_FEEDRATE/feed_x)
gtm.y_throttle = 0 if feed_y == 0. else np.floor(gtm.FAST_XY_FEEDRATE/feed_y)
@ -81,4 +88,9 @@ class DummyController(Controller):
print("Throttles : ", gtm.x_throttle, gtm.y_throttle, gtm.z_throttle)
# If we are close enough, we're good
return (gtm.ctrl_step*(feed*1000./60) >= 3.*(dx**2+dy**2+dz**2)**.5)
if(gtm.x_throttle == 0 and gtm.y_throttle == 0 and gtm.z_throttle == 0):
return True
print("Expected move (mm/call)", gtm.ctrl_step*feed*1000./60)
print("Delta (mm) ", (dx**2 + dy**2 + dz**2)**.5)
return (dx**2+dy**2+dz**2)**.5 <= 1.

View file

@ -25,22 +25,33 @@ class SimuHardware(Hardware):
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())
print("HAS PROBED")
last_x, last_y, last_z = gtm.current_steps
# We are now at some position which realizes the encoder positions
# curr_x = encoder_x + k*X_MOTOR_STEPS
# |curr_x - last_x| <= 1/2 * X_MOTOR_STEPS
curr_x = encoder_x + (last_x // gtm.X_MOTOR_STEPS) * gtm.X_MOTOR_STEPS
if curr_x - last_x > .5 * gtm.X_MOTOR_STEPS:
curr_x -= gtm.X_MOTOR_STEPS
print("GOING BACKWARD, would have ", curr_x)
curr_x = curr_x - gtm.X_MOTOR_STEPS
elif curr_x - last_x < -.5*gtm.X_MOTOR_STEPS:
curr_x += gtm.X_MOTOR_STEPS
curr_y = encoder_y + (last_y // gtm.Y_MOTOR_STEPS) * gtm.Y_MOTOR_STEPS
if curr_y - last_y > .5 * gtm.Y_MOTOR_STEPS:
curr_y -= gtm.Y_MOTOR_STEPS
elif curr_y - last_y < -.5*gtm.Y_MOTOR_STEPS:
curr_y += gtm.Y_MOTOR_STEPS
curr_z = encoder_z + (last_z // gtm.Z_MOTOR_STEPS) * gtm.Z_MOTOR_STEPS
if curr_z - last_z > .5 * gtm.Z_MOTOR_STEPS:
curr_z -= gtm.Z_MOTOR_STEPS
elif curr_z - last_z < -.5*gtm.Z_MOTOR_STEPS:
curr_z += gtm.Z_MOTOR_STEPS
print("Last steps : ", gtm.current_steps)
print("Encoders : ", encoder_x, encoder_y, encoder_z)
print("Current steps : ", curr_x, curr_y, curr_z)
# Note that if we don't probe regularly enough, we lose track of the position
# Really, we should be able to set_steps
@ -65,12 +76,3 @@ class SimuHardware(Hardware):
self.s.send(str(gtm.z_direction).encode() + b" 0\n")
else:
self.s.send(str(gtm.z_direction).encode() + b" " + str(gtm.FAST_Z_FEEDRATE / gtm.z_throttle).encode() + b"\n")
if __name__ == '__main__':
b = "socket.sock"
sh = SimuHardware(b)
ctrl = DummyController()
gtm1 = GCode_Interpreterdc.GCodeToMotors(ctrl, sh)
sh.probe(gtm1)
print(gtm1.current_units)

25261
log.txt

File diff suppressed because it is too large Load diff

View file

@ -6,4 +6,8 @@ b = "socket.sock"
sh = hw.SimuHardware(b)
ctrl= ctl.DummyController()
gtm1 = gci.GCodeToMotors(ctrl, sh)
gtm1.instruction_converter("G0 X2.000 Y30.000 F1.000")
gtm1.instruction_converter("G0 X25.000 Y25.000 F0.0500")
gtm1.instruction_converter("G0 X50.000 Y30.000 F0.0500")
while(True):
print("mdr")

View file

@ -64,10 +64,8 @@ class Simulator:
self.s.setblocking(True)
match req:
case b'request\n':
print("At your service")
self.request() # These are the functions that need to be implemented
case b'realize\n':
print("Contemplating Life")
self.realize()
case b'':
break
@ -146,7 +144,7 @@ class NaiveSimulator(Simulator, Douche):
#print("timestep ", self.time_step)
#print("gamma ", gamma)
#print("speed ", self.speed)
#print("position ", self.pos)
print("position ", self.pos)
self.steps = np.ceil(self.pos * np.array([self.X_STEPS_PER_MM,
self.Y_STEPS_PER_MM,
@ -154,16 +152,14 @@ class NaiveSimulator(Simulator, Douche):
self.add_point(self.pos[0], self.pos[1])
def request(self):
self.s.send(f"{int(self.steps[0])}\n".encode())
self.s.send(f"{int(self.steps[1])}\n".encode())
self.s.send(f"{int(self.steps[2])}\n".encode())
self.s.send(f"{int(self.steps[0] % self.X_MOTOR_STEPS)}\n".encode())
self.s.send(f"{int(self.steps[1] % self.Y_MOTOR_STEPS)}\n".encode())
self.s.send(f"{int(self.steps[2] % self.Z_MOTOR_STEPS)}\n".encode())
def realize(self):
print("I JUST REALIZED: MA VIE C'EST DE LA MERDE")
x_v = parse_speed(socket.SocketIO(self.s, 'r').readline())
y_v = parse_speed(socket.SocketIO(self.s, 'r').readline())
z_v = parse_speed(socket.SocketIO(self.s, 'r').readline())
print("Everything parsed")
self.command_spd = np.array([x_v, y_v, z_v])
print("New speeds : ", self.command_spd)
#self.s.send("Realized\n".encode())