-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
126 lines (111 loc) · 2.18 KB
/
client.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python # This is client.py file
import socket # Import socket module
#import time
import json
from Tkinter import *
s = socket.socket() # Create a socket object
#host = '192.168.1.37' # Get local machine name
host = 'raspberrypi.local' # Get local machine name
port = 12345 # Reserve a port for your service.
s.connect((host, port))
run = False
TUNE_MESSAGE = 4
def show_values():
msg = {
'height': pitch.get(),
'roll': roll.get(),
'PR': PR.get(),
'P': P.get(),
'I': I.get(),
'D': D.get(),
'trim_x': trim_x.get(),
'trim_y': trim_y.get(),
'run': run}
msg1 = json.dumps(msg)
print msg1
s.send(msg1)
def stop():
global run
run = False
def reset():
s.send(json.dumps({'reset': True}))
def start():
global run
run = True
master = Tk()
pitch = Scale(master, from_=0, to=100, tickinterval=10)
PR = Scale(
master,
from_=0,
to=500,
tickinterval=100,
label='P',
orient=HORIZONTAL,
length=600)
P = Scale(
master,
from_=0,
to=500,
tickinterval=100,
label='P',
orient=HORIZONTAL,
length=600)
I = Scale(
master,
from_=0,
to=500,
tickinterval=100,
label='I',
resolution=0.01,
orient=HORIZONTAL,
length=600)
D = Scale(
master,
from_=0,
to=500,
tickinterval=100,
label='D',
orient=HORIZONTAL,
length=600)
PR.set(0)
P.set(0)
I.set(0)
D.set(0)
PR.pack()
P.pack()
I.pack()
D.pack()
pitch.set(5)
pitch.pack()
roll = Scale(
master,
from_=0,
to=100,
length=600,
tickinterval=10,
orient=HORIZONTAL)
roll.set(5)
roll.pack()
trim_x = Scale(
master,
from_=-100,
to=100,
length=600,
tickinterval=10,
orient=HORIZONTAL)
trim_x.set(0)
trim_x.pack()
trim_y = Scale(
master,
from_=-100,
to=100,
length=600,
tickinterval=10,
orient=HORIZONTAL)
trim_y.set(0)
trim_y.pack()
Button(master, text='Show', command=show_values).pack()
Button(master, text='Stop', command=stop).pack()
Button(master, text='Reset', command=reset).pack()
mainloop()
s.close # Close the socket when done