diff --git a/controller.py b/controller.py index bc22a46..4d3f1d8 100644 --- a/controller.py +++ b/controller.py @@ -11,6 +11,6 @@ class Controller: class PIDController(Controller): def __call__(self, gtm, *args, **kwargs): - return None + self. diff --git a/hardware.py b/hardware.py index d0e7841..72b3e31 100644 --- a/hardware.py +++ b/hardware.py @@ -8,4 +8,58 @@ class Hardware: return def realize(self, gtm: GCodeToMotors): - return \ No newline at end of file + return + + +class SimuHardware(Hardware): + def __init__(self, filename): + try: + self.f = open(filename) + except FileNotFoundError: + raise FileNotFoundError + + def probe(self, gtm): + f.write("request") + encoder_x = (int)(f.readline()) + encoder_y = (int)(f.readline()) + encoder_z = (int)(f.readline()) + + 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 + + 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 + + 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 + + # Note that if we don't probe regularly enough, we lose track of the position + # Really, we should be able to set_steps + self.set_position([curr_x/gtm.X_STEPS_PER_MM, + curr_y/gtm.Y_STEPS_PER_MM, + curr_z/gtm.Z_STEPS_PER_MM]) + + def realize(self, gtm): + f.write("realize") + + if(gtm.throttle_x == 0): + f.write(gtm.x_direction + " 0") + else: + f.write(gtm.x_direction + " " + gtm.FAST_XY_FEEDRATE/gtm.x_throttle) + + if(gtm.throttle_y == 0): + f.write(gtm.y_direction + " 0") + else: + f.write(gtm.y_direction + " " + gtm.FAST_XY_FEEDRATE/gtm.y_throttle) + + if(gtm.throttle_z == 0): + f.write(gtm.z_direction + " 0") + else: + f.write(gtm.z_direction + " " + gtm.FAST_Z_FEEDRATE/gtm.z_throttle)