|
|
| controller.encAPin1 = pyb.Pin(pyb.Pin.cpu.B6) |
| |
|
| controller.encAPin2 = pyb.Pin(pyb.Pin.cpu.B7) |
| |
|
| controller.tim4 = pyb.Timer(4, period = 65535, prescaler = 0) |
| |
|
| controller.encoderA = Encoder(encAPin1, encAPin2, tim4) |
| |
|
| controller.tim3 = pyb.Timer(3, freq = 20000); |
| |
|
| controller.pin_nSLEEP = pyb.Pin(pyb.Pin.cpu.A15, mode=pyb.Pin.OUT_PP, value=1); |
| |
|
| controller.pin_IN1 = pyb.Pin(pyb.Pin.cpu.B4); |
| |
|
| controller.pin_IN2 = pyb.Pin(pyb.Pin.cpu.B5); |
| |
|
| controller.motorA = Motor(pin_nSLEEP, pin_IN1, 1, pin_IN2, 2, tim3) |
| |
|
int | controller.kpA = 50 |
| |
|
int | controller.kiA = 1 |
| |
|
int | controller.kdA = 0 |
| |
|
| controller.pidA = ClosedLoop(kp = kpA, ki = kiA, kd = kdA, sat = 75) |
| |
|
| controller.controllerA = Controller(motorA, encoderA, pidA) |
| |
|
| controller.encBPin1 = pyb.Pin(pyb.Pin.cpu.C6) |
| |
|
| controller.encBPin2 = pyb.Pin(pyb.Pin.cpu.C7) |
| |
|
| controller.tim8 = pyb.Timer(8, period = 65535, prescaler = 0) |
| |
|
| controller.encoderB = Encoder(encBPin1, encBPin2, tim8) |
| |
|
| controller.pin_IN3 = pyb.Pin(pyb.Pin.cpu.B0) |
| |
|
| controller.pin_IN4 = pyb.Pin(pyb.Pin.cpu.B1) |
| |
|
| controller.motorB = Motor(pin_nSLEEP, pin_IN3, 3, pin_IN4, 4, tim3) |
| |
|
int | controller.kpB = 50 |
| |
|
int | controller.kiB = 1 |
| |
|
int | controller.kdB = 0 |
| |
|
| controller.pidB = ClosedLoop(kp = kpB, ki = kiB, kd = kdB, sat = 75) |
| |
|
| controller.controllerB = Controller(motorB, encoderB, pidB) |
| |
|
| controller.prevTime = utime.ticks_ms() |
| |
a controller task for controlling a motor using PID.
The controller task is a state machine that uses closed loop feedback to move a motor along a reference path and velocity. The controller task also has several methods, selfTune, step, and ramp, for automatically tunning the PID gains and are not implemented as part of the state machine. These methods are only for debugging and tuning and should not be run with this, or any other state machine, as they will pause the program until complete. Link to source code: https://bitbucket.org/ebriefer/me305_lab/src/master/Final%20Project/controller.py
- Author
- Eliot Briefer