Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: homebuilt on January 26, 2019, 06:35:59 AM

Title: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 06:35:59 AM
Hi all brand new to mach 4 and ive almost finished my first build but alas i'm well an truly stuck and have been pulling hair for a week.

I cant seam to wrap my head around motor tuning to suit my motors, i just dont understand and would love if someone would be able to help me through it

My set up is Mach 4 with a ess and MB2 breakout board, I'm running Nema 34 hybrid motors like the ledshine branded ones in 8.5nm and 12nm with SFU1605 leadscrews
I have everything moving and working well but im just stuck on the tuning.

If there is anyone that is able to help i would really appreciate it.

Let me know if you need anymore information and ill try and add some pictures of my rig

Regards
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: Cbyrdtopper on January 26, 2019, 11:32:40 AM
Homebuilt,
How what are you having trouble with?  The Steps Per Unit or the Velocity and Accel?
 
For Steps Per Unit, I found a couple of resources that are worth looking at. 
The first is Artsoft's YouTube Channel:  Steps Per Unit Calculator Wizard.
https://www.youtube.com/watch?v=d-xCWDR0Uvg
The next resource I found gives you a formula for finding the correct SPU.  (You can stop reading once you get to the formula)
https://planet-cnc.com/how-to-setup-cnc/

For Velocity and Accel; I'm sure someone else will have a better explanation than what I do, but this is how we do it....  I like the old trial and error approach.  First, calibrate your axis, otherwise this will be pointless because it will change with calibration.  Once I know that all my axis are calibrated correctly, I decide what the Max Rapid Rate for my machine should be or where I want it; this will depend on how strong your motors are for your table, I retrofit lathes and VMCs mostly so I use good size servos so I can get good speed out of my machine.  Your Velocity is the max units per minute the machine can move; for example, the mill I'm working on is currently set to 450 units (inches) per minute.  If you are unsure how fast to set the velocity, start high and keep adjusting your velocity down until the motors don't stall while jogging, then go 3/4 of that speed and you should be good to go.

As for the acceleration, I usually go with 10% of my velocity and 95% of the time it works great.  With servos and hybrid steppers it could be a little less because they have the feedback from the encoder; but again, this is trial and error, if you machine table is a heavy, has small motors, or is a gantry type machine, it will likely have to have a higher acceleration to not stall your motors.

Like I said, someone may have a more scientific or mathematical approach than what I do; but this has always worked for us.  Maybe someone else will share their experience, I'd love to hear it as well.
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 01:09:08 PM
Hi,
Chad has outlined the process spot on.

Quote
I'm running Nema 34 hybrid motors like the ledshine branded ones in 8.5nm and 12nm with SFU1605 leadscrews

Those are extremely powerful steppers. Often large steppers that have a great deal of torque do not have very high top
speeds before they start missing steps. You might be advised to treat the maximum speed as when the motors are doing 500 rpm.


If the steppers are direct coupled to the ballscrews then 500 rpm results in a linear speed of 2500 mm/min.

With steppers such as yours with high torque you can probably accommodate high or even very high acceleration. Chad has suggested
10% of your velocity, a good place to start, but I suspect, especially if you don't try to make them spin too fast, ie keep
the max velocity low then your acceleration could be much MUCH higher.

Often cycle times are improved as much if not more by high acceleration than axis speed. Certainly the higher the acceleration
your machine is capable of the more accurate parts will be when running in CV mode. The long and short of it is you need
to find the maximum safe and reliable acceleration your machine and motors can handle. Its more important than maximum
axis speed.

Can you tell us about the drivers and the settings you can make with them? Perhaps post the manual. If they are genuine closed
loop hybrid then there are a number of settings that will affect resolution and therefore your 'steps per unit'. Until you have the
'steps per unit' absolutely nailed down then any other motor tuning is a waste of time.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 04:07:09 PM
Thanks for your help guys, i suppose ill start from the begining

On the stepper motor controller units i have it set at 2000 pulses per rev but im not really sure if that works as everything is moving at a snails pace now
and with 2000 pulses what does that equate to in my current steps per revolution just to give me a start point
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 04:20:02 PM
Also wanted to add in the wizard i have my settings as

1000 counts per unit
100 units velocity
10 acceleration units

no idea if these numbers are right but when i move 10 units it moves 63mm and when i try to input that new length the number gets amazing small and my machine is crawling along like a snail
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 04:37:23 PM
Hi,
who knows.....you have given us no information.

First...tell us about the stepper drivers or better yet post the manual
Are the steppers direct coupled to the ballscrews or through some sort of gear/belt reduction?
You said you are using 1605 ballscrews....can you confirm and in particular that they are 5mm pitch?

I will make some assumptions based on what you have said, I know 'assumption is the mother of all 'f......ups'
but here goes.

If your ballscrew is direct coupled and it is 5mm pitch AND you have set the drivers to 2000 steps per revolution THEN

Steps per Unit (mm)=2000 /5
                              =400

I would suggest you start with the velocity setting of 2500 (mm/min) and an acceleration of 250 mm/sec/sec.

When you say that the axis is traveling very slowly, how are you instructing it to move?
I would be prepared to guess that you are jogging it and the jog rate is set vey low.

Do yourself a favour and learn a little Gcode and use MDI instructions instead.

If for instance you code:
g0 x100 <MDI Cycle Start> the X axis should move at its fastest possible (2500 mm/min if you have followed my recommendation)
speed to X=100 mm.

If you code:
g1 x100 f500 <MDI Cycle Start> then the X axis should move to X=100 at 500 mm/min.

Thus by using MDI commands you have explicitly told Mach how fast to drive the axes....you are not reliant on jog speeds.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 04:46:48 PM
Hi craig chucked in those assumptions and she is definalty moving a bit better.

I post a link to the driver spec sheet
http://oceancontrols.com.au/files/datasheet/lea/SMC-180_ES-Dhm_V1.1.pdf

I'm running the larger one and they are direct link coupled, i turned up a aluminium couple on my lathe and i can confirm they are 100% 5mm pitch ballscrews.

Ill watch some more youtube videos on g code but yeah i was just jogging to unit.

Hope that helps a little

Regards Dale
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 04:47:07 PM
Hi,

Quote
1000 counts per unit

You cant arbitrarily set the 'Steps per Unit' to whatever value you like.

If you have a manual car and are cruising in top gear if the engine is doing 3000 rmp and you are going 100km/hr
unless you change the gearing, or the diff or the size of the wheels you can't suddenly decide 'I want to go 120km/hr
at 3000 rpm'. The ratio is fixed by the mechanics of your car.

The analogy is that if you have set your stepper drivers to 2000 pulses per revolution and the pitch is 5mm per revolution
then the Steps per Unit IS 400.....no if...no buts. If you want to change it then change the number pulse per revolution
ie your stepper driver OR change the pitch of your ballscrews OR introduce some gearing between the motor and the
ballscrew.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 05:20:03 PM
Hi Dale,
are you Aussie? Is it warm enough yet!

Ok, the stepper driver has a setting which would make your desired 'Steps per Unit' 1000.
If you set your stepper driver to 5000 pulse rev revolution combined with directly driven 5mm pitch screws
results in 1000 Steps per Unit.

Its another way of saying that every pluse issued by Mach/BoB/Controller will advance the axis 1 um. That's pretty impressive.

You have not said what sort of controller you are using?.

If you wish to spin your motors at 500 rpm and your driver is set to 5000 pulses per rev then
Pulses per minute= 500 X 5000
                          =2,500,000
or Pulses per sec  =41666 or near as dammit 42kHz.

As you can see my question about your controller is not idle. Machs parallel port is natively 25kHz. It would not be
fast enough to signal your driver with that high resolution. You can increase the kernel speed in Mach3 parallel port,
if I recall there is a setting for 45kHz. The downside is that the faster you try to make a parallel port go the likelihood
of glitches /stalls and stutter goes up markedly.

For this reason I would not recommend such high resolution if you are attempting to use a parallel port, your original
setting of 2000 pulse per rev is better. That corresponds to a linear resolution of 2.5um per pulse, still very impressive.
Even 2.5um resolution is likely to be more accurate than your machine....or if your machine is that good/expensive
then what are you doing pissing around with Mach in the first place?

If you are using an Ethernet SmoothStepper say, by way of comparison, that has a max pulse frequency of 4Mhz.....
that is 160 TIMES faster than Machs parallel port (at 25kHz), thus you can set your resolution high, even higher than 5000
pulse per rev and still be within the capability of  the SmoothStepper.

Resolutions of finer than 1um (excepting wafer scale semiconductor manufacturing gear at millions of dollars each) is for those
people who like to jerk off and/or brag.....not what I would expect from an Aussie! ;D

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 05:28:27 PM
Hi,
my apologies, in your original post you specified that you have an ESS, so disregard the question about the controller.
The ESS will handle anything you care to throw at it at a canter.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 05:51:41 PM
Wow thanks craig, Yes i am aussie thanks for noticing  ;D lol

As i was building i wanted to get the best i could afford hoping i could build something semi impressive but reliable haha

Just wanted to double check in the motor tuning tab am i still sticking to 400 counts per unit? or am i still way off.
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 06:05:23 PM
Hi,
you've seen the calculation......2000 pulses per rev and 5mm per rev (pitch) means 2000/5 =400 pulse per mm.

Under the assumptions I have made that is correct. Put 400 in the 'Steps per Unit' setting.

Zero your X axis and MDI g0 x100. <MDI Cycle Start>. How far did it move, it should be 100mm....exactly.
If it has moved exactly 100 mm then leave that setting alone, you'll never touch it again in the life of the machine.
The max velocity and acceleration you can change at will but the steps per unit set the dimensional accuracy of the machine.
If you do a cutting move of g1 x100 f300 say and it only moves 95mm then your part is going to be undersize....rubbish.

As a start set the max velocity to 2500 (mm/min) and try acceleration of 250 (mm/sec2)

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 06:17:05 PM
Hi Craig thanks for helping me i really appreciate it.

I've put 400 with 2500 and 250 and punched on g0 x100 and its moved 63mm
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 06:44:07 PM
Hi Dale,
then something is wrong. It could be that the ESS is issuing 2000 pulses per rev for 20 revs to get your 100mm
travel but the stepper is missing steps. Its possible but unlikely, I would expect there to be unusual noises.

I think it more likely that the settings in the stepper driver are wrong.

I'm guessing that you have the dip switches back to front and you have accidentally set the steps per rev to 3200
not 2000 as you intended.

Now you issue an g1 x100 instruction so Mach/ESS dutifully sends 100 (mm) x 400 (pulse/mm) =40,000 pulses.

If I am correct your stepper driver took those 40,000 pulses and applied them to your motor but at 3200 per rev.
So your motor would turn 40,000 /3200 = 12.5 revolutions and at 5mm per rev =12.5 5 =62.5mm.
Does that sound correct to you?

Have a close look at the bottom of page 14. Compare with the settings required to make 2000 pulse/rev on page 15.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 06:46:42 PM
Hi,
sorry, in that last pic I highlighted the settings to make 5000 pulse/rev, please disregard my highlighting.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 07:11:07 PM
Hi Craig can confirm i did have the dip switches wrong (working in a small cabinet under the CNC)

So i pulled the stepper motor controllers out and changed them to 2000 and re run g0 x100 and its moves 25mm not 100?

 :o
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 07:33:49 PM
Hi,
I still think you have the switches wrong....its easily done.

There is one other remote possibility and that is the difference between PPR and counts per rev.

Encoders have a certain number of lines which is the same as PPR. In the case of your steppers they have 1000
line encoders. When the two encoder channels are combined, they are in quadrature to each other, you end up getting
four times the number of distinct counts per revolution, ie 4000 counts.

I would expect, and am led to believe, the dip switch settings are counts per rev, not lines per rev. I am suspicious that
the actual travel is exactly 1/4 of what was expected.

Please go and double and triple check the dip switches. If they are indeed set to 2000 pulse per rev as you believe
then set your 'Steps per Unit' to 1600 and try the same test. The ESS can handle the extra pulse speeds no trouble.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 07:50:24 PM
Hi Craig you mentioning quadrature rings a bell, in the ESS settings under motors i had changed the settings from step/dir to quad a few days ago and forgot about it.

I changed it back to step/dir and ran g0 x100 again and got 93mm am heading in the right direction and i pulled to controllers out again they are 100% in 2000

thanks again for your help
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 08:45:28 PM
Hi Dale,

Quote
ran g0 x100 again and got 93mm am heading in the right direction

Not quite sure that is the case. In the previous instances it was a setting that caused a predictable variation between
actual and what you wanted. 93mm vs 100mm we actually expected is much harder to understand.

You can correct it by adjusting the step per unit until it comes right. It is not correct however. The calculation is so
straight forward having to deviate from it means that a fault elsewhere is being overlooked.

One possibility is that the stepper is losing steps at speed. If you try MDI g1 x100 f250 what happens?. The axis will
move but more slowly. If the discrepancy is caused by trying to go too fast then this test should highlight it.

Another possibility is that you have a loose coupler, its surprising how many get caught with such a simple fault.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 26, 2019, 09:24:15 PM
well i had some lunch and had some time to think and tried it again and bingo its bang on 100mm in the X and Y axis and i have no idea as i didnt change anything so that has me stumped.....

also just a quick question when i press "ref all" all 3 axis barley move to the home switches any idea what i might have done
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 26, 2019, 10:16:22 PM
Hi,

Quote
also just a quick question when i press "ref all" all 3 axis barley move to the home switches any idea what i might have done

That has to do with homing also call referencing and it is adjustable. Don't bother with it until you have the motors
dialed in. If you cannot move a precise distance then you are going nowhere.

Try this MDI:
Code: [Select]
g0 x100
x0
x100
x0
x100
x0
x100
x0
x100
x0

Does it move backwards and forwards, 100 mm per move? Does it move flat stick?
If so now try the Y axis:

Code: [Select]
g0 y100
y0
y100
y0
y100
y0
y100
y0
y100
y0
y100
y0

If the Y axis is moving backwards and forwards OK then try some linear interpolated moves:

Code: [Select]
g0 x100y100
x0y0
x100y100
x0y0
x100y100
x0y0
x100y100
x0y0

If all these work OK then you can start thinking about tuning your motors. By tuning I do not mean fiddling with the
Steps per Unit. Those settings are now made and unless you change motor settings or ballscrews you shouldn't ever have
to touch them again.

I would concentrate on acceleration first. Acceleration (linear) is equivalent to torque (rotation) so to explore the
torque capacity of your motors at various speeds is where you want to go. You might achieve a high speed say, but have
to dial back on the acceleration in order to avoid losing steps. I think that is a mistake, increase acceleration as much
as you can and THEN increase max velocity until the onset of losing steps.

Try quadrupling your acceleration to 1000 mm/sec2. Run the same test as above. How did it go?
If it went well double the acceleration again, now up to 2000mm/sec2. It is now very likely your machine
is flopping around like a fish. Industrial production machines have accelerations of 1g-5g that is 10,000mm/sec2
up to 50,000mm/sec2. Hobby machines cant usually get within a bulls roar of that and they try to throw themselves
around the room if you try.

What you are trying to achieve is the highest acceleration your motors can deliver consistent with the machine not flexing
alarmingly AND your heart rate  stay below 200BPM! You might chose to back off from max by 10-20% and allow some headroom.

Now you want to start increasing the maximum velocity until it starts losing steps. Given that your steppers are closed loop
the drive will try (try being the operative word) to catch up on lost steps. Usually what happens if it starts losing steps the drive
faults 'following error'. You know then that you hit the limit. Back off 25% and run your tests again. What you are trying to
achieve is the maximum RELIABLE speed with the steppers having still plenty of torque to accommodate both  good acceleration
and cutting forces.

A thorough investigation of your motors and machine capabilities will probably take a couple of days. Try to be methodical about it.
Often, once you tune your machine, those settings will stay the same over the life of the machine. It really does pay to explore
the limits. So many machines around the globe are actually way more capable than the owner realizes and he will merrily be
using but a fraction of the machines capability because of his inexperience/impatience/disorganization at the time he set those
limits.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 27, 2019, 12:29:56 AM
HI Craig ive spent the past few hours running various lines of g code and by my measurements x and y are accurate every time, i cant thank you enough for the help i certainly would not have been able to work through it with out you.

On the other note of tuning i have my motors running both x and y lines of code at

7000 velocity
3500 acceleration

it moves well and ive realized the rubber feet im using to the cabinet  have a bit of flex in the so they will go but should i keep pushing? the machine flies around hahaha

also i have changed my homing to 40% but there is next to no movement still, any ideas?
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 27, 2019, 01:02:55 AM
Hi,
acceleration of 3500 is pretty impressive. When machining parts the accuracy of the corners is very much determined
by the acceleration the machine can attain. For this reason I recommend the max acceleration your motors and machine can handle.

I would push it to 5000, then 7500....until you find the limit. It may well be that your machine starts careening around the workshop
and that will constitute the effective max acceleration.

If it transpires, and from your description it sounds probable that the mechanics of the machine will limit the acceleration
but that will allow you to bump up the max velocity.

The very real fact is that steppers lose torque at high speeds, closed loop steppers are no exception. It is normal for instance that
the low speed torque, or holding torque, is reduced to half at 500 rpm and reduced to  a quarter at 1000 rpm. There again
being closed loop does not change those characteristics. My suggestion was to use 500 rpm as a starting point for your
max velocity. Now that you have really upped the acceleration and are probably approaching the effective max acceleration
now you can start turning up the speed.

I would try 10000 mm/min, that is equivalent to the steppers doing 2000 rpm. Particularly if you have to limit the acceleration
to prevent the machine from rocking around you may find 10000mm/min doable. That would be a very impressive result  for
steppers.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: joeaverage on January 27, 2019, 01:17:53 AM
Hi,
where about are you setting your Homing parameters? From your description:

Quote
also i have changed my homing to 40% but there is next to no movement still, any ideas?

You are using Configure/Control (Mach)/Homing-SoftLimits tab. That is not correct, at least for the approach and backoff
speeds. They are set in the ESS plugin. It is a bit confusing but some of the Mach settings are ignored in preference to
the ESS plugin. Speeds and index homing certainly. Softlimits, Home in Place and Home Order are all still set in the Mach
plugin, not the ESS plugin. You will have to experiment some to determine which settings are applied.

Note that the ESS has two speeds, the approach speed, which exactly as described is the speed at which it approaches the
home switch. It can afford to be reasonably fast, provided it doesn't hammer the switch with overrun. The back off speed
can be much slower and therefore more accurate. When the axis backs off the switch, that is the moment that the machine
coordinates are reset. Accordingly the accuracy is determined principally by the back off speed.

Craig
Title: Re: Motor Tuning in Mach 4, Very Stuck
Post by: homebuilt on January 28, 2019, 02:39:43 AM
Hi Craig so I've been busy yesterday checking and double checking measurements. And I can confidently say your settings were spot on I managed to get the thing up to 14000 before my heart rate went up and stripped a coupling hahaha so I've taken 20% off and I'm happy there. Boy she moves in still waiting on my new VFD so I can fiddle with it actually cutting but a huge step forward. Mate thanks again

While I have you I've been having a play with fusion 360 and made a simple 200mmX200mm X 10mm box I wanted to cut out around the outside. I've generated the g code and loaded the file into mach pushed everything into the middle and zeroed the DROs and hit the big go button but it just sorts of stutters for a split second the doesn't move. Bit of a long shot but am I missing anything else in this process?