def test_extruderTriggers_NoFilter(self): """Test the extruder triggers""" # test with no filters - should trigger self.Extruder.reset() state = ExtruderState() self.Extruder.add_state(state) state.is_primed = False # turn this off so we don't have to account for this default state triggers = ExtruderTriggers(None, None, None, None, None, None, None, None, None, None) self.assertTrue(self.Extruder.is_triggered(triggers))
def test_extruderTriggers_on_primed(self): self.Extruder.reset() state = ExtruderState() self.Extruder.add_state(state) triggers = ExtruderTriggers(None, None, True, None, None, None, None, None, None, None) # test True with true filter state.is_primed = True self.assertTrue(self.Extruder.is_triggered(triggers)) # test False with True filter state.is_primed = False self.assertTrue(not self.Extruder.is_triggered(triggers)) # test on_primed - False Filter triggers = ExtruderTriggers(None, None, False, None, None, None, None, None, None, None) # test True with False filter state.is_primed = True self.assertTrue(not self.Extruder.is_triggered(triggers)) # test False with False filter state.is_primed = 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.extrusion_length = 100 state.extruder_length_total = 200 state.retraction_length = 300 state.deretraction_length = 400 state.is_extruding_start = True state.is_extruding = True state.is_primed = True state.is_retracting_start = True state.is_retracting = True state.is_partially_retracted = True state.is_retracted = True state.is_deretracting_start = True state.is_deretracting = True state.is_deretracted = True state.has_changed = 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.extrusion_length, 100) self.assertEquals(new_state.extruder_length_total, 200) self.assertEquals(new_state.retraction_length, 300) self.assertEquals(new_state.deretraction_length, 400) self.assertTrue(new_state.is_extruding_start) self.assertTrue(new_state.is_extruding) self.assertTrue(new_state.is_primed) self.assertTrue(new_state.is_retracting_start) self.assertTrue(new_state.is_retracting) self.assertTrue(new_state.is_partially_retracted) self.assertTrue(new_state.is_retracted) self.assertTrue(new_state.is_deretracting_start) self.assertTrue(new_state.is_deretracting) self.assertTrue(new_state.is_deretracted) self.assertTrue(new_state.has_changed)
def test_extruderTriggers_on_deretracted(self): # test on_deretracted self.Extruder.reset() state = ExtruderState() self.Extruder.add_state(state) triggers = ExtruderTriggers(None, None, None, None, None, None, None, None, None, True) # test True with true filter state.is_deretracted = True state.is_primed = 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.is_deretracted = False self.assertTrue(not self.Extruder.is_triggered(triggers)) # test on_deretracted - False Filter triggers = ExtruderTriggers(None, None, None, None, None, None, None, None, None, False) # test True with False filter state.is_deretracted = True self.assertTrue(not self.Extruder.is_triggered(triggers)) # test False with False filter state.is_deretracted = False self.assertTrue(not self.Extruder.is_triggered(triggers))
def test_extruderTriggers_on_extruding_start(self): self.Extruder.reset() state = ExtruderState() self.Extruder.add_state(state) # test on_extruding_start - True Filter triggers = ExtruderTriggers(True, None, None, None, None, None, None, None, None, None) # test True with true filter state.is_extruding_start = True state.is_primed = 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.is_extruding_start = False self.assertTrue(not self.Extruder.is_triggered(triggers)) # test on_extruding_start - False Filter triggers = ExtruderTriggers(False, None, None, None, None, None, None, None, None, None) # test True with False filter state.is_extruding_start = True self.assertTrue(not self.Extruder.is_triggered(triggers)) # test False with False filter state.is_extruding_start = False self.assertTrue(not self.Extruder.is_triggered(triggers))
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 is_primed state.is_extruding_start = True state.is_extruding = True state.is_primed = True state.is_retracting_start = True state.is_retracting = True state.is_partially_retracted = False state.is_retracted = True state.is_deretracting_start = True state.is_deretracting = False state.is_deretracted = True self.assertTrue(not self.Extruder.is_triggered(triggers)) # True - is extruding state.is_extruding_start = False state.is_extruding = True state.is_primed = False state.is_retracting_start = True state.is_retracting = False state.is_partially_retracted = False state.is_retracted = True state.is_deretracting_start = False state.is_deretracting = False state.is_deretracted = True self.assertTrue(self.Extruder.is_triggered(triggers)) # Test all false states and all Nones state.is_extruding_start = True state.is_extruding = True state.is_primed = True state.is_retracting_start = True state.is_retracting = True state.is_partially_retracted = True state.is_retracted = True state.is_deretracting_start = True state.is_deretracting = True state.is_deretracted = 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_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.require_zhop = False # no zhop required trigger.height_increment = 0 # Trigger on every layer change # get the current extruder state state = position.Extruder.current_state # 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.is_extruding_start = 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.is_primed = False # try out on extruding state.is_extruding = 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.is_primed = False # try out on primed trigger.ExtruderTriggers = ExtruderTriggers(None, None, True, None, None, None, None, None, None, None) state.is_primed = 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.is_primed = False # try out on retracting start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, True, None, None, None, None, None, None) state.is_retracting_start = 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.is_primed = False # try out on retracting trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, True, None, None, None, None, None) state.is_retracting = 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.is_primed = False # try out on partially retracted trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, True, None, None, None, None) state.is_partially_retracted = 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.is_primed = False # try out on retracted trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, True, None, None, None) state.is_retracted = 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.is_primed = False # try out on deretracting Start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, True, None, None) state.is_deretracting_start = 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.is_primed = False # try out on deretracting Start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, None, True, None) state.is_deretracting = 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.is_primed = False trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, None, None, True) state.is_deretracted = True trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0))
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.interval_seconds = 1 trigger.require_zhop = 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).trigger_start_time = 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].is_extruding_start = 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.is_extruding = True trigger.get_state(0).trigger_start_time = 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.is_primed = True trigger.get_state(0).trigger_start_time = 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.is_retracting_start = True trigger.get_state(0).trigger_start_time = 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.is_retracting = True trigger.get_state(0).trigger_start_time = 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.is_partially_retracted = True trigger.get_state(0).trigger_start_time = 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.is_retracted = True trigger.get_state(0).trigger_start_time = 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 deretracting Start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, True, None, None) state.is_deretracting_start = True trigger.get_state(0).trigger_start_time = 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 deretracting Start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, None, True, None) state.is_deretracting = True trigger.get_state(0).trigger_start_time = 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 deretracting Start trigger.ExtruderTriggers = ExtruderTriggers(None, None, None, None, None, None, None, None, None, True) state.is_deretracted = True trigger.get_state(0).trigger_start_time = time.time() - 1.01 trigger.update(position) self.assertTrue(trigger.is_triggered(0)) self.assertFalse(trigger.is_waiting(0))