Back to top

KAS PLCopen Teach Home for absolute feedback devices

This article and attached sample KAS project show how to use PLCopen function blocks to teach a position so that an axis with an absolute feedback device will not need to run a home routine to move to a sensor or hard stop each time you power up a machine. In this example, Axis1 does not have rollover turned on so it would be a good example for a motor with a multi-turn absolute feedback device with linear mechanics connected to it. Axis2 does have rollover turned on so it is representative of how you could setup an axis with a single turn absolute feedback device with rotary mechanics attached. With this method, you do not have to set AKD parameters such as FB1.OFFSET and instead set and apply an offset in your PLC/motion control program as a retained variable stored in NVRAM so it will be saved through a power cycle. All of the code shown below is contained in the Main program of the attached KAS project in Networks 5 and 6.

First we will go through the first case that requires less coding for Axis1 that does not have rollover. The first step is to move the axis into the desired home or zero position and to press the button on the Control Panel to Teach Home on Axis1. This will save the raw position feedback value to be stored in a retain variable called OffsetAxis1. We use the MC_ReadParam function block to check parameter 1007 or the raw feedback position directly from the drive over EtherCAT that is then converted into user units. No offsets are applied to this value, which is how it differs from the output of the MC_ReadActPos function block and we use it in case a user wants to teach or change the home position multiple times. By looking at the raw feedback position without any offsets we do not have to worry about summing multiple offsets together.

image

The next step is in Network 6 is to call the MC_SetPos function block for Axis1 to apply an offset so the current position is reported as a new absolute position. This position is calculated by taking the different of the raw position feedback and the offset that was saved earlier. This function block is called automatically when the EtherCAT network first starts up through the bMotionEngine started variable, and again each time a new home position is taught.

image

There are a few extra steps for Axis2 because rollover is turned on. Just as with Axis1, we will use the MC_ReadParam to read the raw feedback postion, but also parameter 1008 which is the rollover position specified for this axis. We could have just hard coded in 360 as this is the value we enter for Axis2 rollover, but there might be programs where this value can change depending on the mechanics attached so we will be safe and use the function block to read the value.

image

Since rollover is turned on for Axis2, we do not want to save the raw feedback of Axis2 directly when the teach home button is pressed. The raw feedback value will be put into user units, but rollover is not applied. We use the modLR to convert this raw feedback into the corresponding position with rollover applied. This is the equivalent of taking the remainder of dividing the raw feedback value by the rollover amount of 360. This value which will always be between 0 and 360 is what we will save in the retain variable as an offset for Axis2.

image

There is extra code required for the axis with rollover that has to be run before we can call the MC_SetPos function block to set a new absolute position. When we subtract the saved offset from the current position, we may have either a negative number or a number greater than the rollover value (if the offset was negative) which we must account for or else the MC_SetPos function will have an error. The below code checks for these conditions and will convert the desired absolute position to be between zero and the rollover value (0 and 360 for this example).

image

Finally, with a converted offset that we can guarantee is between 0 and the rollover value we can call MC_SetPos automatically whenever the EtherCAT network first starts or after the teach home button is pressed.

image

Other things to consider is that the code for Axis1 will not work with single turn absolute feedback devices. After a power cycle any motion of multiple revolutions will be lost so if you have linear mechanics you will need to implement a traditional home routine to move to a sensor or hard stop. Additionally, if the range of the linear mechanics take over 4096 motor revolutions to travel then you will not be able to use these "no movement" home routines as our multi-turn feedback devices have a limit and can only keep track of up to 4096 revolutions before that count rolls over. Another issue exists if people are using gearboxes with multi-turn feedback devices that do not divide evenly into 4096 (which would be pure multiples of 2). For example, if you had a 10 to 1 gearbox on a rotary axis that could goes in a single direction indefinitely, you will not reliably know where the axis is after a power cycle because 4096/10 is not a whole number so the feedback device and the output shaft of the gearbox will rollover at different times.