def update_position(self, bounding_box, x=None, y=None, z=None, e=None, f=None, force=False): if f is not None: self.F = float(f) if force: # Force the coordinates in as long as they are provided. # if x is not None: x = float(x) x = x + self.XOffset self.X = x if y is not None: y = float(y) y = y + self.YOffset self.Y = y if z is not None: z = float(z) z = z + self.ZOffset self.Z = z if e is not None: e = float(e) e = e + self.EOffset self.E = e else: # Update the previous positions if values were supplied if x is not None and self.XHomed: x = float(x) if self.IsRelative: if self.X is not None: self.X += x else: self.X = x + self.XOffset if y is not None and self.YHomed: y = float(y) if self.IsRelative: if self.Y is not None: self.Y += y else: self.Y = y + self.YOffset if z is not None and self.ZHomed: z = float(z) if self.IsRelative: if self.Z is not None: self.Z += z else: self.Z = z + self.ZOffset if e is not None: e = float(e) if self.IsExtruderRelative: if self.E is not None: self.E += e else: self.E = e + self.EOffset if (not utility.is_in_bounds( bounding_box, x=self.X, y=self.Y, z=self.Z)): self.HasPositionError = True self.PositionError = "Position - Coordinates {0} are out of the printer area! " \ "Cannot resume position tracking until the axis is homed, " \ "or until absolute coordinates are received.".format( get_formatted_coordinates(self.X, self.Y, self.Z, self.E)) else: self.HasPositionError = False self.PositionError = None
def test_IsInBounds_CustomBox(self): """Test the IsInBounds function to make sure the program will not attempt to operate after being told to move out of bounds. """ # test custom box with values above zero bounding_box = { "min_x": 1, "max_x": 200, "min_y": 1, "max_y": 200, "min_z": 1, "max_z": 200 } # Initial test, should return false without any coordinates self.assertFalse(utility.is_in_bounds(bounding_box, None, None, None)) # test the origin (min), should return false self.assertFalse(utility.is_in_bounds(bounding_box, 0, 0, 0)) # test 1,1,1 - True self.assertTrue(utility.is_in_bounds(bounding_box, 1, 1, 1)) # move X out of bounds - Min self.assertFalse(utility.is_in_bounds(bounding_box, .9999, 1, 1)) # move X out of bounds - Max self.assertFalse(utility.is_in_bounds(bounding_box, 200.0001, 1, 1)) # move X in bounds - Max self.assertTrue(utility.is_in_bounds(bounding_box, 200.0000, 1, 1)) # move X in bounds - Middle self.assertTrue(utility.is_in_bounds(bounding_box, 100.5000, 1, 1)) # move Y out of bounds - Min self.assertFalse(utility.is_in_bounds(bounding_box, 1, .9999, 1)) # move Y out of bounds - Max self.assertFalse(utility.is_in_bounds(bounding_box, 1, 200.0001, 1)) # move Y in bounds - Max self.assertTrue(utility.is_in_bounds(bounding_box, 1, 200.0000, 1)) # move Y in bounds - Middle self.assertTrue(utility.is_in_bounds(bounding_box, 1, 100.5000, 1)) # move Z out of bounds - Min self.assertFalse(utility.is_in_bounds(bounding_box, 1, 1, .9999)) # move Z out of bounds - Max self.assertFalse(utility.is_in_bounds(bounding_box, 1, 1, 200.0001)) # move Z in bounds - Max self.assertTrue(utility.is_in_bounds(bounding_box, 1, 1, 200.0000)) # move Z in bounds - Middle self.assertTrue(utility.is_in_bounds(bounding_box, 1, 1, 100.5000))
def test_IsInBounds_AllNegativeMin(self): # test custom box with all negative min values bounding_box = { "min_x": -100, "max_x": -50, "min_y": -100, "max_y": -50, "min_z": -100, "max_z": -50 } # test X axis # move out of bounds - Min self.assertFalse( utility.is_in_bounds(bounding_box, -100.0001, -100, -100)) # move out of bounds - Max self.assertFalse( utility.is_in_bounds(bounding_box, -49.9999, -100, -100)) # move in bounds - Max self.assertTrue( utility.is_in_bounds(bounding_box, -50.0000, -100, -100)) # move in bounds - Middle self.assertTrue( utility.is_in_bounds(bounding_box, -75.0000, -100, -100)) # test Y axis # move out of bounds - Min self.assertFalse( utility.is_in_bounds(bounding_box, -100, -100.0001, -100)) # move out of bounds - Max self.assertFalse( utility.is_in_bounds(bounding_box, -100, -49.9999, -100)) # move in bounds - Max self.assertTrue( utility.is_in_bounds(bounding_box, -100, -50.0000, -100)) # move in bounds - Middle self.assertTrue( utility.is_in_bounds(bounding_box, -100, -75.0000, -100)) # test Z axis # move out of bounds - Min self.assertFalse( utility.is_in_bounds(bounding_box, -100, -100, -100.0001)) # move out of bounds - Max self.assertFalse( utility.is_in_bounds(bounding_box, -100, -100, -49.9999)) # move in bounds - Max self.assertTrue( utility.is_in_bounds(bounding_box, -100, -100, -50.0000)) # move in bounds - Middle self.assertTrue( utility.is_in_bounds(bounding_box, -100, -100, -75.0000))
def test_IsInBounds(self): """Test the IsInBounds function to make sure the program will not attempt to operate after being told to move out of bounds. """ bounding_box = { "min_x": 0, "max_x": 250, "min_y": 0, "max_y": 200, "min_z": 0, "max_z": 200 } # Initial test, should return false without any coordinates self.assertFalse(utility.is_in_bounds(bounding_box, None, None, None), "") # test the origin (min), should return true self.assertTrue(utility.is_in_bounds(bounding_box, 0, 0, 0)) # move X out of bounds of the min self.assertFalse(utility.is_in_bounds(bounding_box, -0.0001, 0, 0)) # move X out of bounds of the max self.assertFalse(utility.is_in_bounds(bounding_box, 250.0001, 0, 0)) # move X to the max of bounds of the max self.assertTrue(utility.is_in_bounds(bounding_box, 250.0000, 0, 0)) # move Y out of bounds of the min self.assertFalse(utility.is_in_bounds(bounding_box, 0, -0.0001, 0)) # move Y out of bounds of the max self.assertFalse(utility.is_in_bounds(bounding_box, 0, 200.0001, 0)) # move Y to the max of bounds of the max self.assertTrue(utility.is_in_bounds(bounding_box, 0, 200.0000, 0)) # move Z out of bounds of the min self.assertFalse(utility.is_in_bounds(bounding_box, 0, 0, -0.0001)) # move Z out of bounds of the max self.assertFalse(utility.is_in_bounds(bounding_box, 0, 0, 200.0001)) # move Z to the max of bounds of the max self.assertTrue(utility.is_in_bounds(bounding_box, 0, 0, 200.0000))
def test_IsInBounds_NegativeMin(self): # test custom box with negative min values bounding_box = { "min_x": -1, "max_x": 250, "min_y": -2, "max_y": 200, "min_z": -3, "max_z": 200 } # move X out of bounds - Min self.assertFalse(utility.is_in_bounds(bounding_box, -1.0001, 1, 1)) # move X out of bounds - Max self.assertFalse(utility.is_in_bounds(bounding_box, 250.0001, 1, 1)) # move X in bounds - Max self.assertTrue(utility.is_in_bounds(bounding_box, 250.0000, 1, 1)) # move X in bounds - Middle self.assertTrue(utility.is_in_bounds(bounding_box, 123.5000, 1, 1)) # move Y out of bounds - Min self.assertFalse(utility.is_in_bounds(bounding_box, 1, -2.0001, 1)) # move Y out of bounds - Max self.assertFalse(utility.is_in_bounds(bounding_box, 1, 200.0001, 1)) # move Y in bounds - Max self.assertTrue(utility.is_in_bounds(bounding_box, 1, 200.0000, 1)) # move Y in bounds - Middle self.assertTrue(utility.is_in_bounds(bounding_box, 1, 99.0000, 1)) # move Z out of bounds - Min self.assertFalse(utility.is_in_bounds(bounding_box, 1, 1, -3.0001)) # move Z out of bounds - Max self.assertFalse(utility.is_in_bounds(bounding_box, 1, 1, 200.0001)) # move Z in bounds - Max self.assertTrue(utility.is_in_bounds(bounding_box, 1, 1, 200.0000)) # move Z in bounds - Middle self.assertTrue(utility.is_in_bounds(bounding_box, 1, 1, 98.5000))