Adding Functionality

Audience

This section is for developers who want to add homing procedures that require changes to the code. Note that many custom homing sequences may be achieved by simply recombining the existing snippets and this would not require code changes to this library.

For an overview of how the following work together see How it Works

Adding a New Homing Sequence Function

TODO - flesh this out

A nice example is home_slits_hsw

def home_slits_hsw(posx, negx, posy, negy):
    """
    A special seqence for two pairs of slits in which the vertical and horizontal
    pairs may collide with each other at the extreme of their homing direction.

    - move all axes to the limit away from their homing direction
    - home both positive axes using home switch or mark
    - move the positive axes out of the way
    - home both negative axes using home switch or mark
    - move the negative axes out of the way

    Args:
        posx (int): axis number of the positive horizontal motor
        negx (int): axis number of the negative horizontal motor
        posy (int): axis number of the positive vertical motor
        negy (int): axis number of the negative vertical motor
    """
    drive_to_limit(homing_direction=False)

    with only_axes(posx, posy):
        home_hsw()
        drive_to_limit(homing_direction=False)
    with only_axes(negx, negy):
        home_hsw()
        drive_to_limit(homing_direction=False)

Adding a New Snippet Template

TODO - flesh this out

  • write the Jinja template

  • add a snippet command to snippets.py using _snippet_function decorator

The decorator _snippet function allows you to declare a function whose name is the same as the Jinja template file prefix. This function need only have arguments and a docstring. The decorator will provide the rest as follows:

pmac_motorhome.snippets._snippet_function(*arglists: Dict[str, Any]) Callable[[pmac_motorhome.snippets.F], pmac_motorhome.snippets.F][source]

A decorator function to allow simple declaration of snippet functions. Snippet functions are used to append snippets of Jinja PLC code to the current PLC.

The decorated function should have:

  • the same name as a jinja template file (less .pmc.jinja) in the folder pmac_motorhome/snippets. The function should take

  • Type hinted parameters that the template will use

  • A docstring that describes the function of the snippet

The snippet may itself include further snippets and if this is the case any argument lists required by further snippets should be passed to the decorator. The only example of this at present is wait_for_done_args.

The decorator adds the following to the decorated function:

  • code to check parameters passed at runtime

  • code to implement appending the template with parameters

  • appends the original Jinja to the docstring

  • appends a description of parameters to the wait_for_done template if wait_for_done_args was passed to the decorator

Adding a New Callback Function

TODO - flesh this out

  • add the function to Plc or Group

  • use the all_axes function to generate axis commands

  • or output arbitrary text