Add servo inheritance hierarchy to motor control
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import time
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from RPi import GPIO
|
||||
|
||||
import MotorControl.servo as servo
|
||||
|
||||
"""This module controls the Motor and Servo control.
|
||||
|
||||
This module provides an interface for interacting with
|
||||
@@ -9,16 +12,23 @@ the motor on the Traxxas Slash using a Raspberry Pi
|
||||
3B+.
|
||||
"""
|
||||
|
||||
class MotorController:
|
||||
class Motor(servo.Servo, ABC):
|
||||
|
||||
@abstractmethod
|
||||
def arm(self):
|
||||
pass
|
||||
|
||||
|
||||
class MotorController(Motor):
|
||||
def __init__(self, pin_number, frequency, duty_cycle=0):
|
||||
self._duty_cycle = duty_cycle
|
||||
self._operating_frequency = frequency
|
||||
self._running = False
|
||||
self.pin_number = pin_number
|
||||
|
||||
# Pulse width was mentioned to be 6-7.2% by uni group.
|
||||
# Operating Frequency should be 50Hz
|
||||
|
||||
GPIO.setmode(GPIO.OUT)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setup(self.pin_number, self._operating_frequency)
|
||||
self._control_pin = GPIO.PWM(self.pin_number, self._duty_cycle)
|
||||
|
||||
@@ -32,36 +42,43 @@ class MotorController:
|
||||
if value > 0 and value < 100:
|
||||
self._duty_cycle = value
|
||||
# Change the current duty cycle of the GPIO.
|
||||
self._control_pin.changeDutyCycle
|
||||
self._control_pin.changeDutyCycle(value)
|
||||
|
||||
def start(self):
|
||||
def _start(self):
|
||||
if self._running:
|
||||
return
|
||||
else:
|
||||
self._control_pin.start(self._duty_cycle)
|
||||
|
||||
def stop(self):
|
||||
def _stop(self):
|
||||
self._control_pin.stop()
|
||||
|
||||
def arm(self):
|
||||
# Set pulse width 0
|
||||
# Set pulse width max
|
||||
self._control_pin.start(7.2)
|
||||
|
||||
|
||||
# Wait 1s
|
||||
|
||||
# Set pulse width to maximum
|
||||
|
||||
# Wait 1s
|
||||
# Now wait until ESC is turned on.
|
||||
input("Please turn on the ESC, then press enter")
|
||||
|
||||
# set pulse width minimum
|
||||
|
||||
self._control_pin.ChangeDutyCycle(6)
|
||||
# Wait 1s
|
||||
|
||||
# Set pulse width to idle
|
||||
# Set middle.
|
||||
self._control_pin.ChangeDutyCycle(6.6)
|
||||
# Also try setting to max again if necessary, once it's tested again.
|
||||
|
||||
# Stop the control pin (set it to idle).
|
||||
self._control_pin.stop()
|
||||
|
||||
# Now just start the control pin to use the slash, by setting the throttle.
|
||||
|
||||
@property
|
||||
def percent(self):
|
||||
pass
|
||||
|
||||
def setThrottle(self, throttle: float):
|
||||
@percent.setter
|
||||
def percent(self, value):
|
||||
pass
|
||||
|
||||
class MotorDetails:
|
||||
|
||||
Reference in New Issue
Block a user