Tuesday, February 22, 2022

Dealing with limit cycles in my hot end in Marlin

I replaced my Melzi 2.0 board with a Bigtree Tech SKR V1.3. 

I replaced my Bowden tube extruder with a nearly direct extruder hoping to be able to use Flex filament.

When I installed the new extruder, I had a very difficult time getting the extruder temperature under control. I repeatedly tried autotuning to get the hotend under control, but it was to no avail. I continually had temperature excursions of +/- 5 degrees C, which I had never had before. 

It appeared that the power (and cooling) in my hot end were so large that the speed of the controller was too low to keep up with the changes. But I didn't know how to troubleshoot this. I observed that during autotuning, the temperature control was *much* better than during PID control, which is exactly opposite of what I would expect. 

I finally figured out the meaning of the temperature message reported by Marlin(I never found a description on the Marlin website or anywhere else on the web). 

 Here's a typical temperature report message, as captured in the terminal on Octoprint:
Recv: T:175.89 /0.00 B:17.21 /0.00 @:0 B@:0

This tells me that the current extruder temperature is 175.89, with a setpoint of 0.  The current bed temperature is 17.21, with a setpoint of zero.  The PWM value of the extruder heater is 0, and the PWM value of the bed heater is zero.

Here's a temperature report while I'm trying to heat to 240:

Recv: T:45.23 /240.00 B:14.11 /0.00 @:127 B@:0

This shows me that I'm trying to get my extruder up to 240, but it's only at 45.23.  However, the heater is currently set to 127, which is the maximum value established in the firmware as PID_MAX.

In contrast, during autotuning, the hotend heats up a a PWM value of one half of PID_MAX.  If PID_MAX is set to 127, heating during autotuning will be at 63.  If PID_MAX is set too low, you will never be able to get up to temperature for autotuning.

In my case, I had PID_FUNCTIONAL_RANGE set to 10, which means that if the temperature is more than 10 degrees away from the setpoint, the controller will be in bang-bang mode (either PID_MAX or 0).  If the temperature is changing quickly, the temperature may get out of the PID_FUNCTIONAL_RANGE before the PID controller settles.  By looking at my temperature messages during heating, I could see that the PID controller never settled.  In order to give the controller time to adapt, I increased the PID_FUNCTIONAL_RANGE from 10 to 30.  At that point, I could control the temperature of the extruder, although it was still not as tight a control as I would prefer.

I insulated the hot end block to decrease the cooling rate and slow the system down a little bit.  That helped somewhat.

Bottom line -- my printer is now functional.  But there is still more variability in the extrusion temperature than I would like.  I'll keep working on it.


Saturday, February 19, 2022

Using Octoprint with one Raspberry Pi and two printers

I have two Tronxy X3A printers.  I have Octoprint on one, but not on the other.  I love Octoprint so much that I can't stand not having it.  So I decided to connect both printers to my Pi.

Detailed instructions are given on the web here.

Without further ado, here's what I did.

Identify the port for my current printer

  1. ssh into my Raspberry pi, with the user name of pi (which was set up when I installed Octoprint).  
     ssh -lpi octopi.local  
  2. List the ports for the connected usb devices
     ls /dev/ttyUSB*  
  3. Plug in the second printer, then relist the ports for the connected usb devices. The new device is the one for the second printer.
     ls /dev/ttyUSB*  
  4. Get the device info for both devices, and find the differences (I have /dev/ttyUSB0 and /dev/ttyUSB1. You might have different devices.)
    udevadm info -a -n /dev/ttyUSB0 > devInfoUSB0
    udevadm info -a -n /dev/ttyUSB1 > devInfoUSB1
    diff -u devInfoUSB0 devInfoUSB1  
    My difference is this:
    ATTRS{bInterfaceProtocol}=="02"
    ATTRS{bInterfaceProtocol}=="ff"  
    Where my old printer is 02, and my new printer is ff
  5. Create a named symlink to the appropriate USB port that will last through a reboot by editing the /etc/udev/rules.d/99-usb.rules file
    cd /etc/udev/rules.d
    sudo vi 99-usb.rules  
    Enter the following two lines in the file (specific for my printers):
    SUBSYSTEM=="tty", ATTRS{bInterfaceProtocol}=="02", SYMLINK+="ttyCDSX3A"
    SUBSYSTEM=="tty", ATTRS{bInterfaceProtocol}=="ff", SYMLINK+="ttyCPSX3A"
    
    The symlinks are the names I choose to use for the printer ports.
  6. Open up Octoprint, go to the settings menu, and add the new ports to the additional ports box.

Create a second copy of Octoprint

  1. Copy the octoprint directory
    cp -R .octoprint .octoprint2 
  2. Copy the octoprint configuration file
    sudo cp /etc/default/octoprint /etc/default/octoprint2
  3. Edit the octoprint2 configuration file to change the port and add a basedir
    sudo vi /etc/default/octoprint2

Edit my haproxy.cfg flie

The