Author Topic: positional 4th Axis  (Read 3161 times)

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
positional 4th Axis
« on: October 31, 2025, 02:24:32 am »
I had a look at the old lathes headstock recently and stripped it down
and painted it. The bearings are ok, I've gave them soaking and  repacked them
and installed the spindle.

What I had planned to do was sit it on a pedestal and use it for buffing and wire brushing.
After inspecting the bearings, I've changed my mind and will try to make a positional 4th Axis.

There are some quite nice builds using Harmonic and cycloidal  drives but these are too  fancy 
for my use case as I don't want to make a 4th Axis that can cut metal whilst moving, just a positional 4th Axis so
move to an angular position, index spindle (lock it), machine feature, rinse and repeat.

The sanest thing to do, and a fall back position if all else fails, is buy or make some indexing
plates for a spindexer and make a mounting with the 10 ths holes and be done with it.

I had a look about in the larder and the only motor left is an old Reliant Nema 34 motor and I do have a drive to suit.
Using this motor in open loop mode and the belt and pulleys would be the simplest way.
I'm not going to do that though.

So the idea is to fix a 3 jaw chuck and face plate type 4 jaw which could have a small vice.
Because I want to run a series of sequential drilling and tapping ops I don't think that the open loop stepper
will suffice alone even with gear reduction and some microstepping.

A closed loop stepper is better as the position is not reliant on the step angle of the motor but you are
measuring the angle of the motor not the spindle and would still have to make sure that the spindle doesn't move whilst being locked into position.

What I'm going to try is to mount the encoder on the spindle and run the stepper motor in closed loop
mode (with an esp32 ) and use a parking procedure where the caliper snugs up on the rotor during the last
bit of the deceleration phase of a move, to do this I'm going to try using another small stepper motor and a differential thread to activate the caliper.

Drive = 30 teeth
Driven 120 teeth
I'm going to use x 8 microstepping.

I do have leadshine drives which require 24 volt and my lab power supply only goes to 15 so
for testing and debugging I'll use the easydriver boards as they can run happily at 12 volts.
I'll use the Mach3 usb board as per the tapping head.

I would like it to have a manual mode where it's not connected to the controller.
I would like to be able to use a terminal program (like realterm\putty)  semi manual.
I would like to use the drilling and tapping plugin to write the positioning gcode to drill and tap
a hole. 

Dave







Offline EddyCurrent

  • CNC Jedi
  • *****
  • Posts: 5329
  • Made in England
    • View Profile
Re: positional 4th Axis
« Reply #1 on: October 31, 2025, 14:03:05 pm »
Dave,

Would it also work in a vertical position like a rotary table ?
As an aside I've been watching an excellent youtube channel called, "Cutting Edge Engineering Australia", it's worth checking out.
Filmed in Supermarionation

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #2 on: October 31, 2025, 23:38:12 pm »
Hi Eddy

Would it also work in a vertical position like a rotary table ?

Unfortunately, no, it's just too big, (see pic) what I would like to do is cut gears and splines in plastic and
aluminum, and be able to mount a carburetor bowl from vintage machinery and re spot face the threaded holes and clean up the thread.

Years ago I had a look at the problem when I had a lot more hair and a lot less experience, and
there were spindexers, rotary tables, universal dividing heads, and a fancy one call a plug grinder.

What I realised was the accuracy was in the plates and locking mechanism.
I graphed the error in a simple system, I used CB to polar array a line at 1.8 degrees steps and at
a pcd of 150 mm and at the circumference of the workpeice the error was 0.49 mm steps

I then mapped the +- error in the stepper motor 10% or 0.18 deg you don't want to microsetep down into that area
as you have no idea where you are without mapping this is why I'm microstepping by eight and not 10, and using 4 to 1
gear reduction which is still not enough resolution really.

I do have two industrial encoders an 360 ppr and an Allen Bradley at 5000 ppr.
The 360 ppr is not suitable and the AB one is two expensive to use on something that I'll use once in a blue moon.

I had ordered some AS 5040's 1024 ppr for the tapping head but decided not to use them
They are no good for this task either, so I had a look at some 21 bit encoders which would provide
up to 2000000 ppr although after filtering and signal conditioning 100000 ppr was reliable.

This was to much for the micocontroller  and the other problem was that I'd have to drive it
from the spindle shaft where it would be easy to knock about.

I've been thinking about a 4th axis on and off for years but it is a difficult problem and a standard open loop
system won't be up to the task, a closed loop stepper would be better but the encoder
is on the motor and not the spindle so any transmission error caused by backlash in the system
(caused by brake engaging) may move the spindle slightly without the motor compensating for it.

Having the encoder on the spindle can be problematic as if there is any appreciable backlash in the system, perhaps two rollers
connected together with gears or a rack and pinion then the controller can oscillate.
 I think I'll be ok here as I wrote my own pid routines I clamped the I value in the PID to a quarter of the total output so that the system could not saturate.
Maybe in a few days I'll have the machining done so that I can bring it inside and start coding.

Anyway while looking about on utube at 21 bit encoder vids I saw this
https://www.youtube.com/watch?v=MgQbPdiuUTw
(I'm glad I did) this guy legit knows his sensors, I'm really impressed with his project.

 I want to use those AS5040's like he did I don't need the impressive resolution he needed but if I orientate the
magnets like he did I don't have to have the encoder hanging of the end of the spindle.

Quote
"Cutting Edge Engineering Australia", it's worth checking out
Yes I do watch him I much prefer real humans rather than the overwhelming amount of AI generated stuff.

Edit: had trouble inserting hyper link
Dave
« Last Edit: October 31, 2025, 23:46:19 pm by dave benson »

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #3 on: November 03, 2025, 00:12:53 am »
I got a chance to do some more today and gave it a test run, as an aside I really wanted to use the leadshine drive so
looked in the manual DM556 and it said 20 to 50 volts, I gave it a go anyway
and set the drive to minimum current out put and feed it 15 volts, the drive fired up and I plugged it
into the mach3usb board and configured the axis I got to run with the settings in the pic.

About 22 rpm it stops and starts quick enough and has enough torque to do the dynamic braking tests.
With a 24 volt 10 amp supply and this gearing it should have good torque up to 75 rpm.
I'm waiting on the brake line fitting, so can't do much more with that, except model the activation mechanism.

At this point I have to decide what the interface should be, I do like the idea of using the tapping head power and signal lines
via a plug, however I want to use the tapping head in conjunction with
4th Axis so would have to get another switching power supply.
There's no room left in the control box so I would have to get another smaller box to house the power supply and driver this would be pretty straight forward if a bit messy.

I did check and there seems to be enough bandwidth in an espnow bluetooth link to do 30 rpm, this would require
two esp32's one as a port sniffer connected to the break out board.

I had a look at the Xaxis\Yaxis wrap pp's and the wrapper plugin along with the drilling and tapping plugin.

The tapping code ran through, the only modification required being to set the rollover in the mach3 general
config as this 4th axis wants the dro to roll over to zero and the tapping head doesn't.

I used the Xaxis wrap pp and placed the geometry in different planes using linear and polar arrays and
laying the circles along the X axis.

I discovered that if I laid out the circles along the X axis spaced as 1mm = 1deg, then the x values the pp
outputs are the the A axis values I then hand edited the file inserting the (A) axis values
and it worked, the file ran through. For my purposes, drilling a radial bolt hole pattern on the periphery of 
of a disk I would not want the x and y axis's to move until all of the holes are done.
What the hand edited code will do is drill holes in a spiral pattern.

Dave

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #4 on: November 07, 2025, 12:06:29 pm »
The brake line fitting came so I fitted it and I bleed the system, the brake is surprisingly
progressive, I needed to see just how much plunger travel was required so as to make the activation system.

I left the brake activated overnight with a load on it too see if it didn't leak down, it's ok
To see how much holding force it had, grabbed a 450mm shifter and clamped the head down
to the bench top, and tried to make the brake slip, it didn't so I put an indicator on the brake bracket to see if it was
bending under load as the bracket hangs over the casting cantilever style, I had thought that it might give a little, even though
it was 12mm plate and added another 12mm gusset that extents about halfway along the beam, so the caliper is cantilevered about 30 mm.
 it'll be fine for the cutting forces it will see.

I've ordered two esp32's, the 21 bit magnetic encoder from the video as well as the magnets, I wasn't sure at that
point as to how many I might need so ordered 200 since then I did the math
and I need at most 50.  ::)

What I want to do, is put the encoder wheel inside the casting along with the other electrical components.
For the power supply situation I 3D printed an adaptor for my power tool batteries, 18 volt and this worked  ok
 it gave a little bit better performance, from 22 rpm to 44 rpm with some acceleration
as well I was able to up the drive current to 3.2 amps rms.
 
I connected it and ran a few more Gcode files, and just for drilling and tapping radial holes
it's performance would be ok if a little slow.

This was a shame as I already had the batteries for my power tools, as 3D printing the adaptor worked so well, I ordered
a 36 volt impact driver that comes with two 15000 ma batteries that use the Markita battery pattern, so I'll print an
adaptor for one of those and run the main motor at 36 volt with the leadshine drive and the brake motor at 24 volt using the easy driver board.
I ordered a 2.8 in touch display for a GUI so it can be operated manually.

Dave

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #5 on: November 11, 2025, 12:18:34 pm »
Another small update.
The micro-controllers turn up and I've programmed one as a 4th axis.
I'll get time tomorrow to finish the machining,and to attach the brake servo.
The encoder and magnets haven't arrived yet.
I can't exactly measure the clearance available inside the housing without taking the spindle shaft
out (it has to come out to put the encoder wheel on), the brake motor is a Nema 17 + gearbox 3 N\M
I had to machine the master cylinder and install an outboard pilot bearing to support the shaft.
Dave

Offline Dragonfly

  • CNC Jedi
  • *****
  • Posts: 2680
    • View Profile
Re: positional 4th Axis
« Reply #6 on: November 12, 2025, 16:33:39 pm »
Is this intended to work in conjunction with Mach3? If so, how is the micro-controller communicating with it?

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #7 on: November 13, 2025, 01:48:05 am »
This is how it will operate:
1 Manual using the touch screen. Enter a value hit Move.
2 Connected to one of mach3's rotary Axis A,B,C the usual way with a cable that plugs in.
3 Wireless using one of the flavors of bluetooth.

Option one is mandatory, the word manual has connotations of 'simple' but this is the most
sophisticated mode as it will re-attempt a 'positional move' if the positioning fails, if it cannot
find position it will go through its medic routines, checking sensors, if all else fails it will halt and flag an error.
This method doesn't care what controller is used.

Option two just requires you to plug in the Axis cable, Signal ground, step\dir and brake.
The drilling plugin can be made to generate Gcode for this.
This method also is not dependent on what controller is used.

Option three is bluetooth, they can be BT classic like the turrets, this is very much controller dependent, as it requires a plugin to be written for Mach3.

To get around the controller dependency, I've ordered an extra micro-controller  and will make a port sniffer, this very
much limits the speed of the Axis as its dependent on the available bandwidth.
The abacus tells me about 30 rpm max.

Just right now I've finished the machining for the brake and have bought it inside for testing.
Well version one anyway, I've discovered that the 27 to 1 gearbox is back driveable so must be
energized for the duration of the machining, this is no big deal but wastes energy unnecessarily.

What I wanted to do was use a differential screw or an over center toggle mechanism which
means that the brake can be activated and the motor can be turned off.

I may have to do this in the end but using the present method is quite compact.
I haven't modelled it yet but a snail cam with a dwell might fit without modifying the existing
mechanism, and would allow the motor to be turned off.

This has the benefit of not losing position if the batteries go flat.
I've looked at the schematic and code for the device in the video, and I can't implement FOC
with the Easydrivers that I wanted to because they don't have separate individual pins for current control
of each phase.

Dave

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #8 on: November 15, 2025, 01:48:53 am »
Another small update.
The magnets have turned up but not the encoder or the Impact Gun (so I can use the battery packs)
I set up a series of tests to check the accuracy and repeatability of the Axis when the parts arrive.

I used CB to make a target strip (compensated for being printed on a flat plane rather than a curved one) at 600 mm from the centerline of the chuck and one at 2 meters.

I had ordered a focus-able laser pointer, what turned up was non focus-able so the beam diverged a quite a bit at 2 meters, making the center of the beam had to discern.

What I did was place my drill vice with a piece of sheet metal at the target distance with the thin edge facing the laser beam, which illuminated brightly when hit.
 I wrote a bit of Gcode to cycle through various angles and return to zero.
The motor driver is running at 15 volt and the minimum current so the tests at this point are invalid accuracy and repeatability wise and must be done when the drive is powered correctly.

The only thing I can  determine at this point with some degree of confidence was if the spindle would move as the brake activated.
 
I'm very happy with the brake, at no point did the spindle move while being activated or released.
I accidentally left it on overnight in the activated position (powered up ) and it didn't  move, the driver and motor were luke warm.
 
I would like to leave it in the activated position, brake on, powered off, so will make a friction clamp that can be slid along the mounting post and lock it.

I did a test where I put that half meter shifting spanner in the chuck and slowly let it descend under it's own weight its very nice as there's
no detectable stiction which would cause the load to jump or jerk about. There's lots of resolution too, so if I had a project were I needed to
lower a heavy weight with some delicacy and finesse I wouldn't hesitate to try this.

 As I couldn't do much else until the batteries come I went over to the FOC website and read the manual and looked at the examples, there's one
example using an H bridge which I have and will run at 12 volts where foc can be implemented so I do this for now using the 10 bit encoder to
do the debugging and testing.  They both connect the same way so I swap out the 10 bit for the 21 bit when the batteries come.

Dave

Offline lloydsp

  • CNC Jedi
  • *****
  • Posts: 9079
    • View Profile
Re: positional 4th Axis
« Reply #9 on: November 15, 2025, 12:36:27 pm »
"I would like to leave it in the activated position, brake on, powered off, so will make a friction clamp that can be slid along the mounting post and lock it."
------------------
Be careful of that!  I don't know the alloys or geometries of your brake, but brakes and clutches will often rust-mark their mating surfaces if left engaged for long periods of time without use.  Such a mark can make for VERY rough starts and stops.

Like I said, I don't know the character of your brake, but I'd evaluate it for that potential if I were doing it.

Lloyd
"Pyro for Fun and Profit for More Than Fifty Years"

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #10 on: November 16, 2025, 01:14:41 am »

What I was thinking was, that if I was part way through a job, maybe cutting a gear and
having to stop for the day and turn the axis off and restart it the next day then the axis is
still in a known position, say 90 deg, its important that instead of using the sensor angle,
(it may have auto calibrated) or you calibrated it in your code at startup then the angle
reported from the sensor might not be exactly 90 deg anymore, if the drive is locked up
and cannot move then its prudent to set the angle variable for the axis from your stored
value, and add an offset to the angle variable reported from the sensor on this new startup.

Here's a little bit from the data sheet for the 10 bit encoder.

Quote
The maximum non-linearity error on this example is better than ±1 degree (inner circle) over a misalignment radius of ~0.7mm.
For volume production, the placement tolerance of the IC within the package (±0.235mm) must also be taken into account.
The total nonlinearity error over process tolerances, temperature and a misalignment circle radius of 0.25mm is specified better than ±1.4 degrees.

No good if you're making a gear.

The 21bit encoder turned up.

Even with that encoder, its one thing to measure something, quite another to move a real world object with
mass like a spindle, minuscule amounts.
Its a hard problem.

I don't know what the accuracy or repeatability will be, I don't think it will be extraordinary.

I don't have an independent way to measure the angle with any accuracy so I'm going to cut some facets
on a piece of round and measure them.
   
Dave

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #11 on: November 20, 2025, 23:58:52 pm »
Another small update.

The 36 volt batteries came so I 3D printed a battery mount, they are not too much larger than
the 18 volt ones.
I am worried about the chips or coolant\oil getting to the battery connection so will try to keep
them out with a seal or make a cover for the whole battery mount.

I've ordered a new focus-able laser module with a cross-hair sight.
I'm going to make a module holder that aligns the laser head at the chuck centre line.

I spent many frustrating hours over a couple of days trying to get the FOC lib to compile, I'm glad I stuck with it, as implementing
a simple closed loop system is very easy, I got the H bridge version going first with the Nema 34 stepper motor.

To continue testing I'll 3D print an inset for the spindle shaft with the magnet in it and a metal bracket for the sensor.

 I had the motor rotating about CW/CCW according to the magnet direction using the incremental outputs, this is the simplest
mode where you have to do a bit of housekeeping like remembering the position between uses and have a homing switch for calibration.

The sensor does have some other output options, like an absolute output on the SPI bus which means that you could in theory eliminate the
home switches and remembering the position between sessions would be automatic. The thing is these sensors (the cheap 10 bit one I have) can
drift a little because of the environmental conditions like vibration, temperature, stray magnetic fields.

For that reason alone, I'm going to use a homing switch to help with and double check the calibration.

I did model some covers for the drives, I still like the idea of putting all the electronics in the housing though, the brake motor
driver is small and could be replaced with a step stick style
driver from a 3D printer, the Nema34 requires more current than the smaller drivers can provide       
and I did see a while ago now a shield that had two 5 amp H bridges that will fit inside the housing if it has the same
inputs as the H bridge that I have now I'll get one.

 I'm going to do more testing with the 10 bit encoder before moving on to the 21bit.

Dave

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #12 on: December 05, 2025, 01:24:42 am »
Another small update.

Quote
The 36 volt batteries came so I 3D printed a battery mount, they are not to much larger than
the 18 volt ones.

A bit of foreshadowing there:
As I was checking the polarity of the battery to attach it to the H bridge, I noticed that the voltage was 20.24 volts, at first I thought it
was a dud battery, so got the one of the impact gun, the battery voltage indicator is on the impactor not the battery, and it said full, checking
 that one it was 20.24 volts too, so I checked the charger, and it was outputting 20.24 volts so I've been had, so I did
the tests at 20 volt with the foc lib and 20 volts.

I ran series of tests and the total error for openloop is roughly 0.7 degrees, closed loop
about half that with a hard tune.
I did the tests with the sensor on the spindle and the motor, with the 10 bit encoder.
To account for the encoder being on the spindle in the encoder method you have to divide the PPR by 4 and use that value
else the motor init()  function will complain.

The magnetic encoder needs babysitting as there is an offset at startup, and if I slide a M6 allen key along the back of the
sensor keeper so the distance to the actual sensor is 4 mm, then I can see a one tick rise and fall in it's reported position.

What I determined was that I needed more gear ratio reduction (40:1), so looked at a planetary gearbox, 10 to 1
would be ok as with the pulley ratio of 4:1 this would be 40:1.

but our local stepper on line store only had this series of gearbox EG17-G50  (20 arc\min)
in 50 to 1. They had plenty of the MG series but they have (45 arc\min).

 I've ordered one of those EG17-G50  and have a 20 tooth pulley on hand which makes the mechanical
reduction 6:1 for the pulleys 50:1 for the gearbox, so 300:1. 

This means that 1 revolution of the spindle will take 60 seconds at the motor speed of 300 rpm.
The motor I have is twice the torque rating of the brake motor so I should be able to drive it faster
than 300 rpm, I don't know how much though and will have to determine this with testing.
I will order some drive pulleys (30T\40T )but for now I'll test with what I have.

I didn't get a chance to post this when I wrote it.

Using the Faststepper lib and setting the micro stepping to 2 and using the battery and the Leadshine driver I can
run the motor at 1200 rpm which takes the time per spindle revolution to
15 seconds. Settings in pic.
 I had to back off the Acceleration a fair bit so now it (the gearbox) sounds like a turbine spooling up.

Dave









Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #13 on: December 05, 2025, 01:26:38 am »
continued...

 Running the touch screen and the motor code in the loop function had too much latency so I had to use a timer to get a fixed timing interval. (Foc lib)
A nice thing about the lib is it has a 'Commander' interface which you can setup to change both pid loops in real time.
The lib also lets you make a motor with step and direction inputs so using an external controller is easy.
The con is that it cannot output step and direction.

I couldn't see a definition for the 21 bit endoder in the FOC lib and  have downloaded a lib for that.
I have ran the spindle setup with the FastAccelStepper lib and may use it with the ESP32Enconder lib.
this means that I could use the common step\dir hardware and the encoder lib uses the ESP32 high speed hardware counters.

As an aside there's been a disturbance in the Force over at Arduino and this in some part played a role in getting the foc lib to compile, I do
have Microchip studio and had a look at the STMCube  IDE and will migrate back to those IDE's in case Arduino turns into Autocad.
I did see while looking around that there is an extension for VS Code to program a RP pico 2
in “C” and not Python so will have a look at one of those.

Dave 

Offline dave benson

  • CNC Jedi
  • *****
  • Posts: 1894
    • View Profile
Re: positional 4th Axis
« Reply #14 on: December 15, 2025, 13:39:10 pm »
Another small update.

I've characterised the system, the motor, gearbox and the pulleys and belts at the time of testing.
The motor steps per deg is 333 @ X2 microstepping.  0.0033 deg per step. Mechanical
The incremental outputs from the 21bit encoder are 65535 0.0055 deg per step.
The incremental outputs have less latency.
 
The backlash of the gearbox = 100 steps plus 45 for the elasticity of the belt.

That's a little under half a degree, so if you do nothing about the backlash and run in open loop mode, the repeatability
and accuracy is mediocre at best.

There are things you can do, one being closed loop control, the most common one is a PID loop
where you have an encoder attached to a motor, it's not the only method there's plenty of others.
For this particular case I'm going to use a Hybrid system of open loop and closed loop without pid
to get to the target position.

The control scheme goes like this, the target angle is sent to the controller from the touch screen
the spindle rotates to the computed angle in open loop mode at worst you could be 145 steps out
once the spindle gets to the computed target angle it checks the actual position compared to the computed position and
uses a closed loop park routine to go to final position.
Once at the target the brake is energised to hold position.

I've tested this with both the stepper types of motor drivers and the H-bridge using a few different libs and have chosen the fastaccelstepper lib
and a encoder lib, the leadshine drive outperformed
the others on the spindle drive, for the brake I'll use one of the DRV8825 modules which I have and am waiting on the carrier board.
I 'm fixated on putting the electronics in the main housing and if the DRV8825 can drive the spindle 
as well as the leadshine drive I'll use one of those.

During part of the debugging and testing, I printed a target for 3200 mm and using the old unfocused laser.
At that distance it's easy to see if there are any small changes in the repeatability.

The first pic is of the belt which came apart as I tried to hold the spindle back to load the backlash all one way.
The plan was to use the belt I used for the laser build (steel re-enforced white in colour)  haven't been able to find them and my
local industrial supplies place only had XL and HDT types.
At the moment the belt is acting like spring, I'll keep looking.
 
The other photos are of the laser dot projected at 3.2 mts.  The pics are not very good as I had to make the half their size to fit in a zip file.

At the moment the drive will park successfully at all the encoder ticks no dithering and no deadband.

Once I've got the unit together, I'll test it further with the focusable laser in the shop at 10 mts.
And take better pics.
Edit to add pic
Dave
« Last Edit: December 15, 2025, 14:15:13 pm by dave benson »