MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.35k stars 19.26k forks source link

[FR] True filament sensing #13699

Open klcjr89 opened 5 years ago

klcjr89 commented 5 years ago

Description

I have finished working on my true volumetric filament sensor, and I believe it requires the code in filwidth.cpp and planner.cpp to be changed (not sure about other files), as the old code assumes measurement is done in one axis.

My sensor measures the filament 360º around the periphery of the filament, and outputs an analog voltage that is a delta value. The sensor is calibrated with a precision ground 1.750mm OD pin gage, used as a standard. Whatever the voltage output is of the sensor with the pin gage in the sensor, could be set with a gcode as the 'reference/nominal', which I believe is currently in Marlin. If the voltage was hypothetically 1 volt, Marlin needs to know this, and do delta based measurements from the 1v 'reference' point. With this possibility in code, a potentiometer could be eliminated on the PCB for calibrating.

Since my sensor reports the voltage based on the cross section and not one axis like the old filament sensors, I am not sure what formula needs changed in the source files.

For sanity, it may be best to have a macro that specifies whether the sensor is a single axis (width/diameter) sensor, or a true volumetric sensor, that way the user can specify which sensor they have when I begin selling the sensors.

ghost commented 5 years ago

Curious as to what method you're using to measure the filament cross sectional area ?

klcjr89 commented 5 years ago

Any update on what formula needs changed and how this can be implemented for the main branch?

klcjr89 commented 5 years ago

@thinkyhead Any pointers?

thinkyhead commented 5 years ago

The FILAMENT_WIDTH_SENSOR in Marlin reads a resistance via ADC and uses this to determine the likely width of the filament. This function converts the latest ADC reading to a millimeter value:

  // Convert raw Filament Width to millimeters
  float Temperature::analog_to_mm_fil_width() {
    return current_raw_filwidth * 5.0f * (1.0f / 16383.0f);
  }
klcjr89 commented 5 years ago

@thinkyhead I realize that, but my sensor outputs a voltage based on the periphery of the filament (the most ideal way). So I'm not sure how to figure out the formula. A 1.750mm precision ground standard is used as the reference point and the voltage is 1.750mV

lrpirlet commented 5 years ago

circumference = Pi Diameter… Pi is a constant so, your function will end-up with a parallel function… So, if you make sure that a circumference of 3Pi outputs a voltage of 3 volts a circumference of 2.8*Pi will output 2.8 volts… KISS :-)

lrpirlet commented 5 years ago

Haha my text got formatted unexpectedly, please read circumference = Pi Diameter… Pi is a constant so, your function will end-up with a parallel function… So, if you make sure that a circumference of 3 Pi outputs a voltage of 3 volts a circumference of 2.8 * Pi will output 2.8 volts… KISS :-)

AnHardt commented 5 years ago

If your sensor is measuring the filaments circumference instead of its area (cross section) you don't get any advantage over measuring the diameter. As long the filament is round non of the different measured values has an advantage over an other, it's just an other calculation to find the filaments area (what we are looking for). As soon as the filament is not round only directly measuring the area will give you the area (and i have no clue how that could work). Calculating the area from the circumference is impossible without a assumption about the shape of the measured object. Even if you assume an ellipse (the second simplest shape after the circle ) the area/circumference relation depends on the shape (eccentricity) of the ellipse. (If the small and the big length of the axes are identical you get a circle. If the small axis goes to zero the circumference goes to two times the large axis and the area goes to zero.)

What is your sensor measuring? How does it work?

AnHardt commented 5 years ago

when I begin selling the sensors.

Confusing circumference and area (cross section) by the inventor/producer/seller of a sensor, when discribing his product, shrinks the trust into the product to below zero.

klcjr89 commented 5 years ago

Sorry to confuse you. Periphery may be a better term; and yes, you can find a better sectional area with this rather than a traditional single axis caliper sensor. I don't care if the filament is round or not, It could be egg-shaped and it wouldn't matter in my case.

What I need to know is how to change the stock formula in Marlin.

InsanityAutomation commented 5 years ago

Honestly aside from the difference with a 3.3v analog input on the LPC1768/9 you may not need to. Youre looking at standard deviation from setpoint moreso than anything else. It may need to be done in the HAL per platform based on logic level. Ill have to take a look once i have something to hook up and look at now that.

sjasonsmith commented 4 years ago

@klcjr89 is this still something you are working on?