working mpc with L293D motor driver
This commit is contained in:
parent
2711373d44
commit
7d69c91752
|
@ -12,7 +12,7 @@ class Motor:
|
||||||
def __init__(self, enable, dir1, dir2):
|
def __init__(self, enable, dir1, dir2):
|
||||||
self.enable_pin = machine.Pin(enable, machine.Pin.OUT)
|
self.enable_pin = machine.Pin(enable, machine.Pin.OUT)
|
||||||
self.enable_pwm = machine.PWM(self.enable_pin)
|
self.enable_pwm = machine.PWM(self.enable_pin)
|
||||||
self.enable_pwm.freq(500)
|
self.enable_pwm.freq(250)
|
||||||
|
|
||||||
self.dir1_pin = machine.Pin(dir1, machine.Pin.OUT)
|
self.dir1_pin = machine.Pin(dir1, machine.Pin.OUT)
|
||||||
self.dir2_pin = machine.Pin(dir2, machine.Pin.OUT)
|
self.dir2_pin = machine.Pin(dir2, machine.Pin.OUT)
|
||||||
|
@ -33,7 +33,7 @@ class Motor:
|
||||||
if self.direction: # switch direction if necessary
|
if self.direction: # switch direction if necessary
|
||||||
self.reverse()
|
self.reverse()
|
||||||
# apply value as pwm signal
|
# apply value as pwm signal
|
||||||
self.enable_pwm.duty(abs(value)*10)
|
self.enable_pwm.duty(int(abs(value)*10.23))
|
||||||
|
|
||||||
|
|
||||||
class Robot:
|
class Robot:
|
||||||
|
|
|
@ -210,7 +210,7 @@ class OpenLoopSolver:
|
||||||
# ---- path constraints -----------
|
# ---- path constraints -----------
|
||||||
# limit = lambda pos: 1-sin(2*pi*pos)/2
|
# limit = lambda pos: 1-sin(2*pi*pos)/2
|
||||||
# self.opti.subject_to(speed<=limit(pos)) # track speed limit
|
# self.opti.subject_to(speed<=limit(pos)) # track speed limit
|
||||||
maxcontrol = 0.5
|
maxcontrol = 0.950
|
||||||
self.opti.subject_to(self.opti.bounded(-maxcontrol, self.U, maxcontrol)) # control is limited
|
self.opti.subject_to(self.opti.bounded(-maxcontrol, self.U, maxcontrol)) # control is limited
|
||||||
|
|
||||||
# ---- boundary conditions --------
|
# ---- boundary conditions --------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user