-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrobot.py
executable file
·112 lines (74 loc) · 1.8 KB
/
robot.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env/python3
# File name : robot.py
# Description : Ctrl Robot
import OLED
import PIPPY
import time
import Voltage
screen = OLED.OLED_ctrl()
screen.start()
# OLED screen ctrl
# screen.screen_show(position, text)
# screen.screen_show(1, 'IP:192.168.12.1')
robotCtrl = PIPPY.PIPPY()
robotCtrl.start()
pitch, roll = 0, 0
def forward(speed=100):
robotCtrl.moveStart(speed, 'forward', 'no')
def backward(speed=100):
robotCtrl.moveStart(speed, 'backward', 'no')
def left(speed=100):
robotCtrl.moveStart(speed, 'no', 'left')
def right(speed=100):
robotCtrl.moveStart(speed, 'no', 'right')
def stop():
lookForward()
robotCtrl.moveStop()
def steadyModeStart():
robotCtrl.functionSelect('steady')
def lookForward():
global pitch, roll
pitch = 0
roll = 0
def lookUp(speed=7):
global pitch
pitchBuffer = pitch + speed
if pitchBuffer < (PIPPY.maxHeight - PIPPY.middleHeight) and pitchBuffer > -(PIPPY.maxHeight - PIPPY.middleHeight):
pitch = pitchBuffer
try:
PIPPY.pitchRoll(pitch, roll)
except:
pass
def lookDown(speed=7):
global pitch
pitchBuffer = pitch - speed
if pitchBuffer < (PIPPY.maxHeight - PIPPY.middleHeight) and pitchBuffer > -(PIPPY.maxHeight - PIPPY.middleHeight):
pitch = pitchBuffer
try:
PIPPY.pitchRoll(pitch, roll)
except:
pass
def leanLeft(speed=7):
global roll
roll += speed
PIPPY.pitchRoll(pitch, roll)
def leanRight(speed=7):
global roll
roll -= speed
PIPPY.pitchRoll(pitch, roll)
def stayLow():
PIPPY.stay(PIPPY.minHeight)
def standUp():
PIPPY.stay(PIPPY.maxHeight)
def getVoltage():
return round(Voltage.measure(), 2)
def getUltrasonic():
return None
if __name__ == '__main__':
# robotCtrl.moveStart(100, 'forward', 'no', 0)
# time.sleep(3)
# robotCtrl.moveStop()
while 1:
print(getVoltage())
time.sleep(1)
pass