File size: 13,536 Bytes
0e83c90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
import sys
from dataclasses import dataclass

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import keyboard

import DroneController  # 假设只需要无人机控制

# mobile configuration
@dataclass
class Vehicle():
    acc = 1
    vehicle_type = 'drone'  # 设置为无人机模式

veh = Vehicle()

# form application #
app = QApplication(sys.argv)

class AirDroneClientWindow(QWidget):
    button_takeoff = QPushButton()
    button_land = QPushButton()
    button_up = QPushButton()
    button_down = QPushButton()
    
    button_f = QPushButton()
    button_b = QPushButton()
    button_l = QPushButton()
    button_r = QPushButton()
    
    button_weather = QPushButton()
    button_task = QPushButton()
    button_algorithm = QPushButton()
    button_formation = QPushButton()
    button_keyboard = QPushButton()
    
    weather_selection = QComboBox()
    
    label_gps_alt = QLabel()
    label_gps_lat = QLabel()
    label_gps_lon = QLabel()
    label_rot_w = QLabel()
    label_rot_y = QLabel()
    label_rot_z = QLabel()
    label_speed = QLabel()
    label_angle_speed = QLabel()

    refreshinfo = QTimer()

    def initUI(self):
        self.resize(500, 400)  # 调整为更合适的尺寸
        self.setWindowTitle("U21Data-2 Client")

        #self.set_background()

        self.setObjectName("AirDroneClientWindow")  # 设置对象名称匹配选择器
    

        self.setStyleSheet(self.styleSheet())

        # 主垂直布局
        main_layout = QVBoxLayout()
        
        # 添加Start Point部分
        start_group = QGroupBox("Start Point")
        start_layout = QHBoxLayout()

        self.start_combo = QComboBox()
        self.start_combo.setEditable(True)
        self.start_combo.lineEdit().setReadOnly(True)
        self.start_combo.lineEdit().setAlignment(Qt.AlignCenter)
        self.start_combo.addItems(["9.8, -279, -22", "213, -429, 19","-315, -444, 12", "-335, 282, 19", "-152, 236, 66", "-430, -91, 13"])
        self.start_combo.setCurrentIndex(-1)
        self.start_combo.lineEdit().setPlaceholderText("StartPoint")
    

        self.weather_selection = QComboBox()
        self.weather_selection.setEditable(True)
        self.weather_selection.lineEdit().setReadOnly(True)
        self.weather_selection.lineEdit().setAlignment(Qt.AlignCenter)
        self.weather_selection.addItems(["Clear", "Rain", "Snow", "Fog", "Overcast","Sand"])
        self.weather_selection.setCurrentIndex(-1)
        self.weather_selection.lineEdit().setPlaceholderText("Weather")
    
        for widget in [self.start_combo, self.weather_selection]:
            widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
    
        start_layout.addWidget(self.start_combo)
        start_layout.addWidget(self.weather_selection)
        start_group.setLayout(start_layout)
        
        # 添加功能按钮部分
        func_group = QGroupBox("Functions")
        func_layout = QHBoxLayout()
    
        self.button_keyboard = QComboBox()
        self.button_keyboard.setEditable(True)
        self.button_keyboard.lineEdit().setReadOnly(True)
        self.button_keyboard.lineEdit().setAlignment(Qt.AlignCenter)
        self.button_keyboard.addItems(["Yes", "No"])
        self.button_keyboard.setCurrentIndex(-1)
        self.button_keyboard.lineEdit().setPlaceholderText("Task")



        #Task
        self.task_combo = QComboBox()
        self.task_combo.setEditable(True)  # 设置为可编辑
        self.task_combo.lineEdit().setReadOnly(True)  # 设置行编辑为只读
        self.task_combo.lineEdit().setAlignment(Qt.AlignCenter)  # 文字居中
        self.task_combo.addItems(["Task 1", "Task 2", "Task 3"])
        self.task_combo.setCurrentIndex(-1)  # 不选中任何项
        self.task_combo.lineEdit().setPlaceholderText("Task")

    
        # 设置Algorithm下拉框选项
        self.algorithm_combo = QComboBox()
        self.algorithm_combo.setEditable(True)  # 设置为可编辑
        self.algorithm_combo.lineEdit().setReadOnly(True)  # 设置行编辑为只读
        self.algorithm_combo.lineEdit().setAlignment(Qt.AlignCenter)  # 文字居中
        self.algorithm_combo.addItems(["Algorithm 1", "Algorithm 2", "Algorithm 3"])
        self.algorithm_combo.setCurrentIndex(-1)  # 不选中任何项
        self.algorithm_combo.lineEdit().setPlaceholderText("Algorithm")  # 设置占位文本

        # 设置Formation下拉框选项
        self.formation_combo = QComboBox()
        self.formation_combo.setEditable(True)
        self.formation_combo.lineEdit().setReadOnly(True)
        self.formation_combo.lineEdit().setAlignment(Qt.AlignCenter)
        self.formation_combo.addItems(["Line Formation", "V Formation", "Square Formation", "Circle Formation"])
        self.formation_combo.setCurrentIndex(-1)
        self.formation_combo.lineEdit().setPlaceholderText("Formation")
    
        # 设置控件大小策略
        for widget in [self.task_combo, self.algorithm_combo, 
                       self.formation_combo, self.button_keyboard]:
            widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
    
        # 添加控件到布局
        func_layout.addWidget(self.task_combo)
        func_layout.addWidget(self.algorithm_combo)
        func_layout.addWidget(self.formation_combo)
        func_layout.addWidget(self.button_keyboard)
        func_group.setLayout(func_layout)
        
        # 添加飞行控制部分
        flight_group = QGroupBox("Flight Controls")
        flight_layout = QVBoxLayout()

        # 将Takeoff, Land, Up, Down四个按钮放在同一行
        top_row_layout = QHBoxLayout()
        self.button_takeoff = QPushButton("Takeoff")
        self.button_land = QPushButton("Land")
        self.button_up = QPushButton("Up")
        self.button_down = QPushButton("Down")

        # 设置按钮大小策略,使它们均匀分布
        for button in [self.button_takeoff, self.button_land, 
                       self.button_up, self.button_down]:
            button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        top_row_layout.addWidget(self.button_takeoff)
        top_row_layout.addWidget(self.button_land)
        top_row_layout.addWidget(self.button_up)
        top_row_layout.addWidget(self.button_down)
        top_row_layout.setSpacing(5)  # 设置按钮间距
        
        # 前后左右
        move_layout = QGridLayout()
        self.button_f = QPushButton("Move Forward")
        self.button_b = QPushButton("Move Backward")
        self.button_l = QPushButton("Move Left")
        self.button_r = QPushButton("Move Right")
        move_layout.addWidget(self.button_f, 0, 1)
        move_layout.addWidget(self.button_b, 2, 1)
        move_layout.addWidget(self.button_l, 1, 0)
        move_layout.addWidget(self.button_r, 1, 2)

        flight_layout.addLayout(top_row_layout)
        flight_layout.addLayout(move_layout)
        flight_group.setLayout(flight_layout)
        
        # 添加日志信息部分
        log_group = QGroupBox("Log")
        log_layout = QVBoxLayout()
        self.label_gps_alt = QLabel("GPS Altitude: ")
        self.label_gps_lat = QLabel("GPS Latitude: ")
        self.label_gps_lon = QLabel("GPS Longitude: ")
        self.label_rot_w = QLabel("Rotation w: ")
        self.label_rot_y = QLabel("Rotation y: ")
        self.label_rot_z = QLabel("Rotation z: ")
        self.label_speed = QLabel("Linear Speed: ")
        self.label_angle_speed = QLabel("Angle Speed: ")
        
        log_layout.addWidget(self.label_gps_alt)
        log_layout.addWidget(self.label_gps_lat)
        log_layout.addWidget(self.label_gps_lon)
        log_layout.addWidget(self.label_rot_w)
        log_layout.addWidget(self.label_rot_y)
        log_layout.addWidget(self.label_rot_z)
        log_layout.addWidget(self.label_speed)
        log_layout.addWidget(self.label_angle_speed)
        log_group.setLayout(log_layout)
        
        # 将所有组添加到主布局
        main_layout.addWidget(start_group)
        main_layout.addWidget(func_group)
        main_layout.addWidget(flight_group)
        main_layout.addWidget(log_group)
        
        self.setLayout(main_layout)
        
        # 连接信号槽
        self.button_takeoff.clicked.connect(DroneController.dronecontrol.TakeOff)
        self.button_land.clicked.connect(DroneController.dronecontrol.Landed)
        self.button_up.clicked.connect(self.up)
        self.button_down.clicked.connect(self.down)
        self.button_f.pressed.connect(self.forward)
        self.button_b.pressed.connect(self.backward)
        self.button_l.pressed.connect(self.left)
        self.button_r.pressed.connect(self.right)
        self.button_f.released.connect(self.stop)
        self.button_b.released.connect(self.stop)
        self.button_l.released.connect(self.stop)
        self.button_r.released.connect(self.stop)
        self.button_keyboard.currentIndexChanged.connect(self.EnableKeyboard)
        self.weather_selection.currentIndexChanged.connect(self.change_weather)
        self.algorithm_combo.currentIndexChanged.connect(self.on_algorithm_changed)
        self.formation_combo.currentIndexChanged.connect(self.on_formation_changed)
        self.task_combo.currentIndexChanged.connect(self.on_task_changed)
        self.start_combo.currentIndexChanged.connect(self.on_start_changed)
        
        # 自动刷新信息
        self.refreshinfo.start(1000)
        self.refreshinfo.timeout.connect(self.setInfo)

        self.show()

    def setInfo(self):
        self.label_gps_alt.setText("GPS Altitude: " + str(DroneController.dronecontrol.GetState().gps_pos_altitude))
        self.label_gps_lat.setText("GPS Latitude: " + str(DroneController.dronecontrol.GetState().gps_pos_latitude))
        self.label_gps_lon.setText("GPS Longitude: " + str(DroneController.dronecontrol.GetState().gps_pos_longitude))
        
        self.label_rot_w.setText("Rotation w: " + str(DroneController.dronecontrol.GetState().ori_x))
        self.label_rot_y.setText("Rotation y: " + str(DroneController.dronecontrol.GetState().ori_y))
        self.label_rot_z.setText("Rotation z: " + str(DroneController.dronecontrol.GetState().ori_z))
        
        self.label_speed.setText("Linear Speed: " + str(DroneController.dronecontrol.GetState().linear_speed))
        self.label_angle_speed.setText("Angle Speed: " + str(DroneController.dronecontrol.GetState().a_v_x))

    # 移动功能
    def forward(self):
        DroneController.dronecontrol.DroneMoveByTime(veh.acc, 0, 0)

    def backward(self):
        DroneController.dronecontrol.DroneMoveByTime(-veh.acc, 0, 0)

    def left(self):
        DroneController.dronecontrol.DroneMoveByTime(0, -veh.acc, 0)

    def right(self):
        DroneController.dronecontrol.DroneMoveByTime(0, veh.acc, 0)

    def stop(self):
        pass

    def up(self):
        DroneController.dronecontrol.DroneMoveByTime(0, 0, -veh.acc)

    def down(self):
        DroneController.dronecontrol.DroneMoveByTime(0, 0, veh.acc)
        
    def change_weather(self, index):
        if index >= 0:
            weather = self.weather_selection.currentText()
            if weather == "Snow":
                DroneController.dronecontrol.SnowTeleport()
            elif weather == "Rain":
                DroneController.dronecontrol.RainTeleport()
            elif weather == "Fog":
                DroneController.dronecontrol.FogTeleport()
            elif weather == "Overcast":
                DroneController.dronecontrol.OvercastTeleport()
            elif weather == "Clear":
                DroneController.dronecontrol.ClearTeleport()
            elif weather == "Sand":
                DroneController.dronecontrol.SandTeleport()

    def on_algorithm_changed(self, index):
        """Algorithm下拉框选择变化时的处理"""
        if index >= 0:
            selected_algorithm = self.algorithm_combo.currentText()
            print(f"Selected Algorithm: {selected_algorithm}")


    def on_formation_changed(self, index):
        """Formation下拉框选择变化时的处理"""
        if index >= 0:
            selected_formation = self.formation_combo.currentText()
            print(f"Selected Formation: {selected_formation}")


    def on_task_changed(self, index):
        """Task下拉框选择变化时的处理"""
        if index >= 0:
            selected_task = self.task_combo.currentText()
            print(f"Selected Task: {selected_task}")


    def on_start_changed(self, index):
        if index >= 0:
            pos = self.start_combo.currentText()
            if pos == "9.8, -279, -22":
                DroneController.dronecontrol.SnowTeleport()
            elif pos == "213, -429, 19":
                DroneController.dronecontrol.OvercastTeleport()
            elif pos == "-315, -444, 12":
                DroneController.dronecontrol.RainTeleport()
            elif pos == "-335, 282, 19":
                DroneController.dronecontrol.SandTeleport()
            elif pos == "-152, 236, 66":
                DroneController.dronecontrol.ClearTeleport()
            elif pos == "-430, -91, 13":
                DroneController.dronecontrol.FogTeleport()
            else:
                print(self.start_combo.currentIndex())

    def EnableKeyboard(self):
        keyboard.hook(DroneController.dronecontrol.KeyboardControl)
        keyboard.wait()

window = AirDroneClientWindow()
window.initUI()
window.setInfo()
sys.exit(app.exec())