Internal Documentation
Documentation for maintainers.
Classes
- class pmac_motorhome.plc.Plc(plc_num: int, controller: pmac_motorhome.constants.ControllerType, filepath: pathlib.Path, timeout: int = 600000, post: str = '', post_home: pmac_motorhome.constants.PostHomeMove = PostHomeMove.none, post_distance: int = 0)[source]
This class is used in a PLC definition to declare that a PLC is to be generated.
Should always be instantiated using
pmac_motorhome.commands.plc
- Parameters
plc_num (int) – The PLC number to use in generated code
controller (ControllerType) – Target controller type for the code
filepath (pathlib.Path) – Output file to receive the generated code
timeout (int) – Timeout for the plc - default 600000ms (10min).
post (str) – some raw PLC code to insert at the end of a group
post_home (PostHomeMove) – action to perform on all axes after the home sequence completes
post_distance (int) – A distance to use in post_home if required
- Raises
ValueError – Invalid output file name
ValueError – Invalid PLC number supplied
- classmethod instance() pmac_motorhome.plc.Plc [source]
Get the current in-scope PLC.
- classmethod add_group(group_num: int, post_home: pmac_motorhome.constants.PostHomeMove, post_distance: int, comment: str = '', pre: str = '', post: str = '') pmac_motorhome.group.Group [source]
Add a new group of axes to the current Plc
- Parameters
group_num (int) – A Unique group number (1 is reserved for ‘All Groups’)
post_home (PostHomeMove) – A post home action to perform on success
post_distance (int) – A distance for those post home actions which require it
comment (str) – Add a group comment to the top of the Plc code
pre (str) – some raw PLC code to insert at the start of a group
post (str) – some raw PLC code to insert at the end of a group
- Returns
The newly created Group
- Return type
- classmethod add_motor(axis: int, motor: pmac_motorhome.motor.Motor)[source]
Add a motor to the PLC. The Plc object collects all the motors in all of its groups for use in the Plc callback functions.
- class pmac_motorhome.motor.Motor(axis: int, jdist: int, plc_num: int, post_home: pmac_motorhome.constants.PostHomeMove = PostHomeMove.none, post_distance: int = 0, index: int = - 1, ms: int = - 1)[source]
Declares a motor for use in homing routines in the enclosing Group, Plc
Should always be instantiated using
pmac_motorhome.commands.motor
- Parameters
axis (int) – Axis number of the motor
jdist (int) – Distance in counts to jog after finding the home mark this should be enough distance to move clear of the home mark
plc_num (int) – the plc number of the enclosing Plc
post_home (PostHomeMove) – the action to perform on this motor when homing is complete
post_distance (int) – A distance to use in post_home
index (int) – for internal use in conversion of old scripts sets the index of this motor to a different value than the order of declaration.
ms (int) – macrostation number
- classmethod get_motor(axis: int, jdist: int, plc_num: int, post_home: pmac_motorhome.constants.PostHomeMove = PostHomeMove.none, post_distance: int = 0, index: int = - 1, ms: int = - 1) pmac_motorhome.motor.Motor [source]
A factory function to return a Motor object but ensure that there is only ever one instance of each axis number. This is required since PLC code allocates p variables on a per axis basis.
- property macro_station: str
Calculate macro and generate a command string for this motor Pmac specific command string
- Returns
pmac specific ms command string
- Return type
- property macro_station_brick_str: str
Generate a command string for this motor Brick specific command string
- Returns
brick specific ms command string
- Return type
- macro_station_brick() int [source]
Return or calculate macro station number. Brick specific calculation
- Returns
brick specific macro station number
- Return type
- property post_home_distance: str
Generate a post distance string
- Returns
post distance string, “*” if post distance is 0
- Return type
- class pmac_motorhome.group.Group(group_num, plc_num, controller, post_home: pmac_motorhome.constants.PostHomeMove = PostHomeMove.none, post_distance: int = 0, comment=None, pre='', post='')[source]
Defines a group of axes to be homed as a unit
Should always be instantiated using
pmac_motorhome.commands.group
- Parameters
group_num (int) – A unique number to represent this group within its Plc. group 1 is reservered for ‘all groups’
axes (List[Motor]) – A list of axis numbers that this group will control
plc_num (int) – The plc number of the enclosing Plc
controller (ControllerType) – Enum representing the type of motor controller
post_home (PostHomeMove) – action to perform on all axes after the home sequence completes
post_distance (int) – A distance to use in post_home if required
comment (str) – [description]. A comment to place in the output Plc code at the beginning of this group’s definition
pre (str) – some raw PLC code to insert at the start of a group
post (str) – some raw PLC code to insert at the end of a group
- classmethod add_motor(axis: int, jdist: int, index: int, post_home: pmac_motorhome.constants.PostHomeMove, post_distance: int, enc_axes: List, ms: int) pmac_motorhome.motor.Motor [source]
Add a new motor to the current group
- Parameters
axis (int) – Axis number
jdist (int) – distance to jog to move off of home mark
index (int) – internal use
post_home (PostHomeMove) – action to perform on all axes after the home sequence completes
post_distance (int) – A distance to use in post_home if required
enc_axes (list) – List of additional encoders that need zeroing on homing completion
ms (int) – macrostation number
- Returns
The newly created Motor
- Return type
- classmethod instance() pmac_motorhome.group.Group [source]
Get the current in-scope Group
- classmethod add_comment(htype: str) None [source]
Add a group comment to the top of the Plc code in the style of the original motorhome.py module but note that you can use any descriptive text for htype
- Parameters
htype (str) – Homing sequence type e.g. RLIM HSW etc.
- classmethod add_snippet(template_name: str, **args)[source]
Add a jinja snippet to the list of snippets to be rendered
- Parameters
template_name (str) – prefix of the jinja template’s filename ‘.pmc.jinja’ is added to this name and the template file should be in pmac_motorhome/snippets
- classmethod add_action(func: Callable, **args)[source]
Add a callback to the list of ‘snippets’ to be rendered The callback function should return an string to be inserted into the rendered template
- Parameters
func (Callable) – the function to call
args (dict) – arguments to pass to func
- set_axis_filter(axes: List[int]) str [source]
A callback function to set group actions to only act on a subset of the group’s axes.
Will be called back during the rendering of plc.pmc.jinja, and is inserted using Group.add_action()
- all_motors_have_same_post_move_type() Tuple[bool, pmac_motorhome.constants.PostHomeMove] [source]
Check that all motors in the group have the same post move type
- command(cmd: str) str [source]
A callback function to insert arbitrarty text into the ouput Plc code.
Will be called back during the rendering of plc.pmc.jinja, and is inserted using Group.add_action()
- callback(function: Callable, args: Dict[str, Any]) str [source]
Callback from plc.pmc.jinja to a function that was added into the group using
add_action()
- set_large_jog_distance(homing_direction: bool = True) str [source]
Generate a command string for all group axes: set large jog distance
- jog(homing_direction: bool = True) str [source]
Generate a command string for all group axes: jog indefinitely
- in_pos(operator='&', relOperator='==', value=0) str [source]
Generate a command string for all group axes: check in postiion relOperator (relationalOperator) is required for power pmac based controllers as each variable needs to be evaluated separately
- limits(relOperator='!=', value=0) str [source]
Generate a command string for all group axes: check limits relOperator (relationalOperator) is required for power pmac based controllers as each variable needs to be evaluated separately
- following_err(relOperator='==', value=0) str [source]
Generate a command string for all group axes: check following error
- stored_pos_to_jogdistance()[source]
Generate a command string for all group axes: calculate jog distance to return to pre homed position
- stored_limit_to_jogdistance(homing_direction=True)[source]
Generate a command string for all group axes: save distance to limit
- jog_distance()[source]
Generate a command string for all group axes: jog to prejog position. Useful if a program has been aborted in the middle of a move, because it will move the motor to the programmed move end position
- restore_home_flags()[source]
Generate a command string for all group axes: restore original homing flags
- jog_to_home_jdist()[source]
Generate a command string for all group axes: jog to home and then move jdist
- set_home(encoder=False) str [source]
Generate a command string for all group axes: set current position as home
- restore_limit_flags()[source]
Generate a command string for all group axes: restore original limit flags
- overwrite_inverse_flags()[source]
Generate a command string for all group axes: reuse the not homed store to store ?? (TODO what is this doing ?)
- set_inpos_trigger(value: int)[source]
Generate a command string for all group axes: set the inpos trigger ixx97
- class pmac_motorhome.onlyaxes.OnlyAxes(*axes)[source]
Sets the current axis filter applied to the current group
Should always be instantiated using
pmac_motorhome.commands.only_axes
- class pmac_motorhome.template.Template(jinja_file: Optional[str], args: Dict[str, Any], function: Optional[Callable], custom_text: str = '')[source]
A dataclass for holding details of a jinja template to render into the PLC code.
As the Plc object is being evaluated a list of these is build up. It is then used at render time to insert snippets with arguments into the rendered code.
May also represent a callback function to be called from the root plc.pmc.jinja.
- Parameters
jinja_file (str) – the prefix of the jinja template file name
args (Dict[str, Any]) – arguments to pass to the template if jinja file is not None, or to pass to the function if function is not None
function – (Callable): if not None then this is a callback function to call instead of inserting a jinja template snippet
custom_text – str = “”