ME 405 Portfolio
|
Driver to be used with the TMC4210 and TMC2208 IC's. More...
Public Member Functions | |
def | __init__ (self, nCS, ENN, spi, reverse) |
Creates a motor object by asking for an enable pin, a chip select pin, and an SPI object. More... | |
def | test_version (self) |
Allows testing of whether motor is successfuly configured. More... | |
def | set_mode (self, mode) |
Allows selection of motor mode. More... | |
def | set_divs (self, pulsediv, rampdiv) |
Writes a pulse_div and a ramp_div to the TMC 4210. More... | |
def | set_vmin (self, vmin) |
Writes a minimum velocity to the TMC 4210. More... | |
def | set_vmax (self, vmax) |
Writes a maximum velocity to the TMC 4210. More... | |
def | set_velocity (self, target_vel) |
Allows speed control of the stepper motor. More... | |
def | set_accel (self, max_accel) |
Allows specification of deceleration ramp. More... | |
def | set_target_pos (self, target_pos) |
Allows specification of a desired position. More... | |
def | set_zero (self, offset) |
Allows user to specify motor starting position. More... | |
def | get_target_pos (self) |
Returns the target position of the motor. More... | |
def | arrived (self, tolerance) |
Determines whether the motor has arrived to its target position. More... | |
def | get_pos (self) |
Returns the current position of the motor. More... | |
Public Attributes | |
spi | |
Creares an SPI object. More... | |
nCS | |
Creares an chip select pin for the motor. More... | |
ENN | |
Creares an Enable Pin object. More... | |
X_TARGET | |
Register for X_TARGET. More... | |
X_ACTUAL | |
Register for X_ACTUAL. More... | |
V_TARGET | |
Register for V_TARGET. More... | |
A_MAX | |
Register for A_MAX. More... | |
RAMP_MODE | |
Register for RAMP_MODE. More... | |
X_LATCHED | |
Register for X_LATCHED. More... | |
TYPE_VERSION | |
Register for TYPE_VERSION. More... | |
PMUL_PDIV | |
Register for PMUL_PDIV. More... | |
IF_CONF | |
Register for IF_CONF. More... | |
V_MIN | |
Register for V_MIN. More... | |
V_MAX | |
Register for V_MAX. More... | |
PULSE_RAMP_DIV | |
Register for PULSE_RAMP_DIV. More... | |
TX_buf | |
Buffer for sending data. More... | |
RX_buf | |
Buffer for receiving data. More... | |
Driver to be used with the TMC4210 and TMC2208 IC's.
This driver enables control over a stepper motor by interfacing with both the TMC 2208 and the TMC 4210 (as control over both is required to drive a stepper motor).
def stepperdriver.StepperDriver.__init__ | ( | self, | |
nCS, | |||
ENN, | |||
spi, | |||
reverse | |||
) |
Creates a motor object by asking for an enable pin, a chip select pin, and an SPI object.
Also requires a Boolean specification to switch which rotational direction is positive.
After receiving all the pins, the registers of the TMC 4210 are assigned to variables. From there, the class puts the motors through an initialization process specified by the manual. Lastly, TX and RX buffers are created for sending/receiving data.
def stepperdriver.StepperDriver.arrived | ( | self, | |
tolerance | |||
) |
Determines whether the motor has arrived to its target position.
Computes the difference between the target position and actual position. If the distance is greater than a specified tolerance, then the method returns a True Boolean. Otherwise, it returns a False Boolean.
def stepperdriver.StepperDriver.get_pos | ( | self | ) |
Returns the current position of the motor.
Reads from the corresponding register and returns the current position of the motor.
def stepperdriver.StepperDriver.get_target_pos | ( | self | ) |
Returns the target position of the motor.
Reads from the corresponding register and returns the position that the motor is targeted for.
def stepperdriver.StepperDriver.set_accel | ( | self, | |
max_accel | |||
) |
Allows specification of deceleration ramp.
In order to control the position of a stepper motor, the TMC 4210 requires that a maximum acceleration for the deceleration ramp (the ramp characteristic of the motor slowing down once near its desired location) be specified.
Two scaling factors, PMUL and PDIV, are also required. PMUL can be any integer between 128 and 255 while PDIV can be any integer between 0 and 13. In order to be valid the following relation must be satisfied:
0.95 < (PMUL/AMAX)*2^(4-PDIV) < 1
Thus, for a specified maximum acceleration, this method runs through all possible PMUL and PDIV combinations until a valid combination is found. Then all three values are written to their respective registers.
def stepperdriver.StepperDriver.set_divs | ( | self, | |
pulsediv, | |||
rampdiv | |||
) |
Writes a pulse_div and a ramp_div to the TMC 4210.
The TMC 4210 requires the user to choose a pulse_div and a ramp_div in order to control the motors.
This method allows the user to specify a pulse_div and ramp_div.
def stepperdriver.StepperDriver.set_mode | ( | self, | |
mode | |||
) |
Allows selection of motor mode.
The TMC 4210 has multiple motor modes. By passing in the name of the desired mode, this method puts the motor in that mode.
def stepperdriver.StepperDriver.set_target_pos | ( | self, | |
target_pos | |||
) |
Allows specification of a desired position.
Accepts a desired stepper motor position and writes it to the corresponding register.
def stepperdriver.StepperDriver.set_velocity | ( | self, | |
target_vel | |||
) |
Allows speed control of the stepper motor.
The TMC 4210 allows the user to specify a desired speed at which to spin the motor. This method allows the user to pass in a desired velocity. From there, the method places the stepper motor in velocity mode (the mode necessary for speed control) and writes the desired speed to the corresponding register.
def stepperdriver.StepperDriver.set_vmax | ( | self, | |
vmax | |||
) |
Writes a maximum velocity to the TMC 4210.
The TMC 4210 requires that a maximum velocity for the motor be specified. This method allows for the user to specify one.
def stepperdriver.StepperDriver.set_vmin | ( | self, | |
vmin | |||
) |
Writes a minimum velocity to the TMC 4210.
The TMC 4210 requires that a minimum velocity for the motor be specified. This method allows for the user to specify one.
def stepperdriver.StepperDriver.set_zero | ( | self, | |
offset | |||
) |
Allows user to specify motor starting position.
Allows the user to specify the starting position of the motor if it is imperative that the motor's starting position not be zero microsteps. To do so, the motor is temporarily placed into hold mode (the mode required to set a motor's location), and then the specified location is written to the corrsponding register.
def stepperdriver.StepperDriver.test_version | ( | self | ) |
Allows testing of whether motor is successfuly configured.
This method reads from the TYPE_VERSION register of the TMC 4210. If the value 0x15429101 is read, then the motor is properly configured.
stepperdriver.StepperDriver.A_MAX |
Register for A_MAX.
Register address for A_MAX on the TMC 4210.
stepperdriver.StepperDriver.ENN |
Creares an Enable Pin object.
The TMC 2208 requires that an Enable Pin be specified.
stepperdriver.StepperDriver.IF_CONF |
Register for IF_CONF.
Register address for IF_CONF on the TMC 4210. This is used for inverting the stepper driver direction.
stepperdriver.StepperDriver.nCS |
Creares an chip select pin for the motor.
SPI requires that a chip select pin be designated so that it can distinguish which motor to write information to.
stepperdriver.StepperDriver.PMUL_PDIV |
Register for PMUL_PDIV.
Register address for PMUL_PDIV on the TMC 4210.
stepperdriver.StepperDriver.PULSE_RAMP_DIV |
Register for PULSE_RAMP_DIV.
Register address for PULSE_RAMP_DIV on the TMC 4210.
stepperdriver.StepperDriver.RAMP_MODE |
Register for RAMP_MODE.
Register address for RAMP_MODE on the TMC 4210.
stepperdriver.StepperDriver.RX_buf |
Buffer for receiving data.
Data received from SPI must be read into a buffer. This buffer is created here.
stepperdriver.StepperDriver.spi |
Creares an SPI object.
SPI is used to communicate with the motors.
stepperdriver.StepperDriver.TX_buf |
Buffer for sending data.
Data being sent over SPI must be contained in a buffer. This buffer is created here.
stepperdriver.StepperDriver.TYPE_VERSION |
Register for TYPE_VERSION.
Register address for TYPE_VERSION on the TMC 4210. This address is used primarily to verify that one is successfully communcating with the TMC 4210.
stepperdriver.StepperDriver.V_MAX |
Register for V_MAX.
Register address for V_MAX on the TMC 4210.
stepperdriver.StepperDriver.V_MIN |
Register for V_MIN.
Register address for V_MIN on the TMC 4210.
stepperdriver.StepperDriver.V_TARGET |
Register for V_TARGET.
Register address for V_TARGET on the TMC 4210.
stepperdriver.StepperDriver.X_ACTUAL |
Register for X_ACTUAL.
Register address for X_ACTUAL on the TMC 4210.
stepperdriver.StepperDriver.X_LATCHED |
Register for X_LATCHED.
Register address for X_LATCHED on the TMC 4210.
stepperdriver.StepperDriver.X_TARGET |
Register for X_TARGET.
Register address for X_TARGET on the TMC 4210.