Hello Guest it is August 26, 2019, 01:49:03 AM

Author Topic: Stepper motor as spindle  (Read 22477 times)

0 Members and 1 Guest are viewing this topic.

Re: Stepper motor as spindle
« Reply #10 on: May 09, 2009, 04:02:30 PM »
I know about this and have dealt with it quite a bit.  In my case I needed to direct-drive a stepper as a lathe axis for very light stock and wanted to move around while keeping the A-axis moving constantly.  And call the A-unit a "rotation".

One, the format of G-code will have some problems with the concept.
Two, Mach3's brain will trash itself because of a numerical integrity bug in the acceleration rules.  It will corrupt its numbers and create software-originated stalls.  At least, I ran into it and dissected the problem to no end.

Allow me to explain.
Say you do tune one rotation= 2000 pulses on a 10-microstep G540.

The G-code problems:
Say you want to rotate at 800 RPM for 1 sec.  You can simply type G1 A[800] F800, but that's not interesting, it goes nowhere.
OK so I want to move to X=1 at 5 ipm.  BTW, Motor Tuning has X-jog limited to 50ipm.
G1 X1 A800 F800
Oh wait.  How many rotations did I really want?  How far did I go?  The line doesn't say.  Let's say I just know that I started at X=0.  So the travel should take 1/5th a min and 1/5th of 800 rotations in a minute is 160.  Uhhh... ok, so G1 X1 A160 F800?
But the Feedrate is not exactly correct.  In fact how does Feedrate work?  How would I get 5ipm?  Well, I know it limits XYZ on the basis on sqrt(X^2+Y^2+Z^2).  But rotational axis is something totally different.  As best I can tell it squares and sums it as well, even though this is a meaningless folly in reality.  That's not a Mach3 thing it's a G-code shortcoming.  So you'd have to calculate out a feedrate=sqrt(5^2+800^2)=F800.0156 wait, that basically means the X-axis speed can't be controlled with Feedrate because it has no effect.  RIGHT, the idea doesn't work for combining numerically small XYZ feedrates with numerically high rotational rates.  You want to say G1 X1 A160 F800 and adjust the number of spindle rotations it takes to get from point A to point B.  This becomes less accurate if high linear travel rates come into play and you may have to write in the Feedrate= sqrt(x-movement^2+y-movement^2+z-movement^2+800^2) equation AND adjust the number of revolutions it takes to get there.

The number of revolutions will build without limit.  Say the first move is:
G0 X0 Y0
G1 X1 A160 F800 and the second move is
G1 Y1 A160 F800
This is wrong because the A is absolute, not incremental (unless you put the whole darn thing in inc mode, the structure of G-code does not allow you to make only one axis incremental).   So next 1in move is A320,  next is A480, etc.
You can periodically reset it with G92 A0.  BUT, G92 takes all axes to a full stop and like a 1 sec pause due to a Mach3 implementation limitation.  So you can't use it between successive instructions.  The finish would be bad and it will take forever.

The Mach3 problem:
I found that when G-code gives lines with a very high ratio of delta-A to XYZ motion, there is about a 2% chance of an super-stall on any given line in Constant Velocity mode, even if the RPM is supposed to be constant and there is not even a big change in speed and direction on the XYZ axes.  It will not only stall the A-axis but potentially can stall any of the XYZ axes at the same time, despite being at low speed.  And it doesn't happen because A grew really really large.  I had it happen when A was near 0.  The problem likely originates from the obscenely high Feedrate needed to set the RPM creating an error in its internal velocity number and it somehow passes along an erroneous change in XYZA velocities that completely ignores the Motor Tuning acceleration.  Exactly where it happens in the code is completely random but will always happen at the same point in the code unless you change something.  It really surprised me though that the corruption did not always involve only the A-axis but sometimes the X-axis which was barely even moving before or after, and had a modest acceleration limit.

This is a bear to workaround.  But there IS a workaround.  The A-numbers in all the G-code lines have to be made numerically smaller.  Basically you gotta make the number of pulses per A-unit 10x or 100x larger in the Motor Tuning, and change max speed and acceleration as well.  Then you use numbers in the A-field 10x or 100x smaller.  Funny because this asks for the exact same movement in the end, but it puts delta-A on the same order of magnitude as delta-XYZ fields more sensible and the stalls will stop.  Downside here is that when the magnitude of A travel approaches the magnitude of XYZ travel then "the Feedrate (F-field)=rpm alone, and set the XYZ feedrate by changing the number of A-rots in that line" may not cut it.

Yeah, as you can see, I've "been there".
« Last Edit: May 09, 2009, 10:37:10 PM by MechanoMan »

Offline simpson36

*
  •  1,374 1,374
    • View Profile
Re: Stepper motor as spindle
« Reply #11 on: May 10, 2009, 05:41:19 AM »
Mechaniman; thanks for the contribution.

I've run into some of the same issues. My approach was to calc the number or rotations needed for the feed rate and movement and always used G0 since the A axis was the limit and it never was turning as fast as I wanted anyway.

example - 1" long cut @ .005 per rev. needs 1/.005*360 degrees of A axis movement, so G0  A72000 X1 got the job done.

For threading, I wrote a little macro to do the calculations and generate the G-code for Mach. Learning how to zero machine coords was a critical piece of the programming pie.

I have also run into the stalling issue, but it my case, it appeared as though Mach was not honoring the acceleration on the X axis. One thing is clear. Anything we do to get this working is going to be a work around, so there is no 'correct way'.


Hood: as usual, your comments are thought provoking (this is a good thing). I was immediately impaled upon this comment:

"Ok so what I would do is use the index pulse for the spindle mode  but also set it up as a home switch for the A Axis, should therefore be a simple matter of homing the A Axis each time you swap from spindle to A. The homing could easily be written into the swap axis macro or am I still not following?"



The only homing I have seen thus far is the arduous multi axis process, and stopping for that with every swap axis is not reasonable, but your comment indicates (I hope) that there is a way to home a single axis?

Would you post your proposed macro to accomplish a swap axis with the A axis homing?


« Last Edit: May 10, 2009, 05:49:58 AM by simpson36 »

Offline Hood

*
  •  25,849 25,849
  • Carnoustie, Scotland
    • View Profile
Re: Stepper motor as spindle
« Reply #12 on: May 10, 2009, 05:59:34 AM »
I am not the best at VB and I am sure you said you have done programing beforeĀ  so I will leave  the detailsĀ  up to you, but as far as homing goes then
DoOemButton(1025) will home the A axis. You will probably need to check first that it is not active, ie the axis is at such a position that the slot is in the sensor, easy enough I would think by looking at LED 39 (A axis home) and if it is active then move the axis before you start the home with a Code("G0A10") or whatever.

Obviously in your setup you couldnt have the A Axis with an index as I was referiing to the OP's setup but it would not be impossible to have the actual spindle index and an A Axis index connected to the index input but have a relay switch them depending on the state of the swap axis.
 Your next problem may lie in that you are using Mill and not turn, I dont know if G76 works in Mill, you may have to go back to your old method for threading. If so then the index issue wouldnt need addressed.

Hood

Offline simpson36

*
  •  1,374 1,374
    • View Profile
Re: Stepper motor as spindle
« Reply #13 on: May 10, 2009, 07:31:26 AM »
Based on your previous comments, I tried the homing on the A axis yesterday and it works fine (I cheated and told mach the spindle index was on the A axis and then turned it by hand to see if it would stop the A axis homing rotation). I have a spare CNC4PC index setup that I can easily mount on my 4th axis so that's a non-problem.

I can dig into the scrpiting, no problemo. The scripting is easy enough, the only frustration is finding all of the Mach specific info as it seems there is no comprehensive manual. The info is spread around hear and there and is incomplete. I have collected all I could find on the Mach VB scripting and your clue about the 4th axis home command is probably enough to point me in the right direction, and so it just a treaure hunt at this point.

And your tip about checking the index state is an excellent one. I don't think I need G76, but I'll cross that bridge when I come to it.

Question: What is the command to swap axis?


Thanks for the  help. I'll see what I can come up with.




Incidentally, don't know if I mentioned it, but Simpson is part of clan Frasier from the Loch Ness region. We have a coat of arms, a Tartar I think it is called (hideous one, unfortunately) etc.




« Last Edit: May 10, 2009, 07:48:53 AM by simpson36 »

Offline Hood

*
  •  25,849 25,849
  • Carnoustie, Scotland
    • View Profile
Re: Stepper motor as spindle
« Reply #14 on: May 10, 2009, 07:59:23 AM »
Afraid as I have a SmoothStepper on all on my machines and none of them have parallel ports so I am unable to test (SmoothStepper does not support swap axis yet)
 Having said that I am almost certain either
SwapAxis(3,6)
or
SwapAxis(A,Spindle)

will work.


Hood

Offline simpson36

*
  •  1,374 1,374
    • View Profile
Re: Stepper motor as spindle
« Reply #15 on: May 10, 2009, 01:24:23 PM »
Hood,

Thanks for the help and ideas and tips. Rehoming the A axis separately was the missing piece of the puzzle. I have it all working now!

There are some details to work out  . . swapped axis must be on the same BOB, etc. but it's all functioning.

My macro tests LED39 and if it is active, just rotates the axis 10 degrees before homing. Great idea . . that would have been one of those things that drives you crazy trying to track down.

I have to mount the index sensor on the 4th axis and a few other odds and ends, and then we'll see if the setup works, and if the re-homing is accurate enough.










Offline Hood

*
  •  25,849 25,849
  • Carnoustie, Scotland
    • View Profile
Re: Stepper motor as spindle
« Reply #16 on: May 10, 2009, 01:27:17 PM »
Homing should be accurate if using an opto, certainly is on my coil winder.
Hood
Re: Stepper motor as spindle
« Reply #17 on: May 10, 2009, 01:32:12 PM »
I misspoke.  I meant "zero", not "homing".  I am not sending the machine off to find home in a mechanical sense.  In fact since my stock is round, it does not matter at all what angle the A-axis starts at, they're all the same.  Later in the code I do start cutting flat sides into it and need to maintain the actual angle. 

For example, say you are lathing a cylinder into a profile:
G0 ...  A20
G0 ...  A50
G0 ...  A150
G0  ... A168

This is getting problematic.  The numbers get larger and larger indefinitely because I never turn back and rotate the other direction.  Now if I want to add ONE operation in there requiring an extra 20 turns, I may have to add 20 to like 100 other lines following it.

We can't say "G0 A0".  Well, you could, but it could mean hundreds of turns in the opposite direction as motion.  You could be there for a long time.
Instead I can just back off the work, say G92 A0 and the current location is considered zero so we have a divider in the code where it won't matter if you need to add rots before this line, we won't have to fix lines after the G92 A0.  All those lines rotate off the new zero so it'd be A20, A40, A60....   G92 does involve a 1 sec software-based pause which stops all axes.  This may create a mark in the work's finish so you may have to back the cutter off the work, G92, and reapproach.

This is especially good if you already separate code into sections based on different features.

Now if A1 is one rotation, as long as A is already a whole number before G92 A0, then it IS homed at 0 deg as well.  Mechanically, it was already home since it's at zero deg, but now it's software-home as well.
« Last Edit: May 10, 2009, 01:38:17 PM by MechanoMan »
Re: Stepper motor as spindle
« Reply #18 on: May 10, 2009, 01:33:40 PM »
I was hoping that the SmoothStepper might fix the software-initiated stalls when using the A-axis like this.  No, it doesn't.  It will stall with the parallel port or with the SmoothStepper the same way.

BTW, long moves are NOT required.  In fact so far the problem seems to come up when there is very little XYZ motion.  I was profiling by doing 4 turns and 0.1" X-steps and Y being a variable radius (using side cutting).  Y changes slowly.  It's set up to be one continuous profiling cut.  But after the first 5 it would bomb on the 6th and stall out the A and X axes until the profile was done and it came to a stop. 

Boggled my mind that it's crawling the X-axis along at what equates to under 5 ipm, at what should be a fixed speed, and stalls it.
« Last Edit: May 10, 2009, 01:57:51 PM by MechanoMan »
Re: Stepper motor as spindle
« Reply #19 on: May 10, 2009, 02:34:59 PM »
Hey Triag, why did you want to use a stepper for a spindle? Just curious.