-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainClient.py
38 lines (30 loc) · 977 Bytes
/
mainClient.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
import joystick
import sys
import time
from multiprocessing.connection import Client
# Mars Rover main client module
# Sets up a joystick and sends input
# over internet to rover unit
# Sets up client to connect with the server
client = Client(('192.168.0.27', 10003))
# Initialize joystick
joystick = joystick.Joystick()
if not joystick.isInitialized:
print("Joystick failed initialization:", joystick.initializationError)
exit
print("Press and hold button 11 to stop.")
# Note that button 10 is labeled 11 on the joystick.
while not joystick.isButtonPressed(10):
x, y, z = joystick.getAxes()
data = [x,y,z]
print("" + str(data)) #Test
client.send(data)
time.sleep(0.1) # Set to .1 seconds to send data only every 100 ms to keep from exceeding wifi capabilities
# Close socket and notify user and server of stoppage
print("STOPPED!")
x = 2
y = 2
z = 2
data = [x,y,z]
client.send(data)
client.close()