ME 405 Romi
Loading...
Searching...
No Matches
motor.py
Go to the documentation of this file.
1from pyb import Pin, Timer
2from time import sleep_ms
3
8class Motor:
9
14 def __init__(self, PWM, DIR, nSLP, timer, ch):
15 #Initializes a Motor object
16 self.nSLP = Pin(nSLP, mode=Pin.OUT_PP, value=0) # Defining left motor pins
17 self.dir = Pin(DIR, mode=Pin.OUT_PP, value=0)
18 self.timCH = timer.channel(ch, pin=PWM, mode=Timer.PWM, pulse_width_percent=0)
19
20
22 def set_effort(self, effort):
23 if effort < 0:
24 self.dir.high()
25 self.timCH.pulse_width_percent(-effort)
26 else:
27 self.dir.low()
28 self.timCH.pulse_width_percent(effort)
29
30
32 def enable(self):
33 self.nSLP.high()
34 self.timCH.pulse_width_percent(0)
35
37 def disable(self):
38 self.nSLP.low()
The Motor Diver Class.
Definition motor.py:8
__init__(self, PWM, DIR, nSLP, timer, ch)
Motor Initialization.
Definition motor.py:14
enable(self)
Enable Enables the motor driver by taking it out of sleep mode into brake mode.
Definition motor.py:32
set_effort(self, effort)
Set Effort Sets the present effort requested from the motor based on an input value between -100 and ...
Definition motor.py:22
disable(self)
Disable Disables the motor driver by taking it into sleep mode.
Definition motor.py:37