caxis.comp - How to freewheel axis/spindle?

More
21 Jan 2025 17:23 #319579 by spumco
I'm using a component authored by Andy Pugh to control my lathe's main spindle as both a C-axis and spindle.  Comp attached, and I believe this was the last version Andy and NoJo worked out via the forum a few years ago.

NOTE - this component treats the spindle as an axis until a spindle command is issued.  This means absent a spindle command, the C-axis is active and trying to maintain a position.  Once the spindle command is done, C-axis re-engages and will return to the last position (within one turn) prior to the spindle command.

I want the ability to disconnect the spindle/axis so I can manually turn it (indicating part/chuck).  Because the spindle motor is a servo, if the drive is enabled and machine is on, the spindle is locked in position when the machine is at rest.

Right now I have a simple enable toggle in HAL that disables the drive directly.  This allows me to turn the spindle by hand for indicating or tightening the chuck.  I can jog the C-axis, but I find being able to manually move the spindle more convenient.

Unfortunately, because I haven't disconnected anything else in HAL, if I rotate the spindle more than about a turn I get a following error and LCNC turns the machine off.  I've had to set the ferror higher than I'd like just to be able to turn it a bit, and I'd really like to tighten it up.

I could use some help figuring out how to disable the motor in such a way that:
  • No following error while disabled, regardless of turns
  • No caxis.comp errors or accumulation of following error upon re-enable (which would result in a potentially violent attempt by the C-axis PID to eliminate the following error)

Is this something I could accomplish in HAL, or does caxis.comp need to be modified/edited in some way?
Attachments:
The following user(s) said Thank You: jpg

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

More
27 Jan 2025 10:14 #319941 by Aciera
Replied by Aciera on topic caxis.comp - How to freewheel axis/spindle?
I guess for free wheel operation you would need to disconnect the encoder signal in hal but the tricky bit is that you will need to reorient the spindle to within ferror range before reconnecting the encoder again.

I'm not familiar with 'caxis.comp' I switched the controller mode using a digital signal:
forum.linuxcnc.org/10-advanced-configura...code?start=30#272218
The following user(s) said Thank You: spumco

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

More
27 Jan 2025 13:27 #319948 by spumco
Replied by spumco on topic caxis.comp - How to freewheel axis/spindle?
@Aciera - 

I had hoped to duplicate your C-axis process back when you were working on it, but my drive doesn't permit on-the-fly mode switching via external input.

Since I don't think I can use orient.comp and caxis.comp on the same joint, I'm thinking about ways to un-home and re-home the joint/axis.  Caxis.comp doesn't re-home or move to C0 whenever the spindle stops - it returns to the same position it was in when the spindle command was issued.

Since I don't need to freewheel in the middle of a program, what do you think about using halui to unhome/rehome the C-axis?
  • Freewheel button ON (M-code)
    • set halui.joint.C.unhome
    • Latch encoder reset pin HIGH (to keep it at 0)
    • Amp enable OFF
  • (manual spindle rotation activity)
  • Freewheel button OFF
    • Amp enable ON
    • Unlatch encoder reset pin
    • set halui.joint.C.home
See any major issues with the above before I try testing it this evening?
The following user(s) said Thank You: jpg

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

More
28 Jan 2025 08:34 #319984 by Aciera
Replied by Aciera on topic caxis.comp - How to freewheel axis/spindle?
Sure, give it a try and report back.

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

More
01 Feb 2025 03:26 #320278 by spumco
Replied by spumco on topic caxis.comp - How to freewheel axis/spindle?
No joy.

I can't unhome a joint via hal commands, or at least not how I've got it set up currently.

Attempted an M-code bash file with:
#! /bin/bash
#   C-AXIS FREEWHEEL ON

#SET MODE TO MANUAL
halcmd setp halui.mode.manual 1

#UNHOME JOINT AND RETURN PIN TO LOW STATE
halcmd setp halui.joint.2.unhome 1
sleep 1
halcmd setp halui.joint.2.unhome 0

#RESET ENCODER AND LATCH THE RESET WHILE FREEWHEEL ON
halcmd setp hm2_[MESA](BOARD).0.encoder.04.reset 1

#DISABLE SPINDLE MOTOR AMP
halcmd sets SPIN0-AMP-DISABLE 1

And am getting a "must be in joint mode or disabled to unhome" error.

Any idea how to disable or switch to joint mode for a single axis, either in HAL or with a bash file?

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

More
01 Feb 2025 07:45 #320302 by Aciera
Replied by Aciera on topic caxis.comp - How to freewheel axis/spindle?
As you don't want to unhome during gcode execution you might want to try a python component and use
self.command.unhome(joint)

That is what the guis use, which seems to work just fine.
The following user(s) said Thank You: spumco

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

More
01 Feb 2025 16:37 - 01 Feb 2025 16:38 #320333 by spumco
Replied by spumco on topic caxis.comp - How to freewheel axis/spindle?
@Aciera,

LCNC manual on the python module is, I'm sure, adequate for someone with coding experience, but like many other manual sections it assumes a certain level of familiarity with the subject.  The explanations are meaningless without some sort of foundation:

Import the linuxcnc module.

What does 'import' mean? What is the linuxcnc module and where is it?

If you've got the patience, could you walk me through creating a python component, or pointing me towards a resource with novice-level explanations?

Or just directing me to a complete example of a python component and how to get LCNC to use it?

Thanks, I feel like I'm back at Day 1 with LCNC.
Last edit: 01 Feb 2025 16:38 by spumco.

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

More
01 Feb 2025 17:46 #320336 by PCW
You might use a different PID (with different tuning) during the "recovery" period
so the correction is gentle, that and a 'near' component to determine when to go
back into full servo mode.

So

hand mode: drive disabled, LinuxCNC motor position feedback looped
back from motor position command (via mux)

recover mode: drive enabled,  LinuxCNC motor position feedback looped
back from motor position command (via mux) Special PID used with bounded
error and no FF so correction velocity is limited

exit from recover mode when encoder feedback is "near" position command
The following user(s) said Thank You: besriworld, Aciera, spumco

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

More
01 Feb 2025 18:23 - 01 Feb 2025 18:28 #320338 by Aciera
Replied by Aciera on topic caxis.comp - How to freewheel axis/spindle?
As for the component (Bit of a rushed job as I'm short on time right now):
Save this as 'unhome_comp.py' in a folder named 'python' in your machine config and mark as 'executable':
#!/usr/bin/env python3
import hal
import linuxcnc

h = hal.component("unhome-comp")
h.newpin("unhome-rotary", hal.HAL_BIT, hal.HAL_IN)
h.ready()
c = linuxcnc.command()
joint = 0
homed = 1
try:
    while 1:
        if homed == 1 and h['unhome-rotary'] == 1:
            c.teleop_enable(0)
            c.wait_complete()
            c.unhome(joint)
            homed = 0
        if homed == 0 and h['unhome-rotary'] == 0:
            homed = 1

except KeyboardInterrupt:
    raise SystemExit

add this line to the [HAL] section of your ini file:
HALCMD = loadusr ./python/unhome_comp.py

Start your config and open the 'Show HAL configuration' tool and 'watch' the 'unhome-comp.unhome-rotary' pin, setting it to TRUE should unhome the joint number set in the python script in the line 'joint = 0'.

 
Attachments:
Last edit: 01 Feb 2025 18:28 by Aciera.
The following user(s) said Thank You: besriworld, spumco

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

More
01 Feb 2025 18:47 #320340 by spumco
Replied by spumco on topic caxis.comp - How to freewheel axis/spindle?
@PCW-
I thought about using orient.comp with it's own PID to do just what you suggested (get it close before re-linking the main PID), but caxis.comp interferes with orient (I think).

Cooking up a 3rd get-it-close PID is a fantastic idea.  I'll have a go at it.

@Aciera-
Writing a python comp for me was more than I'd expected (or deserve), but I suspect it'd take longer to explain things and bring me up to speed than to just whip something up.

I'll try to digest what the comp is doing and test it out.

Thank you both very much.
 

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

Time to create page: 0.352 seconds
Powered by Kunena Forum