Late reply as I have been investigating an idea.
I liked the idea of configuring the C-axis as a locking-indexer then using the "joint.2.unlock" pin to control whether the spindle was under velocity control or C-axis control.
But it seems that you can't jog an indexer, and can only do G0 moves.
Both these restrictions seem arbitrary, I might look in to removing them.
But, back to your machine:
It's easy enough to set up a PID controller to add a a second velocity command to the spindle stepgen command for positioning.
What complicates this is that you might have 1,000,000 full revolutions already on the spindle when you engage the C axis, and the PID would want to unwind (very nearly) all of them to go to +90 degrees, for example.
Does your spindle encoder work? (It is in the HAL file, I see. Does the HAL pin spindle.0.revs increase by 1 for every spindle rotation?
(You can test this with the HAL meter, under the "Machine" menu in the Axis GUI.)
Here is a possible solution.
1) Define a user M-code to enable C-axis control.
2) Set up a 4th PID to control the C axis
3) Add the output of that PID to the spindle velocity command.
4) When enabling the C-axis PID, also set the "index-enable" for the spindle encoder. This means that there will be a largely uncontrolled movement of up to 1 turn when the C-axis is engaged, but then it will be referenced to the encoder index.
First you need to make the lathe into a 3-axis machine.
I suggest making a copy of the entire current working config (just copy the ~/linuxcnc/configs/CNC_lathe folder and rename the new one)
In the INI in the [DISPLAY] section:
In the [KINS] section
Code:
JOINTS = 3
KINEMATICS = trivkins coordinates=XZC
Code:
[TRAJ]
COORDINATES = XZ
Code:
[AXIS_C]
MAX_VELOCITY = 40.0
MAX_ACCELERATION = 100
MIN_LIMIT = -3600
MAX_LIMIT = 3600
[JOINT_2]
TYPE = ANGULAR
HOME = 0
FERROR = 1.0
MIN_FERROR = .1
MAX_VELOCITY = 40.0
MAX_ACCELERATION = 350.0
P = 2
I = 0.0
D = 0.0
FF0 = 0.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_OUTPUT = 0.0
MIN_LIMIT = -3600
MAX_LIMIT = 3600
HOME_OFFSET = 0.000000
HOME_SEARCH_VEL =0
HOME_LATCH_VEL = 0
And see if a C-axis appears in the GUI. (with only these changes it will f-error immediately if you try to move it)
Then attach the HAL and INI from that config here so that we can have a look at setting up the C-axis.