Hello Guest it is April 10, 2021, 07:20:11 PM

Author Topic: Setting Motor Counts Per Unit in macro  (Read 4673 times)

0 Members and 1 Guest are viewing this topic.

Re: Setting Motor Counts Per Unit in macro
« Reply #10 on: January 12, 2018, 10:52:09 PM »
Hi,
the speed calculation is reasonably straight forward.

My suggestion is to put some spindle speed adjustment code in the PLC script:
1) Read the current Z position (diameter)
2) Calculate the spindle rpm to suit the required surface speed
3) Apply max and /or min limits to the calculated spindle speed
4) Apply the calculated and limited spindle speed to the hardware spindle.

Step 4) is the critical one. I don't think trying to change the 'steps per unit' value on the fly is the right idea. Once Mach has planned the trajectory and dispatched it
to the controller you can't change it. The controller itself may be able to insert or remove pulses from the pulse stream like a THC function but Mach can't.

Niether can you issue another Gcode command without overwriting the current move and losing it. Lets say you have a coordinated move in X and Z:
G1 X100 Z100 F300.
After a second or so into the move Z has changed and therefore you want to change the spindle speed. If you did something like:
mc.mcCntlGcodeExecute(inst, "S680") 
for instance then it would crash the previous move which has yet to complete, and so wouldn't work.

This API may help:
Quote
LUA Syntax:
rc = mc.mcSpindleSetCommandRPM(
      number mInst,
      number RPM)
I've experimented with it a little and it seems to do the job. That is to say that you can issue a coordinated move, the PLC script will run during the move and it will calculate
the new required spindle speed and issue a speed command WITHOUT the currently executing move being affected.

Note that for the purposes of experimentation I have used a Step/Dir out of band motor as a spindle. I observed the spindle speed by monitoring the Sim plugin diagnostics
and it appears to work. I have not tried on my machine and it would represent quite a quite a re-wire from my current configuration. I presume it would also work
with the PWM output but I haven't tried it, that's your job!

I will hash up some code and post it soon.

Craig
My wife left with my best friend...
     and I miss him!
Re: Setting Motor Counts Per Unit in macro
« Reply #11 on: January 13, 2018, 12:04:49 AM »
Hi,
try put this in the PLC script:
Code: [Select]
local radius=mc.mcAxisGetPos(inst,mc.Z_AXIS)
if radius==0 then radius=1 end
local surfacespeed=mc.mcCntlGetPoundVar(inst,2134)
local spinspeed=surfacespeed/(6.282*radius)*360
if spinspeed>=15900 then spinspeed=15900 end
mc.mcSpindleSetCommandRPM(inst,spinspeed)

Craig
My wife left with my best friend...
     and I miss him!
Re: Setting Motor Counts Per Unit in macro
« Reply #12 on: January 13, 2018, 11:30:37 AM »
I may be getting off subject but I did notice this. If I select “A Rollover” in Mach4 Configuration / General / Rotary Axis and send Gcode “G01 A 370 F10” the A axis DRO goes to 10,  (360° + 10°). Mach4 see 370 as degrees but handles them a linear.  Mach3 has an Angular Properties set up in General config that Mach4 is missing. See attached. Oops! Having adding pictures.
« Last Edit: January 13, 2018, 11:42:48 AM by Tony Bullard »
Re: Setting Motor Counts Per Unit in macro
« Reply #13 on: January 13, 2018, 02:19:16 PM »
Hi Tony,
as far as I know Mach3 and Mach4 handle rollover the same...see attached.

Craig
My wife left with my best friend...
     and I miss him!

Offline Mauri

*
  •  320 320
    • View Profile
Re: Setting Motor Counts Per Unit in macro
« Reply #14 on: January 13, 2018, 05:51:09 PM »
Craig,
I setup a our old test Controller with ESS and a Motor connected to the A Axis on our bench and first ran some test code on Mach3 and timed it at various radius sizes and it worked perfectly as usual. Fast when the radius is small and slower and slower as when the radius was set large and larger.
It is also very accurate when doing a manual calculation comparing to its actual time to complete.
To do this you have to have a setting of .0001 in the Mach3 Setup for the A axis.

I then entered your PLC code into Mach4 screen under PLC and performed the same test.
The result was no speed change no mater what Z Axis radius was set and no time difference apart from the Z Axis Radius move variation.
The A Axis motor never changes speed.
So something is missing here.
Did you test it?
Regards,
Mauri.

Offline Mauri

*
  •  320 320
    • View Profile
Re: Setting Motor Counts Per Unit in macro
« Reply #15 on: January 13, 2018, 06:15:11 PM »
Craig,
Test File I used.
G00 G49 G40 G80 G50 G90 G64 G21
G01 Z5.000 F400 -- changed Z to different values
G01 A360.000
G01 Z0.000
G01 A0.000
M30
I did some more testing to see what changes appear in Mach4.
The #2134 goes to 400.
The Spindle which started up at 8000 on the Mach4 Screen went to 15900 after the program had reached A360 and was about do go to zero on Z and A Axis.
So why is my spindle affected by this PLC code and not the A Axis?
Regards,
Mauri.
Re: Setting Motor Counts Per Unit in macro
« Reply #16 on: January 13, 2018, 06:17:17 PM »
Hi,
as I posted I used the Sim plugin diagnostic to test it, I have no intention of re-wiring my machine...that's your job.

How are you controlling the A axis?. I used Step/Dir on an out of band axis. You cannot use a coordinated axis otherwise you will break legitimate moves when
you attempt to change the pulse rate on the A axis.

May I suggest trying to use an out of band axis, say OB1, that is motor 6. Per the Configure/Mach/Spindle page you will have to set Step/Dir axis as OB1 (6).
On Configure/Mach/Axis Mapping enable OB1 and assign motor 6.

Even if the axis is not equipped you should see the Step/Dir pulses on the motion controller diagnostic page.

I need to point out again YOU CANNOT USE A COORDINATED AXIS, it must be OUT OF BAND. Once a trajectory is planned and dispatched to the motion controller
it cannot be changed. Any attempt to change the motion of one of the coordinated axes will break the entire move. The API I have suggested allows a coordinated
move to be executed and yet allows changes to the pulse streams of out of band axes WITHOUT breaking the coordinated move.

Craig
My wife left with my best friend...
     and I miss him!
Re: Setting Motor Counts Per Unit in macro
« Reply #17 on: January 13, 2018, 06:31:05 PM »
Hi,
that test code is wrong, you are treating the A axis as a position controlled axis which is not possible if you which to change its rotational speed on the fly.

Quote
The #2134 goes to 400

Pound variable #2134 is the current feedrate in units per minute.

Quote
G01 A360.000

This is a positional move, the A axis is to accelerate to the current feedrate and then decelerate so that it turns 360 degrees in total. How are you expecting its
speed to vary? Its a coordinated axis and it accelerates and decelerates according to the motor tuning parameters you supplied.

Your A axis needs to be a spindle, that is to say a free spinning axis. Then repeated application of the mc.SpindleSetCommandRPM() will cause the rotational rate to
change in a manner for you to determine.

Craig
My wife left with my best friend...
     and I miss him!
Re: Setting Motor Counts Per Unit in macro
« Reply #18 on: January 13, 2018, 06:43:32 PM »
Hi,

Quote
So why is my spindle affected by this PLC code and not the A Axis

Because the API is a spindle command, if you hook your A axis up to the spindle output of your controller it will behave as a spindle. You would then
be able to vary its speed according to the radius, ie Z coordinate.

Craig
My wife left with my best friend...
     and I miss him!

Offline Mauri

*
  •  320 320
    • View Profile
Re: Setting Motor Counts Per Unit in macro
« Reply #19 on: January 13, 2018, 06:47:41 PM »
Craig,
Thanks for the reply.
So how does Mach3 do it with the A Axis just being a normal stepper motor setup?
How would I be able to setup my stepper as a spindle just using Mach4 when the code you provided affects the real spindle and not the A axis?
Need some more help here.
Regards,
Mauri.