46
46
from cfclient .ui .tab import Tab
47
47
from cfclient .utils .config import Config
48
48
from cflib .crazyflie .log import LogConfig
49
- from cflib .crazyflie .syncCrazyflie import SyncCrazyflie
50
49
from cflib .crazyflie .syncLogger import SyncLogger
51
50
52
51
import xml .etree .cElementTree as ET
@@ -192,8 +191,7 @@ def __init__(self, tabWidget, helper, *args):
192
191
self .qtm_6DoF_labels = None
193
192
self ._helper = helper
194
193
self ._qtm_connection = None
195
- self .scf = None
196
- self .uri = "80/2M"
194
+ self ._cf = None
197
195
self .model = QStandardItemModel (10 , 4 )
198
196
199
197
self ._cf_status = self .cfStatusLabel .text ()
@@ -735,7 +733,7 @@ def set_path_mode(self):
735
733
self .switch_flight_mode (FlightModeStates .PATH )
736
734
737
735
def set_kill_engine (self ):
738
- self .send_setpoint (self . scf , Position (0 , 0 , 0 ))
736
+ self .send_setpoint (Position (0 , 0 , 0 ))
739
737
self .switch_flight_mode (FlightModeStates .GROUNDED )
740
738
logger .info ('Stop button pressed, kill engines' )
741
739
@@ -905,12 +903,12 @@ def on_packet(self, packet):
905
903
except ValueError as err :
906
904
self .qtmStatus = ' : connected : No 6DoF body found'
907
905
908
- if self .scf is not None and self .cf_pos .is_valid ():
909
- # If a scf (syncronous Crazyflie) exists and the position is valid
906
+ if self ._cf is not None and self .cf_pos .is_valid ():
907
+ # If a cf exists and the position is valid
910
908
# Feed the current position of the cf back to the cf to
911
909
# allow for self correction
912
- self .scf . cf .extpos .send_extpos (self .cf_pos .x , self .cf_pos .y ,
913
- self .cf_pos .z )
910
+ self ._cf .extpos .send_extpos (self .cf_pos .x , self .cf_pos .y ,
911
+ self .cf_pos .z )
914
912
915
913
def _update_ui (self ):
916
914
# Update the data in the GUI
@@ -993,16 +991,10 @@ def _flight_mode_disconnected_entered(self):
993
991
994
992
def flight_controller (self ):
995
993
try :
996
- _scf = SyncCrazyflie ( "radio://0/{}" . format ( self . uri ),
997
- self ._helper . cf )
994
+ self . _cf . param . set_value ( 'stabilizer.estimator' , '2' )
995
+ self .reset_estimator ( self . _cf )
998
996
999
- # init scf
1000
- self .scf = _scf
1001
- cf = self .scf .cf
1002
- cf .param .set_value ('stabilizer.estimator' , '2' )
1003
- self .reset_estimator (self .scf )
1004
-
1005
- cf .param .set_value ('flightmode.posSet' , '1' )
997
+ self ._cf .param .set_value ('flightmode.posSet' , '1' )
1006
998
1007
999
time .sleep (0.1 )
1008
1000
@@ -1045,7 +1037,6 @@ def flight_controller(self):
1045
1037
if self .flight_mode == FlightModeStates .LAND :
1046
1038
1047
1039
self .send_setpoint (
1048
- self .scf ,
1049
1040
Position (
1050
1041
self .current_goal_pos .x ,
1051
1042
self .current_goal_pos .y ,
@@ -1062,7 +1053,7 @@ def flight_controller(self):
1062
1053
self .land_rate *= 1.1
1063
1054
1064
1055
if self .land_rate > 1000 :
1065
- self .send_setpoint (self . scf , Position (0 , 0 , 0 ))
1056
+ self .send_setpoint (Position (0 , 0 , 0 ))
1066
1057
if self .land_for_recording :
1067
1058
# Return the control to the recording mode
1068
1059
# after landing
@@ -1075,7 +1066,7 @@ def flight_controller(self):
1075
1066
1076
1067
elif self .flight_mode == FlightModeStates .PATH :
1077
1068
1078
- self .send_setpoint (self .scf , self . current_goal_pos )
1069
+ self .send_setpoint (self .current_goal_pos )
1079
1070
# Check if the cf has reached the goal position,
1080
1071
# if it has set a new goal position
1081
1072
if self .valid_cf_pos .distance_to (
@@ -1114,7 +1105,7 @@ def flight_controller(self):
1114
1105
) - time_of_pos_reach
1115
1106
1116
1107
elif self .flight_mode == FlightModeStates .CIRCLE :
1117
- self .send_setpoint (self .scf , self . current_goal_pos )
1108
+ self .send_setpoint (self .current_goal_pos )
1118
1109
1119
1110
# Check if the cf has reached the goal position,
1120
1111
# if it has set a new goal position
@@ -1166,7 +1157,6 @@ def flight_controller(self):
1166
1157
self .length_from_wand = (2 * (
1167
1158
(self .wand_pos .roll + 90 ) / 180 ) - 1 ) + 2
1168
1159
self .send_setpoint (
1169
- self .scf ,
1170
1160
Position (
1171
1161
self .wand_pos .x + round (
1172
1162
math .cos (math .radians (self .wand_pos .yaw )),
@@ -1187,7 +1177,6 @@ def flight_controller(self):
1187
1177
(self .last_valid_wand_pos .roll + 90 ) / 180 ) -
1188
1178
1 ) + 2
1189
1179
self .send_setpoint (
1190
- self .scf ,
1191
1180
Position (
1192
1181
self .last_valid_wand_pos .x + round (
1193
1182
math .cos (
@@ -1208,7 +1197,6 @@ def flight_controller(self):
1208
1197
elif self .flight_mode == FlightModeStates .LIFT :
1209
1198
1210
1199
self .send_setpoint (
1211
- self .scf ,
1212
1200
Position (self .current_goal_pos .x ,
1213
1201
self .current_goal_pos .y , 1 ))
1214
1202
@@ -1219,7 +1207,7 @@ def flight_controller(self):
1219
1207
self .switch_flight_mode (FlightModeStates .HOVERING )
1220
1208
1221
1209
elif self .flight_mode == FlightModeStates .HOVERING :
1222
- self .send_setpoint (self .scf , self . current_goal_pos )
1210
+ self .send_setpoint (self .current_goal_pos )
1223
1211
1224
1212
elif self .flight_mode == FlightModeStates .RECORD :
1225
1213
@@ -1296,6 +1284,8 @@ def save_current_position(self):
1296
1284
def _connected (self , link_uri ):
1297
1285
"""Callback when the Crazyflie has been connected"""
1298
1286
1287
+ self ._cf = self ._helper .cf
1288
+
1299
1289
if not self .flying_enabled :
1300
1290
self .flying_enabled = True
1301
1291
self .cfStatus = ": connecting..."
@@ -1315,6 +1305,7 @@ def _disconnected(self, link_uri):
1315
1305
self .cfStatus = ': not connected'
1316
1306
self .flying_enabled = False
1317
1307
self .cf_ready_to_fly = False
1308
+ self ._cf = None
1318
1309
1319
1310
def _param_updated (self , name , value ):
1320
1311
"""Callback when the registered parameter get's updated"""
@@ -1333,7 +1324,7 @@ def _logging_error(self, log_conf, msg):
1333
1324
self , "Example error" , "Error when using log config"
1334
1325
" [{0}]: {1}" .format (log_conf .name , msg ))
1335
1326
1336
- def wait_for_position_estimator (self , scf ):
1327
+ def wait_for_position_estimator (self , cf ):
1337
1328
logger .info ('Waiting for estimator to find stable position...' )
1338
1329
1339
1330
self .cfStatus = (
@@ -1352,7 +1343,7 @@ def wait_for_position_estimator(self, scf):
1352
1343
1353
1344
threshold = 0.001
1354
1345
1355
- with SyncLogger (scf , log_config ) as log :
1346
+ with SyncLogger (cf , log_config ) as log :
1356
1347
for log_entry in log :
1357
1348
data = log_entry [1 ]
1358
1349
@@ -1387,10 +1378,9 @@ def wait_for_position_estimator(self, scf):
1387
1378
1388
1379
break
1389
1380
1390
- def reset_estimator (self , scf ):
1381
+ def reset_estimator (self , cf ):
1391
1382
# Reset the kalman filter
1392
1383
1393
- cf = scf .cf
1394
1384
cf .param .set_value ('kalman.resetEstimation' , '1' )
1395
1385
time .sleep (0.1 )
1396
1386
cf .param .set_value ('kalman.resetEstimation' , '0' )
@@ -1418,13 +1408,10 @@ def switch_flight_mode(self, mode):
1418
1408
1419
1409
logger .info ('Switching Flight Mode to: %s' , mode )
1420
1410
1421
- def send_setpoint (self , scf_ , pos ):
1411
+ def send_setpoint (self , pos ):
1422
1412
# Wraps the send command to the crazyflie
1423
-
1424
- # The 'send_setpoint' function strangely takes the
1425
- # arguments in the order (Y, X, Yaw, Z)
1426
- scf_ .cf .commander .send_setpoint (pos .y , pos .x , 0 , int (pos .z * 1000 ))
1427
- pass
1413
+ if self ._cf is not None :
1414
+ self ._cf .commander .send_position_setpoint (pos .x , pos .y , pos .z , 0.0 )
1428
1415
1429
1416
1430
1417
class Position :
0 commit comments