-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard_controller.py
48 lines (46 loc) · 1.3 KB
/
keyboard_controller.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
#import rospy
import time
import locale
import curses
import sys
from pySpacebrew.spacebrew import Spacebrew
if __name__ == "__main__":
name = "Keyboard Controller"
server = "sandbox.spacebrew.cc"
brew = Spacebrew(name=name, server=server)
brew.addPublisher("cmd", "string")
try:
# start-up spacebrew
brew.start()
locale.setlocale(locale.LC_ALL, '')
code = locale.getpreferredencoding()
#rate = rospy.Rate(1.0)
# initialize the terminal display
stdscr = curses.initscr()
curses.halfdelay(2)
stdscr.keypad(1)
#curses.noecho() # turn off echo
curses.curs_set(0) # turn off cursor
while 1:
c = stdscr.getch()
if (c == 119):
brew.publish('cmd', 'w')
elif (c == 115):
brew.publish('cmd', 's')
elif (c == 97):
brew.publish('cmd', 'a')
elif (c == 100):
brew.publish('cmd', 'd')
elif (c == 120):
break
else:
brew.publish('cmd', 'nan')
#time.sleep(0.5)
except KeyboardInterrupt:
pass
finally:
brew.stop()
curses.nocbreak()
stdscr.keypad(0)
#curses.echo()
curses.endwin()