Axis

class bapsf_motion.actors.axis_.Axis(*, ip: str, units: str, units_per_rev: float, motor_settings: Dict[str, Any] = None, name: str = 'Axis', logger: Logger = None, loop: AbstractEventLoop = None, auto_run: bool = False, parent: EventActor | None = None)

Bases: EventActor

The Axis actor is the next level actor above the Motor actor. This actor is ignorant of how it is situated in a probe drive, but is fully aware of the entire physical axis that defines it and the motor that moves the axis. This actor operates in physical units and will handle all the necessary unit conversion to communicate with the Motor actor.

Parameters:
  • ip (str) – IPv4 address for the motor driving the axis

  • units (str) – Physical units the axis operates in (e.g. 'cm')

  • units_per_rev (float) – The number of units traversed per motor revolution.

  • motor_settings (dict, optional) – A dictionary containing the optionl keyword arguments for Motor. (DEFAULT: None)

  • name (str) – Name the axis. (DEFAULT: 'Axis')

  • 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 the motor will happen primaritly through the evenet 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 Axis
>>> import logging
>>> import sys
>>> logging.basicConfig(stream=sys.stdout, level=logging.NOTSET)
>>> ax = Axis(
...     ip="192.168.6.104",
...     units="cm",
...     units_per_rev=0.1*2.54,  # acme rod with .1 in pitch
...     name="WALL-E",
...     auto_run=True,
... )

Attributes Summary

config

Configuration dictionary of the actor.

connected

True if the TCP connection is established with the physical motor.

conversion_pairs

List of conversion pairs between motor units and physical units.

encoder

Current axis encoder position in units defined by the units attribute.

equivalencies

List of unit equivalencies to convert back-and-forth between the axis physical units and the motor units.

ip

IPv4 address for the Axis' motor

is_moving

True or False indicating if the axis is currently moving.

logger

The Logger instance being used for the actor.

loop

The asyncio event loop for the actor.

motor

Instance of the Motor object that belongs to Axis.

name

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

parent

position

Current axis position in units defined by the units attribute.

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.

units

The unit of measure for the Axis physical parameters like position, speed, etc.

units_per_rev

The number of units (units) translated per full revolution of the motor (motor).

Methods Summary

move_to(*args)

Quick access command for send_command("move_to", *args).

run([auto_run])

Activate the asyncio event loop.

send_command(command,Β *args)

Send command to the motor, and receive its response.

setup_event_loop([loop])

Set up the asyncio event loop.

stop([soft])

Quick access command for send_command("stop").

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 with the physical motor.

conversion_pairs

List of conversion pairs between motor units and physical units. For example, [(u.steps, self.units), ...].

encoder

Current axis encoder position in units defined by the units attribute.

equivalencies

List of unit equivalencies to convert back-and-forth between the axis physical units and the motor units.

ip

IPv4 address for the Axis’ motor

is_moving

True or False indicating if the axis is currently moving.

logger

The Logger instance being used for the actor.

loop

The asyncio event loop for the actor.

motor

Instance of the Motor object that belongs to Axis.

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 axis position in units defined by the units attribute.

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.

units

The unit of measure for the Axis physical parameters like position, speed, etc.

units_per_rev

The number of units (units) translated per full revolution of the motor (motor).

Methods Documentation

move_to(*args)

Quick access command for send_command("move_to", *args).

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)

send_command(command, *args)

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.

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

Quick access command for send_command("stop").

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)