From d7f7cfe810e39fdcadebb833bea1ac87b526104b Mon Sep 17 00:00:00 2001 From: Michael Pivato Date: Thu, 1 Nov 2018 17:57:10 +1030 Subject: [PATCH] Initial Commit --- MotorControl/motor.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 MotorControl/motor.py diff --git a/MotorControl/motor.py b/MotorControl/motor.py new file mode 100644 index 0000000..a2258f5 --- /dev/null +++ b/MotorControl/motor.py @@ -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() + + \ No newline at end of file