Welcome! Log In Create A New Profile

Advanced

Mechaduino Closed-loop Stepper

Posted by LoboCNC 
Re: Mechaduino Closed-loop Stepper
December 04, 2016 09:58AM
Quote

My main goal for the homing is for bed leveling, this way the nozzle would be used to measure the bed height and you would have perfect bed leveling.

For a Cartesian printer this setting would work, because the current/torque required to move should be constant.
But what about a delta? I can imagine, the current would be different depending on the probing position.
Re: Mechaduino Closed-loop Stepper
December 04, 2016 12:26PM
That is correct, using the motor for Z homing would be hard with a delta.

Trampas
Re: Mechaduino Closed-loop Stepper
December 04, 2016 12:29PM
Quote
trampas
The code does implement phase advancement which in simple terms, allows dynamic step size on the stepper motor. That is the driver code for the A4954 implements 256x microstepping, while I have normally been running the external interface at 16x microstepping. So what happens is when a user requests a step internally the firmware calculates what the desired angle is, then it measures the current angle using an encoder and compares to the desired angle. It will then move the motor the difference to achieve the desired position. What this means is that if the error is large (fast movement) it will take larger steps, if error is small it will take smaller steps.

I sounds like you are implementing your closed-loop control very differently from the Mechaduino. Closed-loop steppers that I am familiar with first turn the stepper motor into a brushless servo motor by commutating the motor using the encoder signals. (With the A4954, this would involve modulating the ratio of Vref1/Vref2 to achive sinusoidal commutation - very similar to microstepping.) This enables you to operate the motor like a free-spinning DC motor. You control the overall motor current by changing the magnitude of the vector sum of the two VRef singals. To achieve position control of the motor, you then use a PID control filter to read the encoder, compare it to the command position, and modulate the current so that the motor always driven to the command position.

It sounds like you are doing something different where you are just commanding more forward steps if the motor lags in position. Are you just changing the Vref1/Vref2 ratios (ie, microstepping) or are you also changing overall Vref magnitude? Is there a PID filter involved? From your videos it looks like you are doing PID control, but it's hard to tell.
Re: Mechaduino Closed-loop Stepper
December 04, 2016 12:39PM
Quote
trampas
That is correct, using the motor for Z homing would be hard with a delta.

Trampas

If you have stall detection then you can home all 3 towers of a delta without endstop switches.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: Mechaduino Closed-loop Stepper
December 04, 2016 03:49PM
LoboCNC,

I am changing the current on the Vref1 and Vref2 pins such that I have 256x microstepping at the A4954 driver level. Thus I can can adjust the motor for very small errors, less than 0.01 degrees, the A4954 driver also lets me change the current (torque) (ie magnatude) going to motor. So I can move with a lot of current one microstep or a small amount of current one microstep. From a hardware perspective this means I need more than 8 bits on the Vref ADCs (bug in early versions of Mechaduino firmware). Since I can control the step size and current to the motor it allows me to implement multiple control loops.

The default control loop out of the box is a very simple control loop where I command forward/reverse steps to minimize the error, when the error is low the controller switches to the "hold current" to lower power, heat and noise. This control algorithm is not the "optimal" for any given machine but works with most machines out of the box without tuning. That is it is simple and will work for most applications. It is a PID controller and you can change the parameters, but the control variable is the step size. Inititally the P term is 1.0 and the I and D terms are really small. So this can be thought of as simple control loop where if we have error we move until the error is near zero, hence the "simple" control loop. The I is small to adjust for long term errors, the D term just helps a bit with the stablity. However the default values should be good enough for most system, but depending on the load it might have to change.

I also have a positional PID control loop where you can tweak the PID terms and tune your machine. This basically the same as the mechaduino's positional control loop. This loop controls the current to the motor, rather than step size such that motor behaves more like a DC servo. This can have the lowest power and heat when tuned correctly. However the tuning is highly dependent on your machine.

In addition I have implemented a velocity PID mode just in case you need that, again like mechaduino.

Finally I there is an "open loop" mode where the system just behaves like a step stick. That is you send a step command it will step one step.

Again tuning the PID control loops can be difficult so I chose to default the firmware to the simple mode, which hopefully will work good enough for most people.

I would like to implement an adaptive filter to dynamically tune the control loop, or at least a way to hit a tune button and maybe do relay tuning or something. So far I have not gotten this working in the firmware yet. If anyone knows how to do this please let me know.

Please note the A4954 driver has 256x microstepping, for the interface to the host controller (Marlin/smoothie) the microstep size is user setable with default at 16x.

Of course the firmware is all open source so you can change as you like.

Trampas


Stay in control of your stepper motors - [misfittech.net]
Re: Mechaduino Closed-loop Stepper
December 04, 2016 05:27PM
Quote
trampas
LoboCNC,

I am changing the current on the Vref1 and Vref2 pins such that I have 256x microstepping at the A4954 driver level. Thus I can can adjust the motor for very small errors, less than 0.01 degrees, the A4954 driver also lets me change the current (torque) (ie magnatude) going to motor. So I can move with a lot of current one microstep or a small amount of current one microstep. From a hardware perspective this means I need more than 8 bits on the Vref ADCs (bug in early versions of Mechaduino firmware). Since I can control the step size and current to the motor it allows me to implement multiple control loops.

The default control loop out of the box is a very simple control loop where I command forward/reverse steps to minimize the error, when the error is low the controller switches to the "hold current" to lower power, heat and noise. This control algorithm is not the "optimal" for any given machine but works with most machines out of the box without tuning. That is it is simple and will work for most applications. It is a PID controller and you can change the parameters, but the control variable is the step size. Inititally the P term is 1.0 and the I and D terms are really small. So this can be thought of as simple control loop where if we have error we move until the error is near zero, hence the "simple" control loop. The I is small to adjust for long term errors, the D term just helps a bit with the stablity. However the default values should be good enough for most system, but depending on the load it might have to change.

I also have a positional PID control loop where you can tweak the PID terms and tune your machine. This basically the same as the mechaduino's positional control loop. This loop controls the current to the motor, rather than step size such that motor behaves more like a DC servo. This can have the lowest power and heat when tuned correctly. However the tuning is highly dependent on your machine.
Trampas

Interesting. It sounds like you have implemented a hybrid closed-loop control somewhere between a standard commutation + PID system (Quicksilver, Leadshine) and something like the Oriental Motors Alpha-step control.

To get back to my original question, with a commutation based controller, phase advance is fairly east to implement - you just advance some number of microsteps over what you would normally do base on the velocity of the motor. The logic being that at higher speeds, you need to turn on each winding phase a little sooner to give the coil currents time to build up to the required levels. Note that this is a little different that your algorithm of advancing microsteps based on the position error, which may have nothing to do wiht the velocity.
Re: Mechaduino Closed-loop Stepper
December 04, 2016 05:46PM
Is this a similar solution? [www.kickstarter.com]
Re: Mechaduino Closed-loop Stepper
December 04, 2016 05:56PM
Quote
MechaBits
Is this a similar solution? [www.kickstarter.com]

Yes, this project looks more like the standard commutation + PID control. And then there's this ,a discussion of my earlier effort at a closed-loop stepper controller.
Re: Mechaduino Closed-loop Stepper
December 04, 2016 06:43PM
I was confused over what you were calling phase advance, I think I understand now. I do not do this currently as my goal was not maximum motor speed, but rather positional accuracy.

Is there a need for such speeds? I had figured most people would be happy with full stepping speed, and microstepping accuracy.
Re: Mechaduino Closed-loop Stepper
December 04, 2016 08:05PM
Quote
trampas
I was confused over what you were calling phase advance, I think I understand now. I do not do this currently as my goal was not maximum motor speed, but rather positional accuracy.

Is there a need for such speeds? I had figured most people would be happy with full stepping speed, and microstepping accuracy.

You don't get a lot of torque at the higher speeds, but it can be handy for high-speed traverses where you have no load (like with a CNC machine). On my closed-loop stepper systems, I limit the speed to 1500 RPM because at higher speeds, the regen effect of the motor can actually blow out the driver if you slam the motor to a stop. However, I have run closed-loop steppers at up to 3000 RPM by using phase advance.

The main thing, though is that you should be able to boost the torque somewhat even at lower speeds with the phase advance because you get better matching of the winding current to the rotor position.
Re: Mechaduino Closed-loop Stepper
December 05, 2016 06:33AM
I see the biggest benefit of closed loop steppers in the possibility to use smaller/lighter steppers for direct drive extruders with gears ( say you want to build a mini-E3d Titan with even smaller stepper )
Can you confirm this?
Re: Mechaduino Closed-loop Stepper
December 06, 2016 01:26PM
Quote
o_lampe
I see the biggest benefit of closed loop steppers in the possibility to use smaller/lighter steppers for direct drive extruders with gears ( say you want to build a mini-E3d Titan with even smaller stepper )
Can you confirm this?

As mentioned earlier in this thread, you might be able to use a slightly smaller stepper, but without gearing and running faster, you aren't going to get much more power out of the motor by going closed-loop. The bigger advantage is with closed-loop control, you can monitor the motor current and position error to detect excessive extrusion force, running out of filament, and even potentially stripped filament.
Re: Mechaduino Closed-loop Stepper
December 06, 2016 01:39PM
For a given motor and current the torque of the motor (ie power) is going to be the same. However often people run stepper motors well under their maximum operating current to keep the noise and heat down. If this is the case then the controller might give you more power. Specifically the controller can drive the motor at maximum current when moving, but then lower the current when not moving to reduce noise. Again if you are driving motors at maximum current already the controller will not increase the torque (power) of the stepper motor.
However as stated there are other benefits, but again these are not realized without some code changes to the host controller.
Re: Mechaduino Closed-loop Stepper
December 07, 2016 01:18AM
My above mentioned question was also related to geared steppers and the chance to eliminate backlash with an encoder on the output side.

Edited 1 time(s). Last edit at 12/07/2016 01:19AM by o_lampe.
Re: Mechaduino Closed-loop Stepper
December 07, 2016 01:46AM
Quote
o_lampe
My above mentioned question was also related to geared steppers and the chance to eliminate backlash with an encoder on the output side.

When using a geared stepper for your extruder, the backlash isn't really important because you can always add a fixed increment to the retraction distance to compensate for the backlash.
kr_
Re: Mechaduino Closed-loop Stepper
December 08, 2016 05:52PM
These steppers seem very promising to fix some problems I from time to time encounter when printing new parts for the first times (on a P3 Steel) :

1 - Missed steps when the nozzle hits a bump that sometimes appears when doing top infill (I don't want to lift the nozzle or slow down both the travel and the top infill speeds for the whole part so I currently edit the Gcode to reduce the feedrate for the problematic layers only...)
--> Proposed solution with these steppers : reduce the feedrate if the position error is close to generate a missed step (close to a half step?)

2 - Missed steps when fast solid infill moves hit a natural frequency (resonance) of the Y axis.
--> Same proposed solution

3 - Various problems with the rubbery Filaflex filaments (missed steps on my direct drive extruder or under / over extrusion)
--> Proposed solution, to try, more tricky : try to obtain a constant extrusion pressure by measuring the torque and adjust the extrusion and moves speed accordingly


Which of the Mechaduino or the Nano Zero would be easier to implement along with my MEGA/RAMPS with Marlin firmware ? (I'm not that experienced but I managed to add an EPROM memory on the I2C port to count my plastic usage and write it in a spool "database").
Re: Mechaduino Closed-loop Stepper
December 08, 2016 06:32PM
Well as the designer of the Nano Zero I am biased...

The Nano Zero Stepper has an additional level shifted pin for and Error signal. That is a pin that can interface with the 5V logic of the MEGA/RAMPS hardware. I added this extra pin such that if the stepper misses a step it can signal the host (Marlin firmware in your case).

However I will say that for your problem neither one is an off the shelf solution for all three items. That is firmware on the Nano Zero and on Marlin (RAMPS/MEGA) would have to be written to implement these features.

Trampas
Re: Mechaduino Closed-loop Stepper
December 08, 2016 07:05PM
Quote
kr_
1 - Missed steps when the nozzle hits a bump that sometimes appears when doing top infill (I don't want to lift the nozzle or slow down both the travel and the top infill speeds for the whole part so I currently edit the Gcode to reduce the feedrate for the problematic layers only...)

2 - Missed steps when fast solid infill moves hit a natural frequency (resonance) of the Y axis.

Both of these problems would be aided by closed-loop stepper control without any mods needed to your firmware:

1. If the nozzle hits a bump (some errant bit of filament) the X or Y motor will be pushed out of position. With open-loop control if it gets pushed out by more than 1 full-step, then you'll never recover and forever have shifted print layers. With closed-loop control, though you'll end up with a minor defect in your print, but the motor will eventually recover to the proper position and the rest of your print should be OK.

2. Open-loop steppers are highly susceptible to resonances, as the magnetic detents that form the stable step positions act like mass-spring systems which have a specific resonant frequency. If you get to oscillating and the magnitude of the oscillation grows to more than one full step, again, you will never recover. Closed-loop control, however, is constantly modulating the current so you don't get the same sorts of fixed-frequency resonances that can grow pretty large. Also, if you do happen to hit some resonance that produces large errors, the motor will eventually recover its position after you stop exciting the resonance.

As an example, I did some comparative closed-loop vs. open-loop speed tests of motor and belt driving a mass using the exact same motor. With a smooth path (accelerate, slew, decelerate),I could run open-loop at exactly the same speed as the closed-loop. However, if I put a little vibratory jog in the middle of the motion (a series of accel/decel segments), the open-loop mode could only run half as fast as it could run the smooth path, whereas the closed-loop control was unaffected by the added jog.
Re: Mechaduino Closed-loop Stepper
December 09, 2016 12:53PM
Quote
LoboCNC
1. If the nozzle hits a bump (some errant bit of filament) the X or Y motor will be pushed out of position. With open-loop control if it gets pushed out by more than 1 full-step, then you'll never recover and forever have shifted print layers.

Actually it needs to slip by 4 full steps, although something that blocks motion for just 2 full steps or more will cause that to happen. But correct otherwise.



Large delta printer [miscsolutions.wordpress.com], E3D tool changer, Robotdigg SCARA printer, Crane Quad and Ormerod

Disclosure: I design Duet electronics and work on RepRapFirmware, [duet3d.com].
Re: Mechaduino Closed-loop Stepper
December 09, 2016 12:58PM
It depends on the feedback controller on the Nano Zero Controller it will correct even if 1/16 of step off, however it will not assert the error line unless error is more than 1.8 degrees (1 step for a motor with 200 steps per resolution).

The NZS check the error 6,000 times a second and will attempt to fix the smallest of error. This means that with the NZS your positional accuracy can improve.
Re: Mechaduino Closed-loop Stepper
December 09, 2016 01:55PM
Quote
dc42
Quote
LoboCNC
1. If the nozzle hits a bump (some errant bit of filament) the X or Y motor will be pushed out of position. With open-loop control if it gets pushed out by more than 1 full-step, then you'll never recover and forever have shifted print layers.

Actually it needs to slip by 4 full steps, although something that blocks motion for just 2 full steps or more will cause that to happen. But correct otherwise.

I stand corrected - with microstepping (or if you are at a standstill), being pushed out of position by 2 full steps is the threshold of no return. I was thinking about full-stepping, where if you are out of position by 1 full step, with the next step winding energization it will become ambiguous as to which way the motor will turn.

Edited 3 time(s). Last edit at 12/09/2016 02:10PM by LoboCNC.
Re: Mechaduino Closed-loop Stepper
December 09, 2016 02:19PM
This is not true on the NZS. The firmware constantly reads the encoder so it knows where the shaft is such that it can calculate the correct phase of the current to move. For example see this video

[www.youtube.com]

So even if the motor is way of say 1000 degrees (yes more than full rotation) the unit will recover.

You will also notice in the video the LCD shows you the error...

Edited 1 time(s). Last edit at 12/09/2016 02:20PM by trampas.
kr_
Re: Mechaduino Closed-loop Stepper
December 09, 2016 05:05PM
Thanks for your explanations and feedbacks.

Quote
LoboCNC
1. If the nozzle hits a bump (some errant bit of filament) the X or Y motor will be pushed out of position. With open-loop control if it gets pushed out by more than 1 full-step, then you'll never recover and forever have shifted print layers. With closed-loop control, though you'll end up with a minor defect in your print, but the motor will eventually recover to the proper position and the rest of your print should be OK.

This would help a lot. I also noticed that printing at high speed on a bumpy surface makes it worse layers after layers. Slowing down is smoothing out the bumps. That's why I'd also like to implement a way to slow down when bumps are detected.
I could maybe use the angular error value to calculate some descriptors with the stepper, telling shocks are happening (kurtosis and peak-peak...). Then send the values to my Mega board through I2C (SDA and SCL pins) from time to time and adjust the feedrate accordingly.

Quote
LoboCNC
2. Open-loop steppers are highly susceptible to resonances, as the magnetic detents that form the stable step positions act like mass-spring systems which have a specific resonant frequency. If you get to oscillating and the magnitude of the oscillation grows to more than one full step, again, you will never recover. Closed-loop control, however, is constantly modulating the current so you don't get the same sorts of fixed-frequency resonances that can grow pretty large. Also, if you do happen to hit some resonance that produces large errors, the motor will eventually recover its position after you stop exciting the resonance.

It's even better than I thought if it doesn't let some of the resonances happen !
Sorry, only registered users may post in this forum.

Click here to login