Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

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

    Scheduled Pinned Locked Moved
    Firmware wishlist
    6
    20
    1.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T3P3Tonyundefined
      T3P3Tony administrators @FBG
      last edited by T3P3Tony

      @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).

      www.duet3d.com

      FBGundefined 1 Reply Last reply Reply Quote 1
      • dc42undefined
        dc42 administrators
        last edited by

        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?

        Duet WiFi hardware designer and firmware engineer
        Please do not ask me for Duet support via PM or email, use the forum
        http://www.escher3d.com, https://miscsolutions.wordpress.com

        1 Reply Last reply Reply Quote 0
        • FBGundefined
          FBG @T3P3Tony
          last edited by

          @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...

          1 Reply Last reply Reply Quote 0
          • felekundefined
            felek
            last edited by

            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
            
            Phaedruxundefined 1 Reply Last reply Reply Quote 0
            • Phaedruxundefined
              Phaedrux Moderator
              last edited by

              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?

              Z-Bot CoreXY Build | Thingiverse Profile

              FBGundefined 1 Reply Last reply Reply Quote 0
              • Phaedruxundefined
                Phaedrux Moderator @felek
                last edited by

                @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.

                Z-Bot CoreXY Build | Thingiverse Profile

                felekundefined 1 Reply Last reply Reply Quote 0
                • FBGundefined
                  FBG @Phaedrux
                  last edited by

                  @Phaedrux understood, tomorrow i will check

                  1 Reply Last reply Reply Quote 0
                  • dc42undefined
                    dc42 administrators
                    last edited by

                    @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?

                    Duet WiFi hardware designer and firmware engineer
                    Please do not ask me for Duet support via PM or email, use the forum
                    http://www.escher3d.com, https://miscsolutions.wordpress.com

                    1 Reply Last reply Reply Quote 0
                    • felekundefined
                      felek @Phaedrux
                      last edited by

                      @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 🙂

                      FBGundefined 1 Reply Last reply Reply Quote 0
                      • T3P3Tonyundefined
                        T3P3Tony administrators
                        last edited by

                        @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.

                        www.duet3d.com

                        felekundefined 1 Reply Last reply Reply Quote 0
                        • dc42undefined
                          dc42 administrators
                          last edited by

                          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?

                          Duet WiFi hardware designer and firmware engineer
                          Please do not ask me for Duet support via PM or email, use the forum
                          http://www.escher3d.com, https://miscsolutions.wordpress.com

                          1 Reply Last reply Reply Quote 0
                          • felekundefined
                            felek @T3P3Tony
                            last edited by

                            @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

                            1 Reply Last reply Reply Quote 0
                            • FBGundefined
                              FBG @felek
                              last edited by

                              @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...?

                              Phaedruxundefined 1 Reply Last reply Reply Quote 0
                              • Phaedruxundefined
                                Phaedrux Moderator @FBG
                                last edited by

                                @FBG What exactly do you have right now?

                                Z-Bot CoreXY Build | Thingiverse Profile

                                1 Reply Last reply Reply Quote 0
                                • FBGundefined
                                  FBG
                                  last edited by

                                  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?

                                  1 Reply Last reply Reply Quote 0
                                  • FBGundefined
                                    FBG
                                    last edited by

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

                                    Starting a loop....

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post
                                    Unless otherwise noted, all forum content is licensed under CC-BY-SA