def test_extruderTriggers_OnPartiallyRetracted(self): # test OnPartiallyRetracted self.Extruder.reset() state = ExtruderState() self.Extruder.add_state(state) triggers = ExtruderTriggers(None, None, None, None, None, True, None, None, None, None) # test True with true filter state.IsPartiallyRetracted = True state.IsPrimed = False # turn this off so we don't have to account for this default state self.assertTrue(self.Extruder.is_triggered(triggers)) # test False with True filter state.IsPartiallyRetracted = False self.assertTrue(not self.Extruder.is_triggered(triggers)) # test OnPartiallyRetracted - False Filter triggers = ExtruderTriggers(None, None, None, None, None, False, None, None, None, None) # test True with False filter state.IsPartiallyRetracted = True self.assertTrue(not self.Extruder.is_triggered(triggers)) # test False with False filter state.IsPartiallyRetracted = False self.assertTrue(not self.Extruder.is_triggered(triggers))
def test_ExtruderStateCopy(self): # create a new state state = ExtruderState() # change all the default values state.E = 1 state.ExtrusionLength = 100 state.ExtrusionLengthTotal = 200 state.RetractionLength = 300 state.DetractionLength = 400 state.IsExtrudingStart = True state.IsExtruding = True state.IsPrimed = True state.IsRetractingStart = True state.IsRetracting = True state.IsPartiallyRetracted = True state.IsRetracted = True state.IsDetractingStart = True state.IsDetracting = True state.IsDetracted = True state.HasChanged = True # copy to a new state new_state = ExtruderState(state) # verify the state was copied correctly self.assertEquals(new_state.E, 1) self.assertEquals(new_state.ExtrusionLength, 100) self.assertEquals(new_state.ExtrusionLengthTotal, 200) self.assertEquals(new_state.RetractionLength, 300) self.assertEquals(new_state.DetractionLength, 400) self.assertTrue(new_state.IsExtrudingStart) self.assertTrue(new_state.IsExtruding) self.assertTrue(new_state.IsPrimed) self.assertTrue(new_state.IsRetractingStart) self.assertTrue(new_state.IsRetracting) self.assertTrue(new_state.IsPartiallyRetracted) self.assertTrue(new_state.IsRetracted) self.assertTrue(new_state.IsDetractingStart) self.assertTrue(new_state.IsDetracting) self.assertTrue(new_state.IsDetracted) self.assertTrue(new_state.HasChanged)
def test_LayerTrigger_ExtruderTriggers(self): """Test All Extruder Triggers""" position = Position(self.Settings, self.OctoprintPrinterProfile, False) # home the axis position.update("G28") trigger = LayerTrigger(self.Settings) trigger.RequireZHop = False # no zhop required trigger.HeightIncrement = 0 # Trigger on every layer change # get the current extruder state state = position.Extruder.get_state(0) # Try on extruding start right after home, should fail since we haven't extruded yet trigger.ExtruderTriggers = ExtruderTriggers(True, None, None, None, None, None, None, None, None, None) state.IsExtrudingStart = True trigger.update(position) self.assertFalse(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Try again, should trigger after the extrusion position.update("G1 E1") trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False # try out on extruding state.IsExtruding = True trigger.ExtruderTriggers = ExtruderTriggers(None, True, None, None, None, None, None, None, None, None) trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False # try out on primed trigger.ExtruderTriggers = ExtruderTriggers(None, None, True, None, None, None, None, None, None, None) state.IsPrimed = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False # try out on retracting start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, True, None, None, None, None, None, None) state.IsRetractingStart = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False # try out on retracting trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, True, None, None, None, None, None) state.IsRetracting = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False # try out on partially retracted trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, True, None, None, None, None) state.IsPartiallyRetracted = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False # try out on retracted trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, True, None, None, None) state.IsRetracted = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False # try out on detracting Start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, True, None, None) state.IsDetractingStart = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False # try out on detracting Start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, None, True, None) state.IsDetracting = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the previous extruder state state = ExtruderState() position.Extruder.StateHistory[0] = state state.IsPrimed = False trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, None, None, True) state.IsDetracted = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0))
def test_extruderTriggers_Mixed(self): # Test mixed nones, trues and falses self.Extruder.reset() state = ExtruderState() self.Extruder.add_state(state) triggers = ExtruderTriggers(None, True, False, None, True, False, None, True, False, None) # Forbidden Due to IsPrimed state.IsExtrudingStart = True state.IsExtruding = True state.IsPrimed = True state.IsRetractingStart = True state.IsRetracting = True state.IsPartiallyRetracted = False state.IsRetracted = True state.IsDetractingStart = True state.IsDetracting = False state.IsDetracted = True self.assertTrue(not self.Extruder.is_triggered(triggers)) # True - is extruding state.IsExtrudingStart = False state.IsExtruding = True state.IsPrimed = False state.IsRetractingStart = True state.IsRetracting = False state.IsPartiallyRetracted = False state.IsRetracted = True state.IsDetractingStart = False state.IsDetracting = False state.IsDetracted = True self.assertTrue(self.Extruder.is_triggered(triggers)) # Test all false states and all Nones state.IsExtrudingStart = True state.IsExtruding = True state.IsPrimed = True state.IsRetractingStart = True state.IsRetracting = True state.IsPartiallyRetracted = True state.IsRetracted = True state.IsDetractingStart = True state.IsDetracting = True state.IsDetracted = True triggers = ExtruderTriggers(None, None, None, None, None, None, None, None, None, None) self.assertTrue(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(False, True, True, True, True, True, True, True, True, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, False, True, True, True, True, True, True, True, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, True, False, True, True, True, True, True, True, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, True, True, False, True, True, True, True, True, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, True, True, True, False, True, True, True, True, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, True, True, True, True, False, True, True, True, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, True, True, True, True, True, False, True, True, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, True, True, True, True, True, True, False, True, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, True, True, True, True, True, True, True, False, True) self.assertFalse(self.Extruder.is_triggered(triggers)) triggers = ExtruderTriggers(True, True, True, True, True, True, True, True, True, False) self.assertFalse(self.Extruder.is_triggered(triggers))
def test_TimerTrigger_ExtruderTriggers(self): """Test All Extruder Triggers""" position = Position(self.Settings, self.OctoprintPrinterProfile, False) # home the axis position.update("G28") trigger = TimerTrigger(self.Settings) trigger.IntervalSeconds = 1 trigger.RequireZHop = False # no zhop required # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # Try on extruding start - previous position not homed, do not trigger trigger.ExtruderTriggers = ExtruderTriggers( True, None, None, None, None, None, None, None, None, None) trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertFalse(trigger.is_triggered(0)) self.assertTrue(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # send another command, now the previous state has been homed, should trigger position.update("AnotherCommandNowPreviousHomed") # set is extruding start, wont be set by the above command! position.Extruder.StateHistory[0].IsExtrudingStart = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on extruding trigger.ExtruderTriggers = ExtruderTriggers( None, True, None, None, None, None, None, None, None, None) state.IsExtruding = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on primed trigger.ExtruderTriggers = ExtruderTriggers( None, None, True, None, None, None, None, None, None, None) state.IsPrimed = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on retracting start trigger.ExtruderTriggers = ExtruderTriggers( None, None, None, True, None, None, None, None, None, None) state.IsRetractingStart = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on retracting trigger.ExtruderTriggers = ExtruderTriggers( None, None, None, None, True, None, None, None, None, None) state.IsRetracting = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on partially retracted trigger.ExtruderTriggers = ExtruderTriggers( None, None, None, None, None, True, None, None, None, None) state.IsPartiallyRetracted = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on retracted trigger.ExtruderTriggers = ExtruderTriggers( None, None, None, None, None, None, True, None, None, None) state.IsRetracted = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on detracting Start trigger.ExtruderTriggers = ExtruderTriggers( None, None, None, None, None, None, None, True, None, None) state.IsDetractingStart = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on detracting Start trigger.ExtruderTriggers = ExtruderTriggers( None, None, None, None, None, None, None, None, True, None) state.IsDetracting = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0)) # Reset the extruder state = ExtruderState() position.Extruder.StateHistory[0] = state # try out on detracting Start trigger.ExtruderTriggers = ExtruderTriggers( None, None, None, None, None, None, None, None, None, True) state.IsDetracted = True trigger.get_state(0).TriggerStartTime = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0))