-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRobotRC.py
More file actions
76 lines (50 loc) · 1.34 KB
/
RobotRC.py
File metadata and controls
76 lines (50 loc) · 1.34 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import RPi.GPIO as GPIO
import numpy
import atexit
class RobotRC :
pwm = -1
fPin = 3
bPin = 5
rPin = 11
lPin = 13
tiltPin = 8
tilt = 0
axisTolerance = 0.5
pinList = [fPin,
bPin,
rPin,
lPin,
tiltPin]
def setup() :
GPIO.setmode(GPIO.BOARD)
GPIO.setup(RobotRC.pinList, GPIO.OUT)
atexit.register(RobotRC.endControl)
return 0
def update(axisX, axisY, tiltUp, tiltDown) :
forward = 0
backward = 0
right = 0
left = 0
if(axisY > RobotRC.axisTolerance) :
backward = 1
elif(axisY < (RobotRC.axisTolerance * -1)) :
forward = 1
if(axisX > RobotRC.axisTolerance) :
right = 1
elif(axisX < (RobotRC.axisTolerance * -1)) :
left = 1
if(tiltUp == 1) :
RobotRC.tilt = 1
if(tiltDown == 1) :
RobotRC.tilt = 0
GPIO.output(RobotRC.fPin, forward)
GPIO.output(RobotRC.bPin, backward)
GPIO.output(RobotRC.rPin, right)
GPIO.output(RobotRC.lPin, left)
GPIO.output(RobotRC.tiltPin, RobotRC.tilt)
return 0
def stop() :
GPIO.output(RobotRC.pinList, 0)
def endControl() :
GPIO.cleanup()
return 0