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
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

Group

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.

Parameters
  • axis (int) – axis number

  • motor (Motor) – motor details

save_hi_limits()[source]

Generate a command string for saving all axes high limits

restore_hi_limits()[source]

Generate a command string for restoring all axes high limits

save_lo_limits()[source]

Generate a command string for saving all axes low limits

restore_lo_limits()[source]

Generate a command string for restoring all axes low limits

save_homed()[source]

Generate a command string for saving all axes homed state

save_not_homed()[source]

Generate a command string for saving the inverse of all axes homed state

restore_homed()[source]

Generate a command string for restoring all axes homed state

save_limit_flags()[source]

Generate a command string for saving all axes limit flags

restore_limit_flags()[source]

Generate a command string for restoring all axes limit flags

save_position()[source]

Generate a command string for saving all axes positions

clear_limits()[source]

Generate a command string for clearing all axes limits

stop_motors()[source]

Generate a command string for stopping all axes

are_homed_flags_zero()[source]

Generate a command string for checking if all axes homed=0

are_homed_flags_zero_brick() str[source]

Generate a command string for all axes in the plc which have macros: zero the homed flag (brick specific)

Returns

the resulting command string

Return type

str

has_motors_with_macro_brick() bool[source]

Check if any of the motors in the plc has macros (brick specific)

Returns

returns true is any of the motors in the plc have defined macro (brick specific)

Return type

bool

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

str

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

str

macro_station_brick() int[source]

Return or calculate macro station number. Brick specific calculation

Returns

brick specific macro station number

Return type

int

property post_home_distance: str

Generate a post distance string

Returns

post distance string, “*” if post distance is 0

Return type

str

property post_home_with_distance: str

Generate one string which contains the post home move with distance (if applicable) for this motor.

Returns

one string describing the post home move for this motor.

Return type

str

has_macro_station_brick() bool[source]

” Check if the motor has macro station defined (brick only)

Returns

true if macro station defined for the motor

Return type

bool

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

Motor

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()

Parameters

axes (List[int]) – List of axis numbers to be controlled in this context

Returns

Blank string. Required because this function is used as a callback

from a jinja template and thus must return some string to insert into the template

Return type

str

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()

Parameters

cmd (str) – Any string

Returns

the passed string (for jinja rendering)

Return type

str

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()

Parameters
  • function (Callable) – the function to call

  • args (Dict[str, Any]) – arguments to pass to function

Returns

The string to insert into the PLC output file

Return type

str

jog_stopped() str[source]

Generate a command string that will jog any stopped axes in the group

jog_axes() str[source]

Generate a command string for all group axes: jog a set distance

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

homed(value=0) str[source]

Generate a command string for all group axes: check homed

clear_home() str[source]

Generate a command string for all group axes: clear home flag

store_position_diff()[source]

Generate a command string for all group axes: save position

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

negate_home_flags()[source]

Generate a command string for all group axes: invert homing flags

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

home() str[source]

Generate a command string for all group axes: home command

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

static filter_motors_with_macro(motor) bool[source]

Check if motor (on a brick) has macro.

Parameters

motor (Motor) – motor being checked

Returns

true if the motor has macro (brick only)

Return type

bool

static filter_motors_without_macro(motor) bool[source]

Check if motor (on a brick) doesn’t have a macro.

Parameters

motor (Motor) – motor being checked

Returns

true if the motor doesn’t have macro (brick only)

Return type

bool

has_motors_with_macro_brick() bool[source]

Check if any of the motors in the group has macros (brick specific)

Returns

returns true is any of the motors in the group have defined macro (brick specific)

Return type

bool

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

Parameters
  • group (Group) – The parent group context

  • axes (List[int]) – The subset of axes from the parent to enable

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 = “”