90 lines
3.5 KiB
Markdown
90 lines
3.5 KiB
Markdown
# ecmc_master_slave
|
|
Standard syncronization scripts for ecmc. The module provides:
|
|
* Syncronization scripts
|
|
* Generic state machine
|
|
|
|
## Syncronization scripts
|
|
Syncronazation can be done both by defining the forward adn inverse kinematcis as equations or by matrices.
|
|
|
|
The module implement 5 generic syncronazation scripts based on the matrix approach:
|
|
* axis_kin_2DoF.plc_inc : Kinematics for a 2 Dof system (slits)
|
|
* axis_kin_3DoF.plc_inc : Kinematics for a 3 Dof system
|
|
* axis_kin_4DoF.plc_inc : Kinematics for a 4 Dof system
|
|
* axis_kin_5DoF.plc_inc : Kinematics for a 5 Dof system
|
|
* axis_kin_6DoF.plc_inc : Kinematics for a 6 Dof system
|
|
|
|
and 2 dedicated:
|
|
* axis_kin_slit.plc_inc : Dedicated script for a slit system based on equations (including interlocks and softlimits)
|
|
* axis_kin_mirror.plc_inc : Dedicated script for a 5 DoF mirror system based on matrices
|
|
|
|
### Generic scripts (axis_kin_\<index\>DoF.plc_inc)
|
|
|
|
The generic scripts needs a few macros:
|
|
* AX_S\<index\> : Axis index for slave axes, index = 1..DoF
|
|
* AX_M\<index\> : Axis index for master axes, index = 1..DoF
|
|
* FWD\<index\> : Forward kinematics array, index = 1..DoF
|
|
* INV\<index\> : Inverse kinematics array, index = 1..DoF
|
|
|
|
## State machine
|
|
The state machine makes sure that master and slaved axes cannot run simultaneous. However, several master axes or several slave axes can run at the same time.
|
|
The state machine is implemented in the file axis_sm.plc.inc in this module.
|
|
|
|
The state machine needs two macros:
|
|
* GRP_ID_MA : Group id for master axes (most often virtual axes)
|
|
* GRP_ID_SA : Group id for slave axes (most often real axes)
|
|
|
|
The easiest way to create a group is to just add it in the axis yaml configuration:
|
|
```
|
|
axis:
|
|
id: 5
|
|
group: realAxes
|
|
```
|
|
|
|
If the group does not exist, it will be created. The id of the group will be accessible through the environment variable "GRP_\<group_name\>_ID", in this case "GRP_realAxes_ID".
|
|
This macro can the be used when loading the PLC-code.
|
|
|
|
## Using the scripts
|
|
The easiest way is to generate a main plc file and then use include to access the kinematic and state machine scripts.
|
|
|
|
Example for a slit system:
|
|
```
|
|
/* Forward kinematics to calculate virtual axes from real axes
|
|
| CEN | = FWD * | S1_LO |
|
|
| GAP | | S2_HI |
|
|
|
|
Equations:
|
|
ax{AX_CEN}.enc.actpos:=(ax{AX_LO}.enc.actpos+ax{AX_HI}.enc.actpos)/2;
|
|
ax{AX_GAP}.enc.actpos:=ax{AX_HI}.enc.actpos-ax{AX_LO}.enc.actpos;
|
|
*/
|
|
var FWD1[2] := {0.5, 0.5};
|
|
var FWD2[2] := { -1, 1 };
|
|
|
|
/* Inverse kinematics to calculate real axes from virtal axes
|
|
| S1_LO | = INV * | CEN |
|
|
| S2_HI | | GAP |
|
|
|
|
Equations:
|
|
ax{AX_LO}.traj.extsetpos:=ax{AX_CEN}.traj.setpos-ax{AX_GAP}.traj.setpos/2;
|
|
ax{AX_HI}.traj.extsetpos:=ax{AX_CEN}.traj.setpos+ax{AX_GAP}.traj.setpos/2;
|
|
*/
|
|
var INV1[2] := { 1, -0.5};
|
|
var INV2[2] := { 1, 0.5};
|
|
|
|
# Kinematics for slit system.
|
|
include "axis_kin_2DoF.plc_inc"
|
|
|
|
# State machine
|
|
include "axis_sm.plc_inc"
|
|
```
|
|
|
|
The main plc file can then be loaded into ecmc with appropriate macros (also not the INC):
|
|
```
|
|
${SCRIPTEXEC} ${ecmccfg_DIR}loadPLCFile.cmd, "FILE=./cfg/axis_main.plc, PLC_ID=1, INC=.:${ecmc_master_slave_DIR}, PLC_MACROS='PLC_ID=1, AX_M1=12, AX_M2=13, AX_S1=5, AX_S2=6, GRP_ID_SA=${GRP_realAxes_ID}, GRP_ID_MA=${GRP_virtualAxes_ID}'"
|
|
```
|
|
NOTE: Macros cannot not be used in the include statement. The path to this module needs to set in the INC parameter to loadPLCFile.cmd
|
|
|
|
## Examples
|
|
See examples dir for usage:
|
|
* slits (equations, 2DoFs matrix)
|
|
* mirror (matrix)
|