Snippet Functions
All of these functions will insert a small snippet of PLC code into the generated PLC. Each snippet performs a specific action on all of the axes in a group simultaneously.
These functions can all be called directly from Homing PLC definition file. They should be called in the context of a Group object.
- pmac_motorhome.snippets.wait_for_done_args = {'no_following_err': False, 'wait_for_one_motor': False, 'with_limits': False}
A set of arguments to pass to the wait_for_done function
- pmac_motorhome.snippets.F
A type to represent a callable function
alias of TypeVar(‘F’, bound=
Callable
)
- pmac_motorhome.snippets.drive_to_limit(state='PreHomeMove', homing_direction=False, **kwargs)[source]
Jog all of the group’s axes until they have each hit a limit
- Parameters
This will cause the jinja template drive_to_limit.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} ;---- {{template.args.state}} State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=State{{template.args.state}} ; Execute the move commands {{ group.pre if template.args.state == "PreHomeMove" -}} {{ group.set_large_jog_distance(homing_direction=template.args.homing_direction) }} cmd "{{ group.jog_axes() }}" {% include "wait_for_done.pmc.jinja" %} endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.drive_off_home(state='FastRetrace', homing_direction=False, with_limits=True, **kwargs)[source]
Jog all the group’s axes until the home flag is released
- Parameters
This will cause the jinja template drive_off_home.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} {# Invert the homing flags and the jog until the inverse of the home flag triggers. e.g. for an axis that is home on release of limit this would drive onto the limit #} ;---- {{template.args.state}} State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=State{{template.args.state}} ; Execute the move commands {{ group.negate_home_flags() }} {{ group.set_large_jog_distance(homing_direction=template.args.homing_direction) }} cmd "{{ group.jog_to_home_jdist() }}" {% include "wait_for_done.pmc.jinja" %} endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.store_position_diff()[source]
Save the current offset from the original position.
This is only required in order to support driving back to initial position after the home operation is complete
This will cause the jinja template store_position_diff.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
;---- Store the difference between current pos and start pos ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) {{ group.store_position_diff() }} endif
- pmac_motorhome.snippets.drive_to_home(state='PreHomeMove', homing_direction=False, restore_homed_flags=False, **kwargs)[source]
Drive all axes in the group until they hit the home flag or a limit
- Parameters
state (str) – Which homing state to report to EPICS for monitoring
homing_direction (bool) – When True Jog in the same direction as each axis’ homing direction, defaults False: opposite to homing direction
restore_homed_flags (bool) – restore the home flags original state before starting. Required if a previous step changed the home flags
This will cause the jinja template drive_to_home.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} ;---- {{template.args.state}} State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=State{{template.args.state}} ; Execute the move commands {{ group.pre if template.args.state == "PreHomeMove" }} {% if template.args.restore_homed_flags %} {{ group.restore_home_flags() }} {{ group.set_large_jog_distance(homing_direction=template.args.homing_direction) }} {% else %} {{ group.set_large_jog_distance(homing_direction=template.args.homing_direction) }} {% endif %} cmd "{{ group.jog_to_home_jdist() }}" {% include "wait_for_done.pmc.jinja" %} endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.drive_to_hstop(state='PreHomeMove', homing_direction=False, no_following_err=True, **kwargs)[source]
Drive all axes in the group until they hit the hard stop (following error)
- Parameters
This will cause the jinja template drive_to_hstop.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} ;---- {{template.args.state}} State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=State{{template.args.state}} ; Execute the move commands {{ group.set_inpos_trigger(3) }}; in-position trigger on following error {{- group.pre if template.args.state == "PreHomeMove" }} {{ group.set_large_jog_distance(homing_direction=template.args.homing_direction) }} cmd "{{ group.jog_to_home_jdist() }}" {% include "wait_for_done.pmc.jinja" %} {{ group.set_inpos_trigger(0) }}; in-position trigger on hardware capture endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.home(with_limits=True, **kwargs)[source]
Initiate the home command on all axes in the group
- Parameters
with_limits (bool) – check for limits during the move
This will cause the jinja template home.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} ;---- Homing State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=StateHoming ; Execute the move commands {{ group.restore_home_flags() }} cmd "{{ group.home() }}" {% include "wait_for_done.pmc.jinja" %} endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.debug_pause()[source]
When running in debug mode, pause until the user indicates to continue
This will cause the jinja template debug_pause.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
; Wait for user to tell us to continue if in debug if (HomingStatus = StatusDebugHoming) HomingStatus = StatusPaused while (HomingStatus = StatusPaused) endw endif
- pmac_motorhome.snippets.drive_to_initial_pos(with_limits=True, **kwargs)[source]
Return all axes in the group to their original positions before the homing sequence began. Requires that store_position_diff was called before home.
- Parameters
with_limits (bool) – check for limits during the move
This will cause the jinja template drive_to_initial_pos.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} ;---- PostHomeMove State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=StatePostHomeMove ; Execute the move commands {{ group.stored_pos_to_jogdistance() }} cmd "{{ group.jog_distance() }}" {% include "wait_for_done.pmc.jinja" %} {% if group.post and group.post != "" %} if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) {{ group.post }} endif {% endif %} endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.drive_to_soft_limit(homing_direction=False, with_limits=True, **kwargs)[source]
Drive all axes in the group until they hit their soft limits
- Parameters
This will cause the jinja template drive_to_soft_limit.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} ;---- PostHomeMove State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=StatePostHomeMove ; Execute the move commands {{ group.stored_limit_to_jogdistance(homing_direction=template.args.homing_direction) }} cmd "{{ group.jog_distance() }}" {% include "wait_for_done.pmc.jinja" %} {% if group.post and group.post != "" %} if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) {{ group.post }} endif {% endif %} endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.drive_relative(set_home=False, with_limits=True, **kwargs)[source]
Drive all axes in the group a relative distance from current position
- Parameters
This will cause the jinja template drive_relative.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} ;---- PostHomeMove State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=StatePostHomeMove ; Execute the move commands cmd "{{ group.jog_distance() }}" {% include "wait_for_done.pmc.jinja" %} {% if group.post and group.post != "" %} if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) {{ group.post}} endif {% endif %} endif {% if template.args.set_home %} ;---- Make current position zero ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) cmd "{{ group.set_home() }}" endif {% endif %}
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.zero_encoders()[source]
Zero an associated encoders
This will cause the jinja template zero_encoders.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% if group.has_encoders %} ;---- Zero encoder channels ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) cmd "{{ group.set_home(encoder=True) }}" endif {% endif %}
- pmac_motorhome.snippets.check_homed()[source]
Verfiy that all axes in the group are homed. Set error condition if not.
This will cause the jinja template check_homed.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
;---- Check if all motors have homed ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) and ({{ group.homed() }}=0) HomingStatus=StatusIncomplete endif
- pmac_motorhome.snippets.drive_to_home_if_on_limit(homing_direction=False, **kwargs)[source]
Drive axes to the home mark or switch. Only perform this action on axes that are currently on a limit.
- Parameters
homing_direction (bool) – When True Jog in the same direction as each axis’ homing direction, defaults False: opposite to homing direction
This will cause the jinja template drive_to_home_if_on_limit.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{# TODO #}
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.disable_limits()[source]
Disable the soft limits on all axes in the group
This will cause the jinja template disable_limits.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
;---- Check if any limits need disabling ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) ;Save the user home flags to P variables px52..x67 ;NOTE: this overwrites inverse flag (ran out of P vars), so can't use inverse flag after this point {{ group.overwrite_inverse_flags() }} {% for axis in group.motors -%} {% include 'disable_axis_limits.pmc.jinja' -%} {% endfor %} endif
- pmac_motorhome.snippets.restore_limits()[source]
Restore the saved soft limits on all axes on the group. By default the Plc will always record the soft limits of all axes at the start.
This will cause the jinja template restore_limits.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
;---- Restore limits if needed ---- ;Restore the limit flags to P variables px68..x83 {{ group.restore_limit_flags() }}
- pmac_motorhome.snippets.drive_to_hard_limit(state='PostHomeMove', homing_direction=False, **kwargs)[source]
Drive all axes until they hit a hard limit.
- Parameters
This will cause the jinja template drive_to_hard_limit.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% include "debug_pause.pmc.jinja" %} ;---- {{template.args.state}} State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=State{{template.args.state}} ; Execute the move commands cmd "{{ group.jog(homing_direction=template.args.homing_direction) }}" {% include "wait_for_done.pmc.jinja" %} {% if group.post and group.post != "" %} if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) {{ group.post }} endif {% endif %} endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.jog_if_on_limit(homing_direction=False, with_limits=True, **kwargs)[source]
Jog all axes in the group that are currently on a limit
- Parameters
homing_direction (bool) – When True Jog in the same direction as each axis’ homing direction, defaults False: opposite to homing direction
This will cause the jinja template jog_if_on_limit.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
;---- Check if HSW_HLIM missed home mark and hit a limit ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) ; Execute the move commands if on a limit {%- for motor in group.motors %} {{- group.set_axis_filter([motor.axis]) }} if ({{ group.limits() }}=1) {{ group.set_large_jog_distance(homing_direction=template.args.homing_direction) }} cmd "{{ group.jog_to_home_jdist() }}" endif {%- endfor %} {{- group.set_axis_filter([]) }} {# a unique variant of wait for done #} ; Wait for the move to complete timer = 20 MilliSeconds ; Small delay to start moving while (timer > 0) endw timer = {{ plc.timeout }} MilliSeconds ; Now start checking the conditions while ({{ group.in_pos() }}=0) ; At least one motor should not be In Position and ({{ group.following_err() }} = 0) ; Following error check and ({{ group.limits() }}=0) ; Should not stop on position limit for selected motors and (timer > 0) ; Check for timeout and (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) ; Check that we didn't abort endw ; Check why we left the while loop if ({{ group.following_err() }} != 0) ; Following error check failed HomingStatus = StatusFFErr endif if ({{ group.limits() }}=1) ; If a motor hit a limit HomingStatus = StatusLimit endif if (timer<0 or timer=0) ; If we timed out HomingStatus = StatusTimeout endif endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.continue_home_maintain_axes_offset(**kwargs)[source]
Monitor axes that are homing and when one achieves home jog it in the same direction as home. This is to avoid tilt on pairs of axes that have misaligned home marks.
This will cause the jinja template continue_home_maintain_axes_offset.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
;--- Homing State 2 ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=StateHoming ; This block to be used after a home block with wait_for_one_motor=True. ; It allows motors to continue to home but restarts those that have already ; reached home. For use with axes that are sensitve to tilt but do not have ; aligned home marks ; make sure all jogs will be a long distance {{ group.set_large_jog_distance(homing_direction=template.args.homing_direction) }} ; continue processing until all motors are homed or something goes wrong timer = {{ plc.timeout }} MilliSeconds while ({{group.homed()}} = 0) ; at least one is not homed and ({{group.following_err()}} = 0) ; there are no following errors and ({{group.in_pos()}} = 0) ; at least one is not in postion and (timer > 0) ; Check for timeout ; jog any motors that have stopped on home {% filter indent(width=12) %} {{ group.jog_stopped() }} {% endfilter %} endw ; Check why we left the while loop if ({{ group.following_err() }} != 0) ; Following error check failed HomingStatus = StatusFFErr endif if (timer<0 or timer=0) ; If we timed out HomingStatus = StatusTimeout endif endif
The included template wait_for_done.pmc.jinja allows this function to take these additional parameters which all default to False:
- Parameters
no_following_err (bool) – don’t check for following error during moves
with_limits (bool) – check for limits during the move. When False we continue waiting even if a subset of the axes have stopped on a limit
wait_for_one_motor (bool) – stop wating as soon as one of the motors has stopped instead of waiting for all motors
- pmac_motorhome.snippets.post_home_action()[source]
Insert an extra block with the group’s post home action in it
This will cause the jinja template post_home_action.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% if group.post and group.post != "" %} {% include "debug_pause.pmc.jinja" %} ;---- PostHomeMove State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=StatePostHomeMove ; Execute the move commands if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) {{ group.post }} endif endif {% endif %}
- pmac_motorhome.snippets.pre_home_action()[source]
Insert an extra block with the group’s pre home action in it
This will cause the jinja template pre_home_action.pmc.jinja to be expanded and inserted into the PLC code. The template is as follows:
{% if group.pre and group.pre != "" %} {% include "debug_pause.pmc.jinja" %} ;---- PreHomeMove State ---- if (HomingStatus = StatusHoming or HomingStatus = StatusDebugHoming) HomingState=StatePreHomeMove ; Execute the move commands {{ group.pre }} endif {% endif %}