Hello Guest it is November 27, 2021, 04:45:25 PM

Author Topic: How to stop the spindle motor in M6 script?  (Read 515 times)

0 Members and 1 Guest are viewing this topic.

Offline jevs

*
  •  315 315
    • View Profile
How to stop the spindle motor in M6 script?
« on: August 04, 2019, 04:54:59 PM »
I believe I need to use mcSpindleSetCommandRPM, however, the cryptic way the API help is written it never just tells you exactly what code to use. So how do I turn this information into something that actually works?
This does not work:
Code: [Select]
rc = mc.mcSpindleSetCommandRPM (inst, 0)and neither does this:
Code: [Select]
int rc = mcSpindleSetCommandRPM(inst, 0)


 mcSpindleSetCommandRPM
C/C++ Syntax:
int mcSpindleSetCommandRPM(
      MINSTANCE mInst,
      double RPM);

LUA Syntax:
rc = mc.mcSpindleSetCommandRPM(
      number mInst,
      number RPM)

Description:
Set the commanded RPM for the spindle.

Parameters: Parameter Description
mInst The controller instance.
RPM A double specifying the RPM.


Returns: Return Code Description
MERROR_NOERROR No Error.
MERROR_INVALID_INSTANCE The mInst parameter was out of range.

Notes:
None.

Usage:

// Set the spindle RPM to 5000.
MINSTANCE mInst = 0;
int rc = mcSpindleSetCommandRPM(mInst, 5000);

Offline jevs

*
  •  315 315
    • View Profile
Re: How to stop the spindle motor in M6 script?
« Reply #1 on: August 04, 2019, 06:21:42 PM »
I still have not found a way to set the RPM to zero using the above information, however I did find something that works to stop the spindle motor.
Code: [Select]
rc = mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_OFF)

However, in Simulator mode anyway, it does not appear to be waiting for the decel time before making the next moves....

So, any ideas on getting the RPM mentioned above to work, or how to make sure it is waiting for the motor to slow down before moving to the next part of the script using of this direction change command (setting to off).

Offline jevs

*
  •  315 315
    • View Profile
Re: How to stop the spindle motor in M6 script?
« Reply #2 on: August 04, 2019, 06:49:37 PM »
okay, this does seem to be working for changing the RPM. Now that I have a better understanding of how to use the debugger that is helping. However, setting this to zero does not actually take it to zero for me because my min RPM for pulley set 1 is 360, so using this code really sets the speed to 360 instead of OFF.
Code: [Select]
rc = mc.mcSpindleSetCommandRPM (inst, 0)
So, I still have the question about how to make sure it is going to wait for the motor decel time before running the rest of the script if I use the Direction command and setting it to OFF.

Offline jevs

*
  •  315 315
    • View Profile
Re: How to stop the spindle motor in M6 script?
« Reply #3 on: August 05, 2019, 04:07:59 PM »
I figured it out!

Code: [Select]
rc = mc.mcCntlGcodeExecuteWait(inst, "M05") --Turns the spindle off and waits decel time
It seems so simple now. Not sure why this was so hard to get. I finally thought....well maybe just running an M code in the script will not ignore the decel time. So I found this in the API list.

Anyway, I tested this is in the debugger and it waits exactly correct for my decel time in the spindle motor table before going to the next line of code.

So, this particular thread is solved.

Offline jevs

*
  •  315 315
    • View Profile
Re: How to stop the spindle motor in M6 script?
« Reply #4 on: August 05, 2019, 07:41:58 PM »
I did some testing based on something else I read in an old post.
Be aware that the Accel and Decel times when used with these commands are computed down. The number you put in for accel and decel are for max RPM. Mach4 will calculate this time down from there based on the RPM. It will not use the number you put in at lower RPM, it will be a shorter time.
I did time my machine vs the Mach calculated and used values and it is not too bad for my machine. It was close though so I added a second to the times just to be safer. 
I would recommend timing your spindle speed times by hand at 500 or 1000 RPM intervals and compare it to the time Mach uses. You can stretch the max number until every RPM on your largest tool has enough time (if it does not work out with the real time used for it to decel from max RPM).