Drive

class bapsf_motion.actors.drive_.Drive(*, axes: List[Dict[str, Any]], name: str = None, logger: Logger = None, loop: AbstractEventLoop = None, auto_run: bool = False, parent: EventActor | None = None)

Bases: EventActor

The Drive actor is the next level actor above the Axis actor. This actor is ignorant of how the probe drive is implemented in the physical space, but it is fully aware of the axes that make up the probe drive. The axes are ordered, but the actor has no clue how these axes are oriented in the physical space. This actor operates in physical units of the axes.

Parameters:
  • axes (List[Dict[str, Any]]) – A list or tuple of dict elements. Each dictionary element contains the input arguments need to create an Axis instance. The order of the list defines the order of the axes, i.e. element index 0 defines axis 0.

  • name (str, optional) – Name the drive. If None, then a name will be auto-generated.

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

Examples

>>> from bapsf_motion.actors import Drive
>>> import logging
>>> import sys
>>> logging.basicConfig(stream=sys.stdout, level=logging.NOTSET)
>>> dr = Drive(
...     axes=[
...         {"ip": "192.168.6.104", "units": "cm", "units_per_rev": 0.1*2.54},
...         {"ip": "192.168.6.103", "units": "cm", "units_per_rev": 0.1*2.54},
...     ],
...     name="WALL-E",
...     auto_run=True,
... )

Attributes Summary

anames

Tuple of the names of the defined axes.

axes

List of the drive's axis instances.

config

Configuration dictionary of the actor.

connected

True if the TCP connection is established for ALL drive axes.

encoder

The naxes-D encoder position of the probe drive.

is_moving

True if any axis in the Drive is moving, otherwise False.

logger

The Logger instance being used for the actor.

loop

The asyncio event loop for the actor.

name

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

naxes

Number of axes defined in the Drive.

parent

position

The naxes-D position of the probe drive.

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.

Methods Summary

move_to(pos[,Β axis])

Move the drive to a specified location.

run([auto_run])

Activate the asyncio event loop.

sel(aname)

Select an axis index from a given axis name aname.

send_command(command,Β *args[,Β axis])

Send command to the motor, and receive its response.

setup_event_loop([loop])

Set up the asyncio event loop.

stop([soft])

Stop all axes from moving.

terminate([delay_loop_stop])

Stop the actor's event loop.

Attributes Documentation

anames

Tuple of the names of the defined axes.

axes

List of the drive’s axis instances.

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.

encoder

The naxes-D encoder position of the probe drive.

is_moving

True if any axis in the Drive is moving, otherwise False.

logger

The Logger instance being used for the actor.

loop

The asyncio event loop for the actor.

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.

naxes

Number of axes defined in the Drive.

parent
position

The naxes-D position of the probe drive.

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.

Methods Documentation

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

Move the drive to a specified location.

Parameters:
  • pos (array_like) – Position (in axis represented units) for the drive to move to. Can be singled valued if just moving an individual axes, or the same lengths as naxes if moving the whole probe drive.

  • axis (int, optional) – Axis index for the axis to be moved. If None, then it is assumed all axes need to be moved and pos has the same length as naxes. (DEFAULT: None)

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)

sel(aname)

Select an axis index from a given axis name aname.

send_command(command, *args, axis: int | None = None)

Send command to the motor, and receive its response. If the event loop is running, then the command will be sent as a threadsafe coroutine in the loop. Otherwise, the command will be sent directly to the motor.

Parameters:
  • command (str) – The desired command to be sent to the motor.

  • *args – Any arguments to the command that will be sent with the motor command.

  • axis (int, optional) – Axis index the command is directed to. If None, then the command is sent to all axes. (DEFAULT: NONE)

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

Stop all axes from moving.

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)