104 lines
2.2 KiB
Python
104 lines
2.2 KiB
Python
import time
|
|
from abc import ABC, abstractmethod
|
|
|
|
import MotorControl.servo as servo
|
|
|
|
"""This module controls the Motor and Servo control.
|
|
|
|
This module provides an interface for interacting with
|
|
the motor on the Traxxas Slash using a Raspberry Pi
|
|
3B+.
|
|
"""
|
|
|
|
class Motor(servo.Servo, ABC):
|
|
|
|
@abstractmethod
|
|
def arm(self):
|
|
pass
|
|
|
|
|
|
class MotorController(Motor):
|
|
def __init__(self, pin_number, frequency):
|
|
|
|
|
|
@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.
|
|
self._control_pin.changeDutyCycle(value)
|
|
|
|
def _start(self):
|
|
if self._running:
|
|
return
|
|
else:
|
|
self._control_pin.start(self._duty_cycle)
|
|
|
|
def _stop(self):
|
|
self._control_pin.stop()
|
|
|
|
def arm(self):
|
|
# Set pulse width max
|
|
self._control_pin.start(7.2)
|
|
|
|
# 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 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
|
|
|
|
@percent.setter
|
|
def percent(self, value):
|
|
pass
|
|
|
|
class MotorDetails:
|
|
def __init__(self):
|
|
pass
|
|
|
|
@property
|
|
def minDutyCycle(self):
|
|
return self._minDutyCycle
|
|
|
|
@minDutyCycle.setter
|
|
def minDutyCycle(self, value):
|
|
self._minDutyCycle = value
|
|
|
|
@property
|
|
def maxDutyCycle(self):
|
|
return self._maxDutyCycle
|
|
|
|
@maxDutyCycle.setter
|
|
def maxDutyCycle(self, value):
|
|
self._maxDutyCycle = value
|
|
|
|
@property
|
|
def idle(self):
|
|
return self._idle
|
|
|
|
@idle.setter
|
|
def idle(self, value):
|
|
self._idle = value
|
|
|
|
class Connection:
|
|
def __init__(self):
|
|
pass
|
|
|
|
|