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:
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