A stepper driver class for controlling a TMC4210 and TMC2208. More...
Public Member Functions | |
def | __init__ (self, spi, en, cs, x_max, v_min, v_max, pulse_div, ramp_div, a_max, pmul, pdiv) |
Constructor for Stepper_Driver. More... | |
def | send_recv (self, send, recv=None) |
Sends and receives data to and from the TMC4210. More... | |
def | enable_step_dir (self) |
Enables the step/dir interface of the TMC4210. More... | |
def | set_ramp_mode (self, mode='ramp_mode') |
Sets RAMP_MODE. More... | |
def | enable (self) |
Enables the TMC2208. More... | |
def | disable (self) |
Disables the TMC2208. More... | |
def | set_pulse_div (self, pulse_div) |
Sets PULSE_DIV. More... | |
def | set_ramp_div (self, ramp_div) |
Sets RAMP_DIV. More... | |
def | set_pmul (self, pmul) |
Sets PMUL. More... | |
def | set_pdiv (self, pdiv) |
Sets PDIV. More... | |
def | set_velocity (self, v_min, v_max) |
Sets velocity. More... | |
def | set_acceleration (self, acceleration) |
Sets acceleration. More... | |
def | set_target (self, x_target) |
Sets X_TARGET. More... | |
def | target_reached (self, x_target) |
Indicates whether the target position has been reached. More... | |
def | set_position (self, x_target) |
Sets the current position of the stepper. More... | |
def | home (self) |
Homes the stepper. More... | |
def | homing_in_progress (self) |
Indicates whether homing is in progress. More... | |
def | print_arr (self, recv) |
Print a bytearray. More... | |
Public Attributes | |
spi | |
SPI pin. | |
en | |
TMC2208 enable pin. | |
cs | |
Chip select pin. | |
x_max | |
Max position the stepper can move to, in microsteps. | |
A stepper driver class for controlling a TMC4210 and TMC2208.
Objects of this class can be used to interface with a TMC4210 and TMC2208 in order to control a stepper motor.
def stepper_driver.Stepper_Driver.__init__ | ( | self, | |
spi, | |||
en, | |||
cs, | |||
x_max, | |||
v_min, | |||
v_max, | |||
pulse_div, | |||
ramp_div, | |||
a_max, | |||
pmul, | |||
pdiv | |||
) |
Constructor for Stepper_Driver.
Sets registers in a TMC4210 with values passed in and enables the step/dir interface.
spi | SPI pin. |
en | TMC2208 enable pin. |
cs | Chip select pin. |
x_max | Max position the stepper can move to, in microsteps. |
v_min | V_MIN register value. |
v_max | V_MAX register value. |
pulse_div | PULSE_DIV register value. |
ramp_div | RAMP_DIV register value. |
a_max | A_MAX register value. |
pmul | PMUL register value. |
pdiv | PDIV register value. |
def stepper_driver.Stepper_Driver.disable | ( | self | ) |
Disables the TMC2208.
Sets the en pin high to disable the TMC2208.
def stepper_driver.Stepper_Driver.enable | ( | self | ) |
Enables the TMC2208.
Sets the en pin low to enable the TMC2208.
def stepper_driver.Stepper_Driver.enable_step_dir | ( | self | ) |
Enables the step/dir interface of the TMC4210.
Sets the en_sd bit to 1 to enable the step/dir interface.
def stepper_driver.Stepper_Driver.home | ( | self | ) |
Homes the stepper.
Moves the stepper towards 0 until the limit switch is triggered.
def stepper_driver.Stepper_Driver.homing_in_progress | ( | self | ) |
Indicates whether homing is in progress.
Returns True if the stepper is homing and the limit switch has not been triggered yet, else False. If homing is not in progress, the limit switch will be disabled and the stepper's position will be set to 0.
def stepper_driver.Stepper_Driver.print_arr | ( | self, | |
recv | |||
) |
Print a bytearray.
Print each byte in the bytearray that has been passed in. This function can be used to check datagrams that are being sent to or received from the TMC4210.
recv | bytearray object to print. |
def stepper_driver.Stepper_Driver.send_recv | ( | self, | |
send, | |||
recv = None |
|||
) |
Sends and receives data to and from the TMC4210.
Sets the chip select pin and uses spi.send_recv to send and receive data to and from the TMC4210 via SPI.
send | Datagram to send to the TMC4210. |
recv | Datagram in which to store the received datagram. |
def stepper_driver.Stepper_Driver.set_acceleration | ( | self, | |
acceleration | |||
) |
Sets acceleration.
Sets the A_MAX register value to what is passed in.
acceleration | Value of A_MAX to set. |
def stepper_driver.Stepper_Driver.set_pdiv | ( | self, | |
pdiv | |||
) |
Sets PDIV.
Sets the PDIV register value to what is passed in.
pdiv | Value of PDIV to set. |
def stepper_driver.Stepper_Driver.set_pmul | ( | self, | |
pmul | |||
) |
Sets PMUL.
Sets the PMUL register value to what is passed in.
pmul | Value of PMUL to set. |
def stepper_driver.Stepper_Driver.set_position | ( | self, | |
x_target | |||
) |
Sets the current position of the stepper.
Sets the X_TARGET and X_ACTUAL registers to the position that is passed in, in units of microsteps.
x_target | Value of X_TARGET and X_ACTUAL to set. |
def stepper_driver.Stepper_Driver.set_pulse_div | ( | self, | |
pulse_div | |||
) |
Sets PULSE_DIV.
Sets the PULSE_DIV register value to what is passed in.
pulse_div | PULSE_DIV value to set. |
def stepper_driver.Stepper_Driver.set_ramp_div | ( | self, | |
ramp_div | |||
) |
Sets RAMP_DIV.
Sets the RAMP_DIV register value to what is passed in.
ramp_div | RAMP_DIV value to set. |
def stepper_driver.Stepper_Driver.set_ramp_mode | ( | self, | |
mode = 'ramp_mode' |
|||
) |
Sets RAMP_MODE.
Sets the RAMP_MODE register value to 00 for ramp_mode or 10 for velocity_mode.
mode | Mode to set. |
def stepper_driver.Stepper_Driver.set_target | ( | self, | |
x_target | |||
) |
Sets X_TARGET.
Sets the X_TARGET register value to the value that is passed in, in units of microsteps.
x_target | Value of X_TARGET to set. |
def stepper_driver.Stepper_Driver.set_velocity | ( | self, | |
v_min, | |||
v_max | |||
) |
Sets velocity.
Sets the V_MIN and V_MAX register values to what is passed in.
v_min | Value of V_MIN to set. |
v_max | Value of V_MAX to set. |
def stepper_driver.Stepper_Driver.target_reached | ( | self, | |
x_target | |||
) |
Indicates whether the target position has been reached.
Returns True if the motor has reached X_TARGET and False if not.
x_target | Value to check the motor's actual position against. |