GeminiMotorDrive.compilers.move_sequence¶
Module for working with move sequences and compiling them to movement commands, programs, and profiles for a Gemini drive.
Move sequences care described in compile_sequence
along with a few
examples.
compile_sequence (cycles[, ...]) |
Makes the command list for a move sequence. |
convert_sequence_to_motor_units (cycles, ...) |
Converts a move sequence to motor units. |
get_sequence_time (cycles[, unit_converter, eres]) |
Calculates the time the move sequence will take to complete. |
move_time (move, eres) |
Calculates the time it takes to do a move. |
compile_sequence¶
-
GeminiMotorDrive.compilers.move_sequence.
compile_sequence
(cycles, program_or_profile='program', unit_converter=None)[source]¶ Makes the command list for a move sequence.
Constructs the list of commands to execute the given sequence of motion. Program/command line commands or profile commands can be generated depending on the value of program_or_profile so that the commands can be used to construct a program or profile later. Types of motion supported (see Notes for how to specify) are moves from one position to another (the motion will always come to a stop before doing the next motion), waiting a given interval of time till starting the next move, and looping over a sequence of moves.
Parameters: - cycles (iterable of dicts) – The iterable of cycles of motion to do one after another. See Notes for format.
- program_or_profile ({‘program’, ‘profile’}, optional) – Whether program or profile motion commands should be used. Anything other than these two values implies the default.
- unit_converter (UnitConverter, optional) –
GeminiMotorDrive.utilities.UnitConverter
to use to convert the units in cycles to motor units.None
indicates that they are already in motor units.
Returns: commands (list of str) –
list
ofstr
commands making up the move sequence.Notes
cycles is an iterable of individual cycles of motion. Each cycle is a
dict
that represents a sequence of moves that could possibly be looped over. The field'iterations'
gives how many times the sequence of moves should be done (a value > 1 implies a loop). Then the field'moves'
is an iterable of the individual moves. Each individual move is adict
with the acceleration ('A'
), deceleration ('AD'
with 0 meaning the value of the acceleration is used), velocity ('V'
), and the distance/position ('D'
). Back in the cycle, the field'wait_times'
is an iterable of numbers giving the time in seconds to wait after each move before going onto the next.See also
get_sequence_time()
,convert_sequence_to_motor_units()
,GeminiMotorDrive.utilities.UnitConverter()
Examples
Simple program style two motions with a pause in between.
>>> from GeminiMotorDrive.compilers.move_sequence import * >>> cycles = [{'iterations':1, 'wait_times':[1, 0], ... 'moves':[{'A':100, 'AD':0, 'D':-1000, 'V':100}, ... {'A':90, 'AD':0, 'D':-1000, 'V':100}]}] >>> compile_sequence(cycles) ['A100', 'AD0', 'V100', 'D-1000', 'GO1', 'WAIT(AS.1=b0)', 'T1', 'A90', 'GO1', 'WAIT(AS.1=b0)']
The same motion but in profile style commands
>>> from GeminiMotorDrive.compilers.move_sequence import * >>> cycles = [{'iterations':1, 'wait_times':[1, 0], ... 'moves':[{'A':100, 'AD':0, 'D':-1000, 'V':100}, ... {'A':90, 'AD':0, 'D':-1000, 'V':100}]}] >>> compile_sequence(cycles, program_or_profile='profile') ['A100', 'AD100', 'V100', 'D-1000', 'VF0', 'GOBUF1', 'GOWHEN(T=1000)', 'A90', 'AD90', 'VF0', 'GOBUF1']
Another motion with a back and forth loop (100 iterations) in the middle, done in program style commands.
>>> from GeminiMotorDrive.compilers.move_sequence import * >>> cycles = [{'iterations':1, 'wait_times':[1], ... 'moves':[{'A':100, 'AD':0, 'D':-1000, 'V':100}]}, ... {'iterations':100, 'wait_times':[0, 0], ... 'moves':[{'A':50, 'AD':40, 'D':-1000, 'V':30}, ... {'A':50, 'AD':40, 'D':1000, 'V':30}]}, ... {'iterations':1, 'wait_times':[0], ... 'moves':[{'A':100, 'AD':0, 'D':1000, 'V':100}]}] >>> compile_sequence(cycles) ['A100', 'AD0', 'V100', 'D-1000', 'GO1', 'WAIT(AS.1=b0)', 'T1', 'L100', 'A50', 'AD40', 'V30', 'D-1000', 'GO1', 'WAIT(AS.1=b0)', 'D~', 'GO1', 'WAIT(AS.1=b0)', 'LN', 'A100', 'AD0', 'V100', 'GO1', 'WAIT(AS.1=b0)']
convert_sequence_to_motor_units¶
-
GeminiMotorDrive.compilers.move_sequence.
convert_sequence_to_motor_units
(cycles, unit_converter)[source]¶ Converts a move sequence to motor units.
Converts a move sequence to motor units using the provied converter.
Parameters: - cycles (iterable of dicts) –
The iterable of cycles of motion to do one after another. See
compile_sequence
for format. - unit_converter (UnitConverter, optional) –
GeminiMotorDrive.utilities.UnitConverter
to use to convert the units in cycles to motor units.
Returns: motor_cycles (list of dicts) – A deep copy of cycles with all units converted to motor units.
- cycles (iterable of dicts) –
The iterable of cycles of motion to do one after another. See
get_sequence_time¶
-
GeminiMotorDrive.compilers.move_sequence.
get_sequence_time
(cycles, unit_converter=None, eres=None)[source]¶ Calculates the time the move sequence will take to complete.
Calculates the amount of time it will take to complete the given move sequence. Types of motion supported are moves from one position to another (the motion will always come to a stop before doing the next motion), waiting a given interval of time till starting the next move, and looping over a sequence of moves.
Parameters: - cycles (list of dicts) –
The
list
of cycles of motion to do one after another. Seecompile_sequence
for format. - unit_converter (UnitConverter, optional) –
GeminiMotorDrive.utilities.UnitConverter
to use to convert the units in cycles to motor units.None
indicates that they are already in motor units. - eres (int) –
Encoder resolution. Only relevant if unit_converter is
None
.
Returns: time (float) – Time the move sequence will take in seconds.
- cycles (list of dicts) –
The
move_time¶
-
GeminiMotorDrive.compilers.move_sequence.
move_time
(move, eres)[source]¶ Calculates the time it takes to do a move.
Calculates how long it will take to complete a move of the motor. It is assumed that the motor will decerate to a stop for the end of the move as opposed to keep moving at velocity.
Everything is in motor units which are encoder counts for distance, pitches/s for velocity, and pitches/s^2 for acceleration.
Parameters: - move (dict) – Contains the move parameters in its fields: acceleration (‘A’), deceleration (‘AD’ with 0 meaning the value of the acceleration is used), velocity (‘V’), and the distance/position (‘D’).
- eres (int) – Encoder resolution.
Returns: time (float) – Time the move will take in seconds.
See also