-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobotController.py
executable file
·64 lines (54 loc) · 1.49 KB
/
robotController.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
#!/usr/bin/python
#Import stuff
import json
import RPi.GPIO as GPIO
import time
from pySpacebrew.spacebrew import Spacebrew
#str2bool
def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")
#gogo
print "Booting up robot"
print "Configuring GPIO Pins"
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(23, GPIO.OUT)
time.sleep(1)
print "Opening Configuration"
config = open('robotConfig.txt','r')
jsonData = json.load(config)
print "Robot loaded as: " + str(jsonData["robotName"])
#print "Checking if wi-fi configuration needs changing"
#if(jsonData['wifi-update']==1):
# print"Updating Wi-Fi"
print "Attempting to connect to spacebrew server: " + str(jsonData["robotServer"])
brew = Spacebrew(name=str(jsonData["robotName"]), server=str(jsonData["robotServer"]))
#configure motors
brew.addSubscriber("motor1a","boolean")
brew.addSubscriber("motor1b","boolean")
brew.addSubscriber("motor2a","boolean")
brew.addSubscriber("motor2b","boolean")
#define functions
def motor1a(state):
GPIO.output(17,str2bool(state))
def motor1b(state):
GPIO.output(18,str2bool(state))
def motor2a(state):
GPIO.output(22,str2bool(state))
def motor2b(state):
GPIO.output(23,str2bool(state))
#add listeners
brew.subscribe("motor1a", motor1a)
brew.subscribe("motor1b", motor1b)
brew.subscribe("motor2a", motor2a)
brew.subscribe("motor2b", motor2b)
try:
brew.start()
print "Spacebrew Started"
while 1:
pass
finally:
brew.stop()
GPIO.cleanup()