MotionGroup

class bapsf_motion.actors.motion_group_.MotionGroup(config: str | Dict[str, Any] = None, *, logger: Logger = None, loop: AbstractEventLoop = None, auto_run: bool = False, build_mode: bool = False, parent: EventActor | None = None)

Bases: EventActor

The MotionGroup actor brings together all the components that are needed to move a probe drive around the motion space. These components include: (1) the full motion group configuration (i.e. instance of MotionGroupConfig), (2) communication with the probe drive (i.e. instance of Drive), (3) an understanding of the motion space (i.e. instance of MotionBuilder, and (4) how to convert back and forth from the motion space coordinate system and the probe drive coordinate system (i.e. instance of a subclass of BaseTransform).

Parameters:
  • config (str or dict) – A TOML like string or dictionary defining the motion group configuration. See MotionGroupConfig for further details.

  • logger (Logger, optional) – An instance of Logger that the Actor will record events and status updates to. If None, then a logger will automatically be generated. (DEFAULT: None)

  • loop (asyncio.AbstractEventLoop, optional) – Instance of an asyncio event loop. Communication with all the axes will happen primarily through the event loop. If None, then an event loop will be auto-generated. (DEFAULT: None)

  • auto_run (bool, optional) – If True, then the event loop will be placed in a separate thread and started. This is all done via the run() method. (DEFAULT: False)

Attributes Summary

config

Configuration dictionary of the actor.

connected

True if the TCP connection is established for ALL drive axes (i.e. the entire motion group).

drive

Instance of Drive associated with the motion group.

encoder

Current encoder position of the probe drive, in motion space coordinates and units.

is_moving

logger

The Logger instance being used for the actor.

loop

The asyncio event loop for the actor.

mb

Instance of MotionBuilder associated with the motion group.

ml_index

Last motion list index the probe drive moved to.

name

(str) A unique name given for the instance of the actor.

parent

position

Current position of the probe drive, in motion space coordinates and units.

tasks

List of asyncio.Tasks this actor has in its event loop.

terminated

Indicates if the actor has been terminated.

thread

The Thread the event loop is running in.

transform

Instance of the transformer associated with the motion group.

Methods Summary

move_ml(index)

Move the probe drive to a specific index of the motion list.

move_to(pos[,Β axis])

Move the probe drive to a specified location, pos.

replace_drive(drive)

Replace the Drive instance associated with the motion group.

replace_motion_builder(mb)

replace_transform(tr)

run([auto_run])

Activate the asyncio event loop.

set_zero([axis])

Make current motion space position zero.

setup_event_loop([loop])

Set up the asyncio event loop.

stop([soft])

Immediately stop the probe drive motion.

terminate([delay_loop_stop])

Stop the actor's event loop.

Attributes Documentation

config

Configuration dictionary of the actor.

Warning

This dictionary should never be written to from outside the owning actor.

connected

True if the TCP connection is established for ALL drive axes (i.e. the entire motion group).

drive

Instance of Drive associated with the motion group.

encoder

Current encoder position of the probe drive, in motion space coordinates and units.

is_moving
logger

The Logger instance being used for the actor.

loop

The asyncio event loop for the actor.

mb

Instance of MotionBuilder associated with the motion group.

ml_index

Last motion list index the probe drive moved to.

name

(str) A unique name given for the instance of the actor. This name is used as an identifier in the actor logger (see logger).

If the user does not specify a name, then the Actor should auto-generate a name.

parent
position

Current position of the probe drive, in motion space coordinates and units.

tasks

List of asyncio.Tasks this actor has in its event loop.

terminated

Indicates if the actor has been terminated.

thread

The Thread the event loop is running in.

If loop was given during instantiation, then there is no way of obtaining the thread object the event loop is running in. In this case thread will be None.

The thread id can always be retrieved using _thread_id.

transform

Instance of the transformer associated with the motion group.

Methods Documentation

move_ml(index: int)

Move the probe drive to a specific index of the motion list.

move_to(pos, axis: int | None = None)

Move the probe drive to a specified location, pos.

Parameters:
  • pos (array_like) – A position in the motion space for the probe to be moved to. pos should have the same dimensionality as the motion space unless keyword axis is used.

  • axis (int, optional) – An integer specifying which axis is to be moved. axis is integer of 0 to \(N-1\), where \(N\) is the dimensionality of the motion space.

replace_drive(drive: Drive | Dict[str, Any])

Replace the Drive instance associated with the motion group. If the new drive is not valid, then no replacement will be performed.

Parameters:

drive (Union[Drive, Dict[str, Any]]) – The new drive to replace this existing drive. This can either be an instance of Drive or a valid dictionary configuration for a drive.

Notes

If the given drive is running, then it will be terminated and respawned using the event loop loop() associated with the motion group.

replace_motion_builder(mb: MotionBuilder | Dict[str, Any])
replace_transform(tr: BaseTransform | Dict[str, Any])
run(auto_run=True)

Activate the asyncio event loop. If the event loop is running, then nothing happens. Otherwise, the event loop is placed in a separate thread and set to run_forever.

Parameters:

auto_run (bool, optional) – If False, then do NOT start the event loop. This keyword is only made available to help with subclassing. (DEFAULT: True)

set_zero(axis: int | None = None)

Make current motion space position zero.

Parameters:

axis (int, optional) – If None (DEFAULT), then all axes will be set to zero. If int, then the axis corresponding to that index will be set to zero.

setup_event_loop(loop: AbstractEventLoop | None = None)

Set up the asyncio event loop. If the given loop is not an instance of AbstractEventLoop, then a new loop will be created.

Parameters:

loop (asyncio.AbstractEventLoop) – asyncio event loop for the actor’s tasks

stop(soft=False)

Immediately stop the probe drive motion.

terminate(delay_loop_stop=False)

Stop the actor’s event loop. All actor tasks will be cancelled, the connection to the motor will be shutdown, and the event loop will be stopped.

Parameters:

delay_loop_stop (bool) – If True, then do NOT stop the event loop. In this case it is assumed the calling functionality is managing additional tasks in the event loop, and it is up to that functionality to stop the loop. (DEFAULT: False)