ME 405 Portfolio
|
File that controls motors for term project. More...
Functions | |
def | main.linspace (a, b, n) |
Special interpolation function that creates a list of interpolated points excluding the last point. More... | |
def | main.g (x, theta) |
A function computng the difference between a desired location and current location. More... | |
def | main.dg_dtheta (theta) |
A function computng the Jacobian of our Pen Plotter. More... | |
def | main.NewtonRaphson (fcn, jacobian, guess, thresh) |
Determines the motor angles required to achieve a desired x and y position. More... | |
def | main.startup () |
A function that performs all calculations before the motors start drawing. More... | |
def | main.task_main () |
A task that controls the motors to draw the desired shape. More... | |
Variables | |
main.CLK_pin = Pin.cpu.B7 | |
Creates a clock pin. More... | |
main.SPI_CLK_pin = Pin.cpu.B13 | |
Creates an SPI clock pin. More... | |
main.MISO_pin = Pin.cpu.B14 | |
Creates a MISO pin. More... | |
main.MOSI_pin = Pin.cpu.B15 | |
Creates a MOSI pin. More... | |
main.CS1_pin = Pin.cpu.C3 | |
Creates a chip select pin for the first motor. More... | |
main.CS2_pin = Pin.cpu.C2 | |
Creates a chip select pin for the second motor. More... | |
main.ENN1_pin = Pin.cpu.C0 | |
Creates an Enable pin to interface with the first TMC 2208. More... | |
main.ENN2_pin = Pin.cpu.B0 | |
Creates an Enable pin to interface with the second TMC 2208. More... | |
main.tim = pyb.Timer(4, period=3, prescaler=0) | |
Creates timer. More... | |
main.clk = tim.channel(2, pin=CLK_pin, mode=pyb.Timer.PWM, pulse_width=2) | |
Configures the timer. More... | |
main.nCS1 = Pin(CS1_pin, mode=Pin.OUT_PP, value=1) | |
Configures the chip select pin for the first motor. More... | |
main.nCS2 = Pin(CS2_pin, mode=Pin.OUT_PP, value=1) | |
Configures the chip select pin for the second motor. More... | |
main.ENN1 = Pin(ENN1_pin, mode=Pin.OUT_PP, pull=Pin.PULL_NONE) | |
Configures the Enable pin for the first motor. More... | |
main.ENN2 = Pin(ENN2_pin, mode=Pin.OUT_PP, pull=Pin.PULL_NONE) | |
Configures the Enable pin for the second motor. More... | |
main.spi = SPI(2, SPI.MASTER, baudrate=100000, polarity=1, phase=1) | |
Configures SPI. More... | |
main.motor1 = stepperdriver.StepperDriver(nCS1, ENN1, spi, reverse=False) | |
Creates a motor object for the first motor. More... | |
main.motor2 = stepperdriver.StepperDriver(nCS2, ENN2, spi, reverse=False) | |
Creates a motor object for the second motor. More... | |
main.pen = actuator.Actuator() | |
Creates a pen object for the linear actuator. More... | |
def | main.num = startup() |
Number of motor angles. More... | |
main.elements = task_share.Share ('h', thread_protect = False, name = "Elements") | |
A share containing the number of positions. More... | |
main.task1 = cotask.Task(task_main, name='Task_Main', priority=1, period=5, profile=True, trace=False) | |
Creates a task for the main function. More... | |
File that controls motors for term project.
This file performs all operations necessary to control the Pen Plotter such that it draws a desired shape.
It parses the HPGL code, performs selective interpolation, uses a Newton-Raphson method to compute motor angles, and sends motor commands to the motors.
@author Baxter Bartlett @author Jake Lesher @date 6/5/2022
def main.dg_dtheta | ( | theta | ) |
A function computng the Jacobian of our Pen Plotter.
This function is used in compute the Jacobian of our Pen Plotter during Newton-Raphson.
theta | A 2x1 matrix containing the current location for an iteration of Newton-Raphson. |
def main.g | ( | x, | |
theta | |||
) |
A function computng the difference between a desired location and current location.
This function is used in the Netwon-Raphson method to determine when to stop iterating.
x | A 2x1 matrix containing the desired location for a round of Newton-Raphson. |
theta | A 2x1 matrix containing the current position for an iteration of Newton-Raphson. |
def main.linspace | ( | a, | |
b, | |||
n | |||
) |
Special interpolation function that creates a list of interpolated points excluding the last point.
This function interpolates a specified number of points between two points. It then places all those points in a list, but excludes the last point.
a | The first point to interpolate between. |
b | The second point to interpolate between. |
n | Number of points plus one for which the interpolated list should contain. |
def main.NewtonRaphson | ( | fcn, | |
jacobian, | |||
guess, | |||
thresh | |||
) |
Determines the motor angles required to achieve a desired x and y position.
This function uses a Newton-Raphson method to determine the motor angles required to achieve a desired x and y position.
fcn | Placeholder for the difference function (g) to be passed into the function. fcn must be a lambda function that passes the the desired location, effectively making g a function of the motor angles solely. |
jacobian | Passes in the jacobian function. |
guess | A 2x1 matrix containing an initial motor angle guess to start iteration. |
thresh | A number for which g should be less than to stop iteration. |
def main.startup | ( | ) |
A function that performs all calculations before the motors start drawing.
This function is called at the start of the drawing process. It parses the HPGL code, performs selective interpolation, and executes the Newton-Raphon method on every location to obtain the required motor angles. To store the immense amount of data points, two text files are used: one to store interpolated points and one to store points obtained via Newton-Raphson.
def main.task_main | ( | ) |
A task that controls the motors to draw the desired shape.
This function reads from the text file containing the points obtained through the Newton-Raphson method.
It sends these points to the motors if the motors have arrived at the previous position. It also sends pen-up and pen down commands to the linear actuator and writes x location, y location, and arm angle over UART such that a live animation of the robot drawing can be made.
main.clk = tim.channel(2, pin=CLK_pin, mode=pyb.Timer.PWM, pulse_width=2) |
Configures the timer.
The timer is configured as a clock to facillitate data transfer.
main.CLK_pin = Pin.cpu.B7 |
Creates a clock pin.
The clock pin is used to create a timer.
main.CS1_pin = Pin.cpu.C3 |
Creates a chip select pin for the first motor.
The clock pin is used to indicate which motor to read/write from in SPI.
main.CS2_pin = Pin.cpu.C2 |
Creates a chip select pin for the second motor.
The clock pin is used to indicate which motor to read/write from in SPI.
main.elements = task_share.Share ('h', thread_protect = False, name = "Elements") |
A share containing the number of positions.
This share is used to determine when to cease writing motor angles to the motors.
main.ENN1 = Pin(ENN1_pin, mode=Pin.OUT_PP, pull=Pin.PULL_NONE) |
Configures the Enable pin for the first motor.
Configures the Enable pin as a Push-Pull.
main.ENN1_pin = Pin.cpu.C0 |
Creates an Enable pin to interface with the first TMC 2208.
Each motor requires a TMC 2208 IC, which requires an Enable Pin.
main.ENN2 = Pin(ENN2_pin, mode=Pin.OUT_PP, pull=Pin.PULL_NONE) |
Configures the Enable pin for the second motor.
Configures the Enable pin as a Push-Pull.
main.ENN2_pin = Pin.cpu.B0 |
Creates an Enable pin to interface with the second TMC 2208.
Each motor requires a TMC 2208 IC, which requires an Enable Pin.
main.MISO_pin = Pin.cpu.B14 |
Creates a MISO pin.
The pin is used as a MISO line in SPI
main.MOSI_pin = Pin.cpu.B15 |
Creates a MOSI pin.
The pin is used as a MOSI line in SPI
main.motor1 = stepperdriver.StepperDriver(nCS1, ENN1, spi, reverse=False) |
Creates a motor object for the first motor.
Configures the first motor.
main.motor2 = stepperdriver.StepperDriver(nCS2, ENN2, spi, reverse=False) |
Creates a motor object for the second motor.
Configures the second motor.
main.nCS1 = Pin(CS1_pin, mode=Pin.OUT_PP, value=1) |
Configures the chip select pin for the first motor.
Configures the chip select pin as a Push-Pull.
main.nCS2 = Pin(CS2_pin, mode=Pin.OUT_PP, value=1) |
Configures the chip select pin for the second motor.
Configures the chip select pin as a Push-Pull.
def main.num = startup() |
Number of motor angles.
Variable containing the number of positions.
main.pen = actuator.Actuator() |
Creates a pen object for the linear actuator.
Configures the linear actuator.
main.spi = SPI(2, SPI.MASTER, baudrate=100000, polarity=1, phase=1) |
Configures SPI.
Creates an SPI object for SPI between the motors and microcontroller.
main.SPI_CLK_pin = Pin.cpu.B13 |
Creates an SPI clock pin.
The clock pin is used to control the rate that data is sent in SPI.
main.task1 = cotask.Task(task_main, name='Task_Main', priority=1, period=5, profile=True, trace=False) |
Creates a task for the main function.
This task is called by the scheduler.
main.tim = pyb.Timer(4, period=3, prescaler=0) |
Creates timer.
The timer is used to control the rate of data transfer.