Initial Commit

This commit is contained in:
Michael Pivato
2018-11-01 17:57:10 +10:30
commit d7f7cfe810

41
MotorControl/motor.py Normal file
View File

@@ -0,0 +1,41 @@
import time
from RPi import GPIO
"""This module controls the Motor and Servo module.
This module provides an interface for interacting with
the motor on the Traxxas Slash using a Raspberry Pi
3B+.
"""
class MotorController:
def __init__(self, control_pin, frequency, duty_cycle=0):
self._duty_cycle = duty_cycle
self._operating_frequency = frequency
self._running = False
GPIO.setmode(GPIO.OUT)
GPIO.setup(self._control_pin, self._operating_frequency)
self._control_pin = GPIO.PWM(control_pin, self._duty_cycle)
@property
def duty_cycle(self):
return self._duty_cycle
@duty_cycle.setter
def duty_cycle(self, value):
if value > 0 and value < 100:
self._duty_cycle = value
# Change the current duty cycle of the GPIO.
def start(self):
if self._running:
return
else:
self._control_pin.start(self._duty_cycle)
def stop(self):
self._control_pin.stop()