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:
EventActorThe
Axisactor is the next level actor above theMotoractor. 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 theMotoractor.- 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
unitstraversed per motor revolution.motor_settings (
dict, optional) β A dictionary containing the optionl keyword arguments forMotor. (DEFAULT:None)name (str) β Name the axis. (DEFAULT:
'Axis')logger (
Logger, optional) β An instance ofLoggerthat the Actor will record events and status updates to. IfNone, then a logger will automatically be generated. (DEFAULT:None)loop (
asyncio.AbstractEventLoop, optional) β Instance of anasyncioevent loop. Communication with the motor will happen primaritly through the evenet loop. IfNone, 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 therun()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
Configuration dictionary of the actor.
Trueif the TCP connection is established with the physical motor.List of conversion pairs between motor units and physical units.
Current axis encoder position in units defined by the
unitsattribute.List of unit equivalencies to convert back-and-forth between the axis physical units and the motor units.
IPv4 address for the Axis' motor
The
Loggerinstance being used for the actor.The
asyncioevent loop for the actor.(
str) A unique name given for the instance of the actor.Current axis position in units defined by the
unitsattribute.List of
asyncio.Tasks this actor has in its event loop.Indicates if the actor has been terminated.
The
Threadthe event loop is running in.The unit of measure for the
Axisphysical parameters like position, speed, etc.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
asyncioevent loop.send_command(command,Β *args)Send
commandto the motor, and receive its response.setup_event_loop([loop])Set up the
asyncioevent 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.
- conversion_pairsο
List of conversion pairs between motor units and physical units. For example,
[(u.steps, self.units), ...].
- 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
- loggerο
The
Loggerinstance being used for the actor.
- loopο
The
asyncioevent 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 (seelogger).If the user does not specify a name, then the Actor should auto-generate a name.
- parentο
- tasksο
List of
asyncio.Tasks this actor has in its event loop.
- terminatedο
Indicates if the actor has been terminated.
- threadο
The
Threadthe event loop is running in.If
loopwas given during instantiation, then there is no way of obtaining the thread object the event loop is running in. In this casethreadwill beNone.The thread id can always be retrieved using
_thread_id.
Methods Documentation
- move_to(*args)ο
Quick access command for
send_command("move_to", *args).
- run(auto_run=True)ο
Activate the
asyncioevent loop. If the event loop is running, then nothing happens. Otherwise, the event loop is placed in a separate thread and set torun_forever.
- send_command(command, *args)ο
Send
commandto 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
commandthat will be sent with the motor command.
- setup_event_loop(loop: AbstractEventLoop | None = None)ο
Set up the
asyncioevent loop. If the given loop is not an instance ofAbstractEventLoop, then a new loop will be created.- Parameters:
loop (
asyncio.AbstractEventLoop) βasyncioevent 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)