Simple switch Run-Out Sensor too sensitive. Add timeout?



  • Hello,
    I use Duet2 with the latest firmware 3.1.1.
    I use a filament runout sensor which is basically a switch.

    https://reprapworld.es/products/extruder/extruder_parts/filament_detection/filament_run_out_sensor_1_75mm/
    

    The problem is that when there is filament the switch is pushed and the sensor is on (Led on on the board), if at any time during the printing there is any interference or the diameter is smaller than normal, the sensor is not pushed and the printer pauses and indicates no filament
    I think it is usually interference of maybe a few milliseconds, but enough to stop the printer.

    My idea is:
    When the duet reads the sensor OFF for at least 5 seconds (or 2), the duet reports NO Filament.

    I don't know if it is possible to configure this, or maybe with MetaCommands it is possible. I do not think so.

    Someone understands me?



  • I have a simple switch sensor that triggers way too often, even though I have redesigned the switch enclosure a few times and feel like I have it exactly right, where my switch is only pressed when filament is present. Still, I get unwanted pauses all the time.

    I'm going to replace the switch itself to be sure, but I like your idea of a timed outage before taking any action.


  • administrators

    Having a time out and/or some other software debouncing sounds like a good idea. As this would be implemented in RepRapFrimware I am going to move it to the Feature requests category.



  • I think that is absolutly necessary, with a meta command of timer will be possible


  • administrators

    @FBG if you are using 3.x and you are happy to check only every second or so then you can also achieve this using daemon.g. Instead of using M591 you can set the pin up as a GPIO using M950 J and then check the state in daemon.g, if its triggered, dwell for 500ms, then check again, if its still triggered then call pause.g, if not then loop (with another 500ms dwell).


  • administrators

    I'll add it to the firmware wish list; but I am not going to buy what, from the behaviour you describe, appears to be a poorly-designed filament sensor in order to test the change. Therefore, when I implement this feature, I will be relying on you to test it.

    Have you considered getting a better filament sensor?



  • @T3P3Tony i am happy and nervous to test this, but could you helpme a little? I understand the M950 but i dont understabd what do you mean with daemon.g and how do the loop?

    @dc42 i tested several diferent brands and always happen me the same...



  • I think that checking filament sensor after some time is not good idea. What if printer is doing long travel without extrusion?
    Recently I've started implemening extra version of simple filament monitor. Instead of using time I use extrude length.
    I assume it is better because I follow the extrusion.

    Let's look at my code. I added extra parameter L. After L mm if filament is sill out the printer will pause

    /*
     * SimpleFilamentSensor.cpp
     *
     *  Created on: 20 Jul 2017
     *      Author: David
     */
    
    #include "SimpleFilteredFilamentMonitor.h"
    #include "RepRap.h"
    #include "Platform.h"
    #include "GCodes/GCodeBuffer.h"
    
    SimpleFilteredFilamentMonitor::SimpleFilteredFilamentMonitor(unsigned int extruder, int type)
    	: FilamentMonitor(extruder, type), highWhenNoFilament(type == 12), filamentPresent(false), enabled(false)
    {
    	filterDistance = 2.0;
    }
    
    // Configure this sensor, returning true if error and setting 'seen' if we processed any configuration parameters
    bool SimpleFilteredFilamentMonitor::Configure(GCodeBuffer& gb, const StringRef& reply, bool& seen)
    {
    	if (ConfigurePin(gb, reply, INTERRUPT_MODE_NONE, seen))
    	{
    		return true;
    	}
    
    	seen = false;
    	float tempfilterDistance;
    
    	gb.TryGetFValue('L', tempfilterDistance, seen);
    	if (seen)
    	{
    		filterDistance = tempfilterDistance > 0 ? tempfilterDistance : 2.0;
    	}
    
    	if (gb.Seen('S'))
    	{
    		seen = true;
    		enabled = (gb.GetIValue() > 0);
    	}
    
    	if (seen)
    	{
    		Check(false, false, 0, 0.0);
    	}
    	else
    	{
    		reply.printf("Simple filtered filament sensor on endstop %d, %s, output %s when no filament, filament present: %s, filter distance: %.2f",
    						GetEndstopNumber(),
    						(enabled) ? "enabled" : "disabled",
    						(highWhenNoFilament) ? "high" : "low",
    						(filamentPresent) ? "yes" : "no",
    						(double)filterDistance);
    	}
    
    	return false;
    }
    
    void SimpleFilteredFilamentMonitor::GetConfiguration(const StringRef& reply)
    {
    	reply.printf("P%s C%d S%d L%.2f", highWhenNoFilament ? "12" : "11", GetEndstopNumber(), enabled, (double)filterDistance);
    }
    
    // ISR for when the pin state changes
    bool SimpleFilteredFilamentMonitor::Interrupt()
    {
    	// Nothing needed here
    	detachInterrupt(GetPin());
    	return false;
    }
    
    // Call the following regularly to keep the status up to date
    void SimpleFilteredFilamentMonitor::Poll()
    {
    	const bool b = IoPort::ReadPin(GetPin());
    	filamentPresent = (highWhenNoFilament) ? !b : b;
    }
    
    // Call the following at intervals to check the status. This is only called when extrusion is in progress or imminent.
    // 'filamentConsumed' is the net amount of extrusion since the last call to this function.
    FilamentSensorStatus SimpleFilteredFilamentMonitor::Check(bool isPrinting, bool fromIsr, uint32_t isrMillis, float filamentConsumed)
    {
    	Poll();
    	// adding the current extrusion measured value to the total value
    	AddExtrusionMeasured(filamentConsumed);
    
    	FilamentSensorStatus fstat = (!enabled || filamentPresent) ? FilamentSensorStatus::ok : FilamentSensorStatus::noFilament;
    
    	if (fstat == FilamentSensorStatus::noFilament)
    	{
    		fstat = FilamentSensorStatus::ok;
    
    		if (!firstNoFilament)
    		{
    			firstNoFilament = true;
    			followFilamentChange = GetExtrusionMeasured();
    		}
    		else
    		{
    			const float totalExtrusion = GetExtrusionMeasured();
    
    			if (totalExtrusion - followFilamentChange > filterDistance)
    			{
    				firstNoFilament = false;
    				fstat = FilamentSensorStatus::noFilament;			
                            }
    		}
    	}
    	else
    	{
    		firstNoFilament = false;
    	}
    
    	return fstat;
    }
    
    // Clear the measurement state - called when we are not printing a file. Return the present/not present status if available.
    FilamentSensorStatus SimpleFilteredFilamentMonitor::Clear()
    {
    	Poll();
    	return (!enabled || filamentPresent) ? FilamentSensorStatus::ok : FilamentSensorStatus::noFilament;
    }
    
    // Print diagnostic info for this sensor
    void SimpleFilteredFilamentMonitor::Diagnostics(MessageType mtype, unsigned int extruder)
    {
    	reprap.GetPlatform().MessageF(mtype, "Extruder %u sensor: %s\n", extruder, (filamentPresent) ? "ok" : "no filament");
    }
    
    // End
    

  • Moderator

    Whenever a spring arm is being used to depress a microswitch there will be difficulties keeping the switch depressed because of the varying tolerances of the switch and the filament passing through.

    Adding a time out could make them a bit more reliable.

    daemon.g is a macro file that gets run repeatedly during operation. Inside that file you could place your M581 to check the pin created in M950 to see if the switch is still depressed.

    https://duet3d.dozuki.com/Wiki/Gcode?revisionid=HEAD#Section_M581_Configure_external_trigger

    M950 in config.g to define a pin for the switch
    M581 in daemon.g to check if the switch is still depressed.

    You can add a G4 P500 command to add a 500 millisecond delay.

    Does that make more sense?


  • Moderator

    @felek said in Simple switch Run-Out Sensor too sensitive. Add timeout?:

    What if printer is doing long travel without extrusion?

    In this case nothing would happen since it's just a simple switch checking for filament presence. The switch would still be depressed.



  • @Phaedrux understood, tomorrow i will check


  • administrators

    @FBG said in Simple switch Run-Out Sensor too sensitive. Add timeout?:

    https://reprapworld.es/products/extruder/extruder_parts/filament_detection/filament_run_out_sensor_1_75mm/

    Looks like the sensor is a spring-loaded switch. I can't see why such a sensor should be unreliable, as long as the filament path is sufficiently constrained. Maybe the switch mechanical sensitivity isn't properly adjusted? Can you provide a photo of the filament path where it passes the switch?



  • @Phaedrux I get it, but I think a bit different.

    Let's look an example:

    • printing some part
    • switch is depressed
    • printer is doing long travel > 2s (no extrusion)
    • in this time we check switch (interval 500ms/1s) and is depressed
      so, we pause the printer

    In scenario when we check extrusion length there is no problem, because while traveling we don't have extrusion.
    That is my idea 🙂


  • administrators

    @felek are you using a switch to detect filament presence/no presence or something more complicated for movement? because if just presence then there is no reason for the switch state to change if its extruding or not.


  • administrators

    My guess is that the switch only triggers when the filament is under tension. But is that intentional in the design of the filament sensor, or due to poor manufacturing or poor adjustment?



  • @T3P3Tony I'll try to explain my story.

    I bought Dyze design sensor (https://dyzedesign.com/shop/filament-detector/sentinel/)
    which looks pretty solid and it is simple on/off presence sensor.

    I tested many materials from different suppliers, as you can image sometimes quality of filament is quite low (I mean filament diameter).

    I had big trouble with this sensor, because it is optical sensor and sometimes when diameter is a bit smaller than reference sensor change the state. I checked it on oscilloscope.

    In this case SimpleFilamentMonitor doesn't work well. So I decided to rewrite this code in order to set flag when filament is depressed. It is a simple filter which remove noises from sensor. I also added parameter to help adjust filter length (extrusion length).

    I hope this image help to understand what I mean. It really helps when someone uses cheap filament sensor or low quality filament.
    673f8f7c-c4cc-4a43-b359-401907d75b3f-image.png



  • @felek @Phaedrux
    Still i don't write ok the trigger2.g file...
    If i write that wait and after check, check after some miliseconds but again start the file trigger2.g... Is a loop..
    Could you give me the exact lines that you think that i must add...?


  • Moderator

    @FBG What exactly do you have right now?



  • In config.g:
    M950 J1 C"e0_stop" ; Filament RunOut Sensor E0
    M581 T2 P1 S1 R1 ; Call trigger2.g

    In trigger2.g
    G4 S1 :Wait 1 second
    And now...What?



  • If in trigger2.g i write:
    G4 S1
    M582 T2

    Starting a loop....


Log in to reply