Jogging while spindle runup

More
01 Jan 2024 15:47 #289480 by teegai
Hi,

I'm running a mill with a 2.2kW "china spindle", controlled via Mesa 7i96s and LinuxCNC 2.9.0~pre1+git20230208.f1270d6ed7-1 with Axis GUI. To warm up the spindle before use, I run the following G-code from file:
m3
s4000  g4 p30
s8000  g4 p30
s12000 g4 p30
s16000 g4 p30
s20000 g4 p30
s24000 g4 p30
m30

This works flawlessly, but I also want to move physical axes while the spindle is performing runup. This was possible when I had the spindle speed manually set by VFD potentiometer and it proved to be useful. E.g. to rough align workpiece coordinates, even to touch off with the end mill or to move the spindle out of the way to recheck or fix clamping. I'm aware that fiddling around with a running tool might pose safety risks and act accordingly. The majority of the work pieces are one-off and machine usage is sparsely, so everything apart from the actual milling takes a large share of the time.

How do I archive this? As I understand, the G-code running interpreter occupies machine controls in the same way manual jogging or MDI would. One faint idea would be to temporary unplug HAL spindle enable/command and feed it separately, maybe using timedelay(9) and some kind of discrete steps generator to iterate through the RPMs. Maybe triggered by a button on the gladevcp panel, but I want to be able to reliably abort the runup (apart from estop). I'm lost, already on the concept level.

On a side note, I'm surprised that there is virtually no search match on this forum for runup (run-up) or warmup (warm-up), even though it's supposed to be beneficial for bearing/etc. life time and surface finish. Am I looking for the wrong keyword? Don't do people runups? Or just manual? By VFD or legacy controller feature? Via post processor options, so it becomes part of the work machining G-code? But then what if the spindle is already warm?

Thanks!

Please Log in or Create an account to join the conversation.

More
03 Jan 2024 14:29 #289659 by andypugh
As you have noted, you can't jog the machine whilst G-code is executing.

It might be possible to create a custom M-code to do this.
Basically, this would start a routine, probably in Python, that would send a "complete" return value, but without stopping.

Before setting it up as an M-code, though, try running this Python code from the command line and see if jogging is possible.
#!/usr/bin/env python 
import linuxcnc
import time
c = linuxcnc.command()
c.spindle(SPINDLE_FORWARD, 4000, 0, 0)
time.sleep(30)
c.spindle(SPINDLE_FORWARD, 8000, 0, 0)
time.sleep(30)
c.spindle(SPINDLE_FORWARD, 12000, 0, 0)
time.sleep(30)
c.spindle(SPINDLE_FORWARD, 16000, 0, 0)
time.sleep(30)
c.spindle(SPINDLE_FORWARD, 20000, 0, 0)
time.sleep(30)
c.spindle(SPINDLE_FORWARD, 24000, 0, 0)
time.sleep(30)

Save that to a file, make the file executable (chmod +x filename.py) and then run it from the command line (./filename.py)

That _should_ sit in the background increasing spindle speed, while you can do other things. But it is completely untested.....
The following user(s) said Thank You: teegai

Please Log in or Create an account to join the conversation.

More
04 Jan 2024 14:57 #289786 by teegai
Replied by teegai on topic Jogging while spindle runup
Hi Andy,

that suggestion works almost flawlessly! Thanks a lot. I can jog while it's executing and the Axis GUI spindle buttons and speed side panel display correctly.

Only thing I had to add initially was the import of the SPINDLE_FORWARD direction constant. I've then evolved the script to have safe ^C (Ctrl-C, sigint, KeyboardInterrupt) behaviour, and also abort if the speed got set from somewhere else, e.g. if you happen to hit F9/F10 in Axis and forget about it. Also, it checks whether the machine is on to start with. I'm also attaching a copy as a file, as I have a feeling this forum software will eat all my white spaces:
#!/usr/bin/python3

import linuxcnc
from linuxcnc import SPINDLE_FORWARD, SPINDLE_OFF
import time
import sys

# spindle(direction: int, speed: float=0, spindle: int=0, wait_for_speed: int=0)

def runup():
        for speed_k in 4, 8, 12, 16, 20, 24:
                speed = float(speed_k * 1000)

                cmd.spindle(SPINDLE_FORWARD, speed, 0)
                time.sleep(30)

                # don't set new speed if we're not alone
                stat.poll()
                current_speed = stat.spindle[0]['speed']
                assert current_speed == speed, 'abort, spindle speed set from other source'

        cmd.spindle(SPINDLE_OFF, 0)

cmd = linuxcnc.command()
stat = linuxcnc.stat()

stat.poll()
if not stat.enabled:
        print('abort, machine is off')
        sys.exit(1)

try:
        runup()
except Exception as e:
        print(e)
        sys.exit(1)
except KeyboardInterrupt:
        cmd.spindle(SPINDLE_OFF, 0)

I've then checked the docs on custom M-Code www.linuxcnc.org/docs/html/gcode/m-code.html#mcode:m100-m199 as per your suggestion, and it works with a nc_files/M100 file reading
#!/bin/sh -eu

~/runup.py &

exit 0

as a test. To make it fancy, one could sure put the forking/job control inside the Python script. However, I think I won't use it that way. I've always got an open terminal for fetching the G-Code and misc use, so running the Python script from there has no overhead. In contrast, toggling MDI mode forth and back seems fiddly to me, and I'm not yet sure if I want to have a gladevcp button along with some interlock logic against accidental tripping. Also, running the custom M-Code from a G-Code file doesn't seem that useful for me in that point in time.

Again, thanks a lot!
Attachments:
The following user(s) said Thank You: eduard

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum