Yes, I have written several of them on the Machsupport.com site, under forum.
Others have also posted up code for various machines, take a look there, you will find what you need.
You will need to look at how your ATC is indexing its tool, i.e. there is a main Home switch for the turret, and/or it reads a "serial" indexing code per tool slot, etc.
is your turret single direction, meaning that it has a forward ratched, that goes past the tool index, then move back into position, a "Locking pawl" or something locks it then it stops rolling back. Also, if you have Stepper/servo control of the axis, you can measure the "Back Track" amount in degrees, and then just have it index backward that number of degrees to bring it into lock position.
I rarely check here, so if you have other questions, post them on the Support forum.