Hi, I wrote the carousel routine as an o-sub, but not the axis motion to go with it yet. Someone else here has done the motion and limit swapping parts. The code is on a drive that was in the machine, but I currently can't go fetch it. It may be posted somewhere in the "tc229 adventure" thread but I'm not sure. I think it was "icebear" that did it.
I can explain how it works roughly from memory.
As you can see in the o-sub I created some variables to read and write: I read the 5 encoder tracks on inputs, and I write to outputs controlling the "brake pack" running the atc motor which I think is direction and on/off. turning it off immediately shorts to a resistor, hence the "brake".
The encoder is 4 bit BCD format, so you add those up to know what pocket you are on.
The basic procedure is:
1 - read encoder position
2 - determine the shortest path to the new tool
3 - spin the carousel in that direction
4 - *count* the deceleration track (one count, is one pocket position)
5 - when you get to the right pocket, read the deceleration track again, then wait (in my case) 200ms, and then hit the brakes.
6 - read the encoder position to make sure you have actually landed in the right spot. You will need to play with brake timing to get it to stop in just the right position.
I put a lot of error handling in to make sure nothing would move unless you were on the right tool, in position on the upper limits, etc.
BEFORE this code, you need to add code that swaps the limits form the lower to the upper, then moves the Z up to the first limit, orients the spindle, then moves up to the top "atc" limit.
Then AFTER my code you move back down to the lower limit, and swap the limits back to normal, and then resume the main program.
This gets a basic reliable operation. Fancier modes of operation I want to implement are single motion (orient on the way up as a coordinated A axis), and repositioning the table during the carousel motion.