-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCANE-client.py
More file actions
76 lines (57 loc) · 1.67 KB
/
CANE-client.py
File metadata and controls
76 lines (57 loc) · 1.67 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
from bluetooth import *
import sys
import random
from src.newUltrasonic import *
from src.dummySound import *
from src.laserSensor import *
#host_address = "B8:27:EB:6E:D4:DF"
host_address = "B8:27:EB:D4:16:2E"
port = 1
sideOpt = DistanceOptions()
sideOpt.minDistance = 0.02
sideOpt.maxDistance = 1.0
sideOpt.inverseConstant = 0.7
frontOpt = DistanceOptions()
frontOpt.minDistance = 0.10
frontOpt.maxDistance = 3.5
frontOpt.inverseConstant = 1
frontOpt.frontSensor = True
sound = DummySoundThread(2)
sideLeftSM = UltrasonicStateMachine(24, 12, sideOpt)
frontLeftSM = UltrasonicStateMachine(24, 5, frontOpt)
thread = UltrasonicThread([sideLeftSM, frontLeftSM],
[sound, sound ])
laser = LaserSensor()
def main():
global sock
thread.start()
# Create the client socket
sock = BluetoothSocket( RFCOMM )
sock.connect((host_address, port))
print("Connected")
while True:
processCommand(sock.recv(1024))
sock.close()
def processCommand(command):
global sock
print("received command: " + str(command))
if command == "getDropOff":
sock.send(boolToString(getDropOffStatus()))
elif command == "getSideUltrasonic":
sock.send(getSideUltrasonicStatus())
elif command == "getFrontUltrasonic":
sock.send(getFrontUltrasonicStatus())
return;
def getDropOffStatus():
return laser.status()
# Convert a boolean into a YES or NO string
def boolToString(statusBool):
if statusBool:
return "YES"
else:
return "NO"
def getSideUltrasonicStatus():
return str(sound.frequencies[0])
def getFrontUltrasonicStatus():
return str(sound.frequencies[1])
main()