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:
EventActorThe
Driveactor is the next level actor above theAxisactor. 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
listortupleofdictelements. Each dictionary element contains the input arguments need to create anAxisinstance. 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 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 all the axes will happen primarily through the event 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 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
Tuple of the names of the defined axes.
List of the drive's axis instances.
Configuration dictionary of the actor.
Trueif the TCP connection is established for ALL drive axes.The
naxes-D encoder position of the probe drive.The
Loggerinstance being used for the actor.The
asyncioevent loop for the actor.(
str) A unique name given for the instance of the actor.Number of axes defined in the
Drive.The
naxes-D position of the probe drive.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.Methods Summary
move_to(pos[,Β axis])Move the drive to a specified location.
run([auto_run])Activate the
asyncioevent loop.sel(aname)Select an axis index from a given axis name
aname.send_command(command,Β *args[,Β axis])Send
commandto the motor, and receive its response.setup_event_loop([loop])Set up the
asyncioevent 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.
- 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(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
naxesif 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 andposhas the same length asnaxes. (DEFAULT:None)
- 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.
- sel(aname)ο
Select an axis index from a given axis name
aname.
- send_command(command, *args, axis: int | None = None)ο
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.
- 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)ο
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)