-
Notifications
You must be signed in to change notification settings - Fork 2
/
motors.py
executable file
·49 lines (33 loc) · 1.31 KB
/
motors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gpiozero
from utils import Pinout
from gpiozero.pins.pigpio import PiGPIOFactory
factory = PiGPIOFactory(host='localhost')
M1_FORWARDPIN = Pinout.PIN_MOTORLEFT1
M1_BACKWARDPIN = Pinout.PIN_MOTORLEFT2
M1_ENABLEPIN = None
M2_FORWARDPIN = Pinout.PIN_MOTORRIGHT1
M2_BACKWARDPIN = Pinout.PIN_MOTORRIGHT2
M2_ENABLEPIN = None
USING_PWM = True
class MotorController:
#speed = 0.9
speed = 1.0
robot = None
def begin():
MotorController.robot = gpiozero.Robot(left=(M1_FORWARDPIN, M1_BACKWARDPIN), right=(M2_FORWARDPIN, M2_BACKWARDPIN), pwm=USING_PWM, pin_factory=factory)
def forward():
MotorController.robot.forward(speed=MotorController.speed)
def backward():
MotorController.robot.backward(speed=MotorController.speed)
def right():
MotorController.robot.right(speed=MotorController.speed)
def left():
MotorController.robot.left(speed=MotorController.speed)
def stop():
MotorController.robot.stop()
def customControl(speeds):
MotorController.robot.value = speeds
def customLeftMotor(speed):
MotorController.robot.left_motor.value = speed
def customRightMotor(speed):
MotorController.robot.right_motor.value = speed