ME 405 Pen Plotter
stepper_driver.Stepper_Driver Class Reference

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ __init__()

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.

Parameters
spiSPI pin.
enTMC2208 enable pin.
csChip select pin.
x_maxMax position the stepper can move to, in microsteps.
v_minV_MIN register value.
v_maxV_MAX register value.
pulse_divPULSE_DIV register value.
ramp_divRAMP_DIV register value.
a_maxA_MAX register value.
pmulPMUL register value.
pdivPDIV register value.

Member Function Documentation

◆ disable()

def stepper_driver.Stepper_Driver.disable (   self)

Disables the TMC2208.

Sets the en pin high to disable the TMC2208.

◆ enable()

def stepper_driver.Stepper_Driver.enable (   self)

Enables the TMC2208.

Sets the en pin low to enable the TMC2208.

◆ enable_step_dir()

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.

◆ home()

def stepper_driver.Stepper_Driver.home (   self)

Homes the stepper.

Moves the stepper towards 0 until the limit switch is triggered.

◆ homing_in_progress()

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.

Returns
True if homing is in progress, else False.

◆ print_arr()

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.

Parameters
recvbytearray object to print.

◆ send_recv()

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.

Parameters
sendDatagram to send to the TMC4210.
recvDatagram in which to store the received datagram.
Returns
Bytes received from the TMC4210.

◆ set_acceleration()

def stepper_driver.Stepper_Driver.set_acceleration (   self,
  acceleration 
)

Sets acceleration.

Sets the A_MAX register value to what is passed in.

Parameters
accelerationValue of A_MAX to set.

◆ set_pdiv()

def stepper_driver.Stepper_Driver.set_pdiv (   self,
  pdiv 
)

Sets PDIV.

Sets the PDIV register value to what is passed in.

Parameters
pdivValue of PDIV to set.

◆ set_pmul()

def stepper_driver.Stepper_Driver.set_pmul (   self,
  pmul 
)

Sets PMUL.

Sets the PMUL register value to what is passed in.

Parameters
pmulValue of PMUL to set.

◆ set_position()

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.

Parameters
x_targetValue of X_TARGET and X_ACTUAL to set.

◆ set_pulse_div()

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.

Parameters
pulse_divPULSE_DIV value to set.

◆ set_ramp_div()

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.

Parameters
ramp_divRAMP_DIV value to set.

◆ set_ramp_mode()

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.

Parameters
modeMode to set.

◆ set_target()

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.

Parameters
x_targetValue of X_TARGET to set.

◆ set_velocity()

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.

Parameters
v_minValue of V_MIN to set.
v_maxValue of V_MAX to set.

◆ target_reached()

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.

Parameters
x_targetValue to check the motor's actual position against.
Returns
True if the target position has been reached, else False.

The documentation for this class was generated from the following file: