Saturday, November 14, 2020

Here's What Happened When I Swapped Servomotors For Steppers In My 3D Printer

A little while ago, I replaced the steppers in The Spice Must Flow sand table with iHSV42-40-07-24 servomotors. The results were so impressive, I just had to try them in my coreXY 3D printer, UMMD.

Even though both use coreXY mechanisms, the sand table and 3D printer are two different animals. The sand table needs high speed and quiet operation over positioning precision and accuracy because sand is a very low resolution medium. The 3D printer doesn't need to be so fast, but does need to position precisely or print quality will suffer. 

It turned out that servos worked much better than steppers in the sand table. It was time to see if they would deliver similar or any performance improvements in a 3D printer.

Why would the servos have any advantage over steppers in a 3D printer? 

They run smoother and quieter since the motors don't have the detents that a stepper has. The particular servos I used are 78W motors, so can deliver much higher acceleration and jerk than the steppers can - much more than is necessary. The thing I mostly wanted to see was if they could deliver the kind of precision and accuracy that the steppers did, and that would show up in the print quality.

UMMD BS (Before Servos)

UMMD used two 64 oz-in, 400 step/rev, NEMA-17 motors to drive the XY mechanism. I ran them with 256:1 interpolated microstepping to keep them quiet. I typically ran the printer at acceleration of 2000 mm/sec^2, jerk speed of 30 mm/sec, and print speeds of around 80 mm/sec. Print quality was generally excellent, though some recent experimenting with non linear extrusion and pressure advance has it over extruding on top solid infill a bit- the tweaking never ends- sigh...

Installing Servos

The servomotors are also NEMA-17 size and have integrated encoders and drivers and accept step/direction/enable signals just like stepper drivers, so installing them in the printer was a pretty easy process, much easier than replacing steppers in the sand table.  All I had to do was remove the steppers and bolt in the servos, add the Duet expansion board to the controller, and connect the power supply and step/direction/enable lines, then tweak the config file for the Duet controller board.

I also added another 24V power supply to power one of the servomotors because I discovered in the sand table that the motors can draw a lot of current when accelerating and I didn't want the power supplies to limit the performance of the servomotors.

Setting the Motor Steps/Rev

The drive pulleys are 20 tooth*2 mm pitch, so move the mechanism 40 mm/rev. I want to be able to drive the mechanism up to 200 mm/sec with the servos, so 5 revs/sec = 300 rpm. The Duet can deliver 120,000 steps/sec. 120,000 step/sec / 5 rev/sec = 24,000 steps/rev. So jumpering the motors for anything less than 24000 steps/rev will allow the print speed over 200 mm/sec. 

I jumpered the motors for 20,000 steps/rev. which should give a top speed of 120,000 step/sec / 20,000 step/rev = 6 revs/sec. 6 revs/sec * 40 mm/rev = 240 mm/sec. 

Configuring the Duet Controller

20,000 steps/rev / 40 mm/rev = 500 steps/mm, which is more than an order of magnitude beyond the resolution needed in a 3D printer.

I set the Duet to drive X and Y with full steps, set steps/mm to 500, and left acceleration and speed settings as they were with the steppers. I also set the timing parameters to drive the servos as I did in the sand table.

M584 X5 Y6  ; remaps the X and Y motor drives to the Duet expansion board
M569 P5 S1 R1 T4.0:5.0:6.0:11.0 ; sets the timing parameters for the X motor servo drive signals
M569 P6 S1 R1 T4.0:5.0:6.0:11.0 ; sets the timing parameters for the Y motor servo drive signals
M92: X500 Y500 ; sets steps/mm for motors using 20 tooth drive pulley and 20,000 steps/rev
M350 X1 Y1 ; sets Duet to output full steps (microstepping is handled by the servomotor drivers)
M201 X10000 Y10000 ; set maximum acceleration limits for each axis
M204 P2000 T2000 ; set print and travel move acceleration
M566 X20 Y20 ; set maximum jerk speed for each axis
M203 X240 Y240 ; set maximum speeds for each axis

Configuring the Servomotor Drivers

Maximizing positional accuracy using the servomotors requires tuning the driver parameters for that purpose. I dug into some information on tuning servo motors and poured over the manual for the motors to glean what I could about the available parameters and their effects on positional accuracy.  

The first step in the process was to get my computer to talk to the motors. The motors need RS-232, not serial TTL, so look for a USB to RS-232 adapter based on a PL2303 chipset. It will provide real RS-232 voltage swings between +3.3V and -3.3V.  I ordered one of these.  This adapter has a male DB9 connector which is fine for some uses, but the motors have spring terminal connections, so I cut up an old serial cable that had a DB9 female connector at one end. I cut the male connector off the other end and stripped the Tx, Rx, and Gnd wires and connected them to the motor.

USB to RS-232 converter using PL2303 chip. I connected an old serial cable to the DB9 connector and used only the Tx, Rx, and ground wires to connect to the motors.

The manual says the default modbus speed of the motors is 9600 bps, but the RS-232 speed default is 57,600 bps, even parity, 1 stop bit. I'm not entirely sure what a modbus is in the context of these motors, but it doesn't matter- RS-232 is what you use to configure the drivers.

RS232 port settings in motor driver
I was able to read all the factory setting for the parameters which I immediately saved to a file in case I did something wrong later and needed to get back to the defaults.

The next page of the manual has the settings for autotuning the motor:

Autotune parameters

I ultimately used the built-in autotune function to tune the parameters automatically, while the motors were driving the printer mechanism. 

First Test Results

I knew before testing that the servos can run at much higher acceleration and jerk than the steppers, but I also knew that high acceleration and jerk lead to noisy operation as the mechanism will make a banging noise (and shake the printer) each time the movement direction changes. My first comparative tests kept the acceleration, jerk, and speed at the nominal stepper settings so I could compare noise levels and print quality.

Before I installed the servomotors, I ran a test print using the nominal settings I normally use in the printer. Specifically, acceleration 3k, jerk 20, and print speed 50 mm/sec.
After the servos were installed and the Duet was configured, I ran the same test print STL file at the same acceleration, jerk, and speed settings I had used for the test print with the steppers. Here are some photos and video of the two prints. I haven't done anything to alter the volume in the videos- what you hear is what I got.

First layer of print with servomotor.  It does not look promising!

first print with the servomotors
First attempt to print with the servomotors. Poor quality with 'salmon skin" effect at all 45 degree corners of the print.

test print with the stepper motors
Test print made with the stepper motors. Some ringing due to the relatively high acceleration (3k), but otherwise good quality.

Servo print.

Stepper print.

Servo print.

Stepper print.