Arduino Based Closed loop Stepper

Hello
pardon me for my poor English

I have two questions/requests and I really appreciate If someone can help me to solve this.

I need to build a closed loop stepper motor based on arduino. and here is my scenario:

1- ramps board generate step and direction signal
2- these signal transfer to proper Arduino board by wires.
3- Arduino process the signals for sometimes like 10ms(for example).
4- after that 10ms delay arduino send every Step and direction signal to stepper driver with as same speed as the original signal was but with 10ms delay which is a permanent delay between these two Input and output. ofcourse this delay time will defined by us in arduino code.
5- after that the encoder send feedback to arduino.
6- if any step were lost arduino inject extra step to compensate the lost steps.
7- if the delays between Ramps and arduino output getting more than 30ms(for example) as a result of lost steps, arduino increase the original speed 10 percent to reach itself to that 10ms delay.
*** the arduino steps and direction signals should always 10ms behind the original signal provided by ramps board.

some of project details is:
A- my 2mm pitch leadscrew need 1200 steps for one complete rotation.
B- my maximum speed will not be more that 20mm per second.
C- so I think arduino due with 84mhz or arduino due with 16mhz Working Frequency can easily handle 36khz of processing and it should be possible to do that. I'm not sure ofcourse.
*** 12khz for input. 12khz for output and 12khz for encoder.

pardon me I dont know if I am able to clearly explain my Idea or not so I provide a simple example which I think qualify my Idea:
think about two friends want to go through the wood. their name is Ramps and uno!
-the Ramps knows the way and take the lead.
-so Uno wait for him to go further about 10 second and carefully look at his steps and direction and speed per step.
-after that 10 second uno start her steps exactly based on Ramps steps.
-so for example if Ramps increase his speed during 3rd to 6th steps she do so. if he jumps (accelerate) in 8th steps she will do it too.
-if Ramps turn at his 27th steps, Uno will turn 10 second later when she reach on her 27th steps too.exactly the same.

-Uno try to keep that 10 second distance to carfuly observe Ramps steps and direction and speed and having enough room to prepare for her next step and make decision if something happened.
***now for some reason she cant make some steps and their distance increase to 16 second.
so she have to take her next steps faster than what it should be to reach that 10 second distance and after that back to normal speed based on every steps' speed of Ramps.
and then when Ramps reachs to his destination, Uno will be there after 10 second.

so my first question is does it possible? and my request is: can somebody please write this code for me? I dont know anythings about coding.

I appreciate you to read this long post.
Thank you in advance,
Regards.

I have to ask: What, exactly, do you hope to gain with that system? It seems grossly over-complicated, but I fail to see what problem it solves. If you are hoping to avoid "lost steps", I can assure you that "lost steps" are caused ENTIRELY by poor system design, component selection, or improper operation. A properly design stepper system, properly operated within its capabilities, will NEVER lose steps.

So, again, what problem are you trying to solve?

How that?
Why that?

Why do you think that an additional step will be taken if the first one did not succeed? How do you want to reset the stepper driver into the state before the missing step before retry?

@RayLivingston is perfectly right. Your only chance is monitoring the proper number of steps taken by the motor. Any difference from the expected steps can not be corrected in software, requires a better solution in hardware.

Hello RayLivingston,

I thank you so much for taking Time and read my long post. I appreciate you.

Yes you are right. the lost steps are caused by poor system design and this is not my case. here is the problem:

  • I'm building an SLA 3d printer and for Z axis I use T8 Lead screw.

  • T8 lead screw has a backlash of about 0.0762mm(0.003"inch).

  • in other hand my layer height is 0.025mm(0.00098425197"inch= 25 µm) or 0.05mm(0.001968504"inch= 50 µm) which means leadscrew's backlash is two to three times bigger than my layer height.

  • between each layer of printing The Z axis which is driven with leadscrew goes up 10mm for example and then back for 9.95mm.

  • the problem is when leadscrew changes its direction produces 75 µm of backlash

  • in each layer leadscrew will move in two directions: up and down.

  • so it produces about 75-150µm of backlash

  • with that amount of backlash it is not possible for anybody to use T8 Leadscrews in SLA 3d printer. so everyone use Anti-backlash mechanism with T8 Leadscrews.

  • but it makes the final print quality looks poor

there are solutions for this problem which I've tested them already:
a- anti backlash nut for leadscrew or using spring between two leadscrew's nuts and then tighten them against each other. this solution do the job and make the leadscrews useful for SLA printer but the result is about 5-10µm deviation per each layer in average.
b- compensating the backlash with printer firmware like marlin is possible, but it truly mess things up. I cant use that as well as using anti backlash nut.
c- using ball screw is an absolute solution but zero backlash ball screws are fairly expensive.

What is my solution:
If I can add an encoder to my moving build plate I can completely eliminate backlash produced by T8 leadscrew. because when we encounter backlash in every direction change, the encoder think there are some lost steps and then inject the lost steps to compensate them.

Thank you for your replying again
Regards

Hello DrDiettrich,

I appreciate your time to read and reply my post.

pardon me for my poor English.

question:

Why do you think that an additional step will be taken if the first one did not succeed?

  • because in my case we wont face any real physical barrier and our lost steps are caused by Leadscrew's own characteristic (which is about 0.0762mm per change direction).
  • solution: if we compensate that amount of backlash by measuring lost steps and then inject extra steps to our output we can precisely move the build plate.
  • of course we can't only inject some additional and preprogrammed steps to compensate that 0.00762mm of backlash because it is not absolute and varies all along the leadscrew. for example somewhere in the middle of leadscrew backlash can be 0.005mm and somewhere it can be 0.07 or something else.
  • that is why firmware based compensating mess things up.

is perfectly right. Your only chance is monitoring the proper number of steps taken by the motor. Any difference from the expected steps can not be corrected in software, requires a better solution in hardware.

this is exactly what I want to do with some changes: by connecting encoder to Build plate movement mechanism I want to compare the proper number of steps taken by motor and the steps taken by Build Plate movement mechanism. Any difference from the expected steps should be corrected by injecting some extra steps to motor by Arduino to compensate the lost steps.

Thank you for taking time and read my post and replying
Regards

I have corrected the Picture from my first post which seems to have a Bad mistake in it: I didn't mention that the encoder should connect to build plate mechanism which is moving by leadscrew. the encoder system convert linear movement to rotating steps and send the feedback to Arduino. I should have mentioned that the steps per mm in both leadscrew and encoder will be the same. :

I appreciate your time taking to read my and replying
Regards

I cannot see any difference between both number of steps, provided that the motor drives the lead screw directly. Backlash may occur in a gearbox between both, or in the up/down movement of the print head or build plate, but this is not related to motor steps. Shouldn't you measure the actual height and correct the number of steps accordingly?

Sorry Because of my poor English I made mistake in my post which I corrected it now by editing it and added a picture to make my idea more qualified.

yes you are right but again I try to explain it better if I can.

For example:

  • assume If our stepper Motor rotate 30 Steps, the leadscrew is doing exactly 30 steps of course. and for example this 30 steps should move our build plate 3mm.
  • but because of leadscrews backlash, our build plate don't move 3mm, it moves 2mm instead.
  • since the steps per mm in both leadscrew and encoder is same in my system, so in this case these lost steps are 10 steps.
  • so our encoder send feedback to Arduino and ask for 10 extra Steps to reach that 3mm.
  • I think this is exactly what is I trying to tell. If I understanding your sentence well.

Thank you again for reading and please pardon me for my writing mistake.

In my understanding backlash results from changed rotation direction. So you have to output 10 steps first, or until the home position is reached, and then continue in the same direction. The encoder won't tell you anything new in contrast to the applied steps.

In the video the encoder seems to be used to recover the set position after an accidental (manual) move of the print head. Such moves are hard to detect from a stepper motor, so that an encoder is the right choice for such disturbance. But I can not imagine how one might move something tied to a leadscrew.

just consider leadscrew's backlash same as that manual disturbance on the video but in an extremley smaller Scale.

it seems working first but won't. because backlash in leadscrews is not fix and varies all along the leadscrew. in the first part of leadscrew it may be 10 steps but in the middle it may be 5 steps. that is why marlin firmware's compensating feature won't work good. it measure backlash from specific part of leadscrew and apply that for all leadscrew's length in order to compensate lost steps due to leadscrew backlash.

  • imagine we send 30 steps to our stepper motor and expect for 3mm of movement in build plate.
  • my encoder mechanism is precisely converting linear motion of build plate into rotary steps and counts the taken steps and for example send 27 steps to Arduino.
  • then Arduino compare these data and find that 3 steps were lost. so it send 3 more steps to precisely compensate the backlash.

let's talk precisely about the steps of my system.

  • my leadscrew need 1200 steps for every 2mm of linear motion. which means 30 steps for every 50micron

  • my encoder mechanism convert every 2mm of linear motion to 1200 steps.

  • in each layer Ramps board will send 18000 steps to move build plate 30mm up and then send 17970 steps to move build plate 29.95mm down(my layer height of printing is 50micron now).

  • but due to leadscrew's backlash(70micron) encoder will count the upward steps 17955 and not 18000.

  • we suppose Arduino compare these two numbers and find the error of 45 lost steps.

  • and then Arduino should send 45 more Upward steps to compensate this lost steps.

  • and then for downward movement encoder counted 17940 steps instead of 17970.

  • we suppose Arduino to compare these number and find the error of 30 lost steps

  • and then Arduino should send 30 more downward steps to compensate this lost steps.

unfortunately as you can see these lost steps are not the same every time in result of manufacturing error and tolerance. so we should count/measure lost steps due to backlash in every movement to achieve an absolute precise motion.

I thank you and appreciate your attention and time to read my post and helping me.
Regards

Please view the first 1:30 minutes of this video:

he is precisely explaining the problem and the solution I am dealing with.

but there is another problem in my case which prevents me to use this solution:

  • this solution only works with CNC and Linuxcnc Software as the brain of the machine. linuxcnc does this job extremely well and precisely.
  • unfortunately my case is LCD based SLA printer which is not supported by linuxcnc .
  • so I'm looking for a solution by this project.

Thank you for taking time to help me
I appreciate you

on another forum someone said they used stepper motors to control cockpit avionics gauges with encoders to insure that the stepper moved to the commanded position

whenever the encoder does not report to correct position, why not just immediately step the motor again?

or use a control loop that inputs a specified target and using the encoder for feedback, steps the motor until the target is reached

i agree, over complicated

Hello gcjr,
I Thank you so much for taking time and reading my post. I appreciate you.

I think it is because I cant tell it in a simple way.

I thought it is hard if we just immediately correct the steps. if it is easier, why not?
The only thing I want is a precise motion.

  • Ramps send step and direction signal to Arduino board.
  • Arduino sends it to stepper motor
  • and then arduino compares the "actual position provided by encoder" with "command position" and correct it.
    is it possible?

This is my Plan B if this project cant be done. I mean if I cant have a board that can take steps and directions directly from Ramps board and then use encoder for feedback to correct the actual position based on command position, I should go to Plan B and use preprogrammed board to do the job as you said. but in this way I will lose some functions of using ramps board like moving z axis manually.

could you please share the link?

I thank you so much for your reply
Regards

yes, this is a very common approach.

that there is some mechanism for making measuring a position or speed, comparing to some "target" to determine some +/- error and making corrections to bring the error to zero.

simply changing the "target" causes the feedback mechanism to change position/speed.

PID is an example of this

Yeah, what you want is a PID controller. You tell it where to go, and it goes there.

But I still think you're chasing a ghost. I've spent decades bulding, working on, and using CNC machines, incuding mills, lathes, and 3D printers, both extruders and SLA.
I have yet to see a backlash compensation scheme that does not have "artifacts". With an application that requires as much precision as an SLA printer, I think you'll sink a huge amount of time and effort into this solution which will offer only slight improvement. When it comes to backlash, the only good solution is to eliminate it mechanically. That means using good quality ballscrews.

Given that very nice SLA printers sell at retail for only a few hundred $, and come with decent quality ballscrews, I think you are grossly over-estimating the cost. I cannot imagine that you could not find a suitable ballscrew for WELL under $100. There are very good qualilty Chinese ballscrews out there now for ridiculously low prices.

Thank you so much gcjr. I appreciate you.

Hello RayLivingston
Thank you for your reply. I appreciate you.

yes you are completely right. there is only one thing that prevent me to use good quality backlash free ball screws. and what is that? The Islamic Republic Of Iran! the Mullahs regime in Iran make every thing very hard and expensive to access. so there is no affordable way to buy from Alibaba or amazon for me. of course there are some good quality stuff Imported inside Iran by themselves but they sell it up to 5 time more expensive. you cant imagine or believe how hard is it to live Under control of Mullahs regime.

for example Anycubic Photon Mono X 6K cost $409.00 for every one in the world but we should pay about 1000 to 2000$ for it! and believe me I can't find any backlash free ballscrew for sell here inside Iran which don't cost me a whole printer!

so If there is any chance for me to compensate backlash with arduino board and simple rotary encoder it seems more affordable solution in my case. am I right?

so is there any way you or someone can make this code for me?

I appreciate you
Thank you in advance
Regards

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.