Skip to content

Commit 5ab4c28

Browse files
committed
#355 Minor clean up in the qualisys tab
* Removed unnecessary SyncCrazyflie * Using correct function to send position to CF
1 parent 8447868 commit 5ab4c28

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

src/cfclient/ui/tabs/QualisysTab.py

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
from cfclient.ui.tab import Tab
4747
from cfclient.utils.config import Config
4848
from cflib.crazyflie.log import LogConfig
49-
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
5049
from cflib.crazyflie.syncLogger import SyncLogger
5150

5251
import xml.etree.cElementTree as ET
@@ -192,8 +191,7 @@ def __init__(self, tabWidget, helper, *args):
192191
self.qtm_6DoF_labels = None
193192
self._helper = helper
194193
self._qtm_connection = None
195-
self.scf = None
196-
self.uri = "80/2M"
194+
self._cf = None
197195
self.model = QStandardItemModel(10, 4)
198196

199197
self._cf_status = self.cfStatusLabel.text()
@@ -735,7 +733,7 @@ def set_path_mode(self):
735733
self.switch_flight_mode(FlightModeStates.PATH)
736734

737735
def set_kill_engine(self):
738-
self.send_setpoint(self.scf, Position(0, 0, 0))
736+
self.send_setpoint(Position(0, 0, 0))
739737
self.switch_flight_mode(FlightModeStates.GROUNDED)
740738
logger.info('Stop button pressed, kill engines')
741739

@@ -905,12 +903,12 @@ def on_packet(self, packet):
905903
except ValueError as err:
906904
self.qtmStatus = ' : connected : No 6DoF body found'
907905

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
910908
# Feed the current position of the cf back to the cf to
911909
# 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)
914912

915913
def _update_ui(self):
916914
# Update the data in the GUI
@@ -993,16 +991,10 @@ def _flight_mode_disconnected_entered(self):
993991

994992
def flight_controller(self):
995993
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)
998996

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')
1006998

1007999
time.sleep(0.1)
10081000

@@ -1045,7 +1037,6 @@ def flight_controller(self):
10451037
if self.flight_mode == FlightModeStates.LAND:
10461038

10471039
self.send_setpoint(
1048-
self.scf,
10491040
Position(
10501041
self.current_goal_pos.x,
10511042
self.current_goal_pos.y,
@@ -1062,7 +1053,7 @@ def flight_controller(self):
10621053
self.land_rate *= 1.1
10631054

10641055
if self.land_rate > 1000:
1065-
self.send_setpoint(self.scf, Position(0, 0, 0))
1056+
self.send_setpoint(Position(0, 0, 0))
10661057
if self.land_for_recording:
10671058
# Return the control to the recording mode
10681059
# after landing
@@ -1075,7 +1066,7 @@ def flight_controller(self):
10751066

10761067
elif self.flight_mode == FlightModeStates.PATH:
10771068

1078-
self.send_setpoint(self.scf, self.current_goal_pos)
1069+
self.send_setpoint(self.current_goal_pos)
10791070
# Check if the cf has reached the goal position,
10801071
# if it has set a new goal position
10811072
if self.valid_cf_pos.distance_to(
@@ -1114,7 +1105,7 @@ def flight_controller(self):
11141105
) - time_of_pos_reach
11151106

11161107
elif self.flight_mode == FlightModeStates.CIRCLE:
1117-
self.send_setpoint(self.scf, self.current_goal_pos)
1108+
self.send_setpoint(self.current_goal_pos)
11181109

11191110
# Check if the cf has reached the goal position,
11201111
# if it has set a new goal position
@@ -1166,7 +1157,6 @@ def flight_controller(self):
11661157
self.length_from_wand = (2 * (
11671158
(self.wand_pos.roll + 90) / 180) - 1) + 2
11681159
self.send_setpoint(
1169-
self.scf,
11701160
Position(
11711161
self.wand_pos.x + round(
11721162
math.cos(math.radians(self.wand_pos.yaw)),
@@ -1187,7 +1177,6 @@ def flight_controller(self):
11871177
(self.last_valid_wand_pos.roll + 90) / 180) -
11881178
1) + 2
11891179
self.send_setpoint(
1190-
self.scf,
11911180
Position(
11921181
self.last_valid_wand_pos.x + round(
11931182
math.cos(
@@ -1208,7 +1197,6 @@ def flight_controller(self):
12081197
elif self.flight_mode == FlightModeStates.LIFT:
12091198

12101199
self.send_setpoint(
1211-
self.scf,
12121200
Position(self.current_goal_pos.x,
12131201
self.current_goal_pos.y, 1))
12141202

@@ -1219,7 +1207,7 @@ def flight_controller(self):
12191207
self.switch_flight_mode(FlightModeStates.HOVERING)
12201208

12211209
elif self.flight_mode == FlightModeStates.HOVERING:
1222-
self.send_setpoint(self.scf, self.current_goal_pos)
1210+
self.send_setpoint(self.current_goal_pos)
12231211

12241212
elif self.flight_mode == FlightModeStates.RECORD:
12251213

@@ -1296,6 +1284,8 @@ def save_current_position(self):
12961284
def _connected(self, link_uri):
12971285
"""Callback when the Crazyflie has been connected"""
12981286

1287+
self._cf = self._helper.cf
1288+
12991289
if not self.flying_enabled:
13001290
self.flying_enabled = True
13011291
self.cfStatus = ": connecting..."
@@ -1315,6 +1305,7 @@ def _disconnected(self, link_uri):
13151305
self.cfStatus = ': not connected'
13161306
self.flying_enabled = False
13171307
self.cf_ready_to_fly = False
1308+
self._cf = None
13181309

13191310
def _param_updated(self, name, value):
13201311
"""Callback when the registered parameter get's updated"""
@@ -1333,7 +1324,7 @@ def _logging_error(self, log_conf, msg):
13331324
self, "Example error", "Error when using log config"
13341325
" [{0}]: {1}".format(log_conf.name, msg))
13351326

1336-
def wait_for_position_estimator(self, scf):
1327+
def wait_for_position_estimator(self, cf):
13371328
logger.info('Waiting for estimator to find stable position...')
13381329

13391330
self.cfStatus = (
@@ -1352,7 +1343,7 @@ def wait_for_position_estimator(self, scf):
13521343

13531344
threshold = 0.001
13541345

1355-
with SyncLogger(scf, log_config) as log:
1346+
with SyncLogger(cf, log_config) as log:
13561347
for log_entry in log:
13571348
data = log_entry[1]
13581349

@@ -1387,10 +1378,9 @@ def wait_for_position_estimator(self, scf):
13871378

13881379
break
13891380

1390-
def reset_estimator(self, scf):
1381+
def reset_estimator(self, cf):
13911382
# Reset the kalman filter
13921383

1393-
cf = scf.cf
13941384
cf.param.set_value('kalman.resetEstimation', '1')
13951385
time.sleep(0.1)
13961386
cf.param.set_value('kalman.resetEstimation', '0')
@@ -1418,13 +1408,10 @@ def switch_flight_mode(self, mode):
14181408

14191409
logger.info('Switching Flight Mode to: %s', mode)
14201410

1421-
def send_setpoint(self, scf_, pos):
1411+
def send_setpoint(self, pos):
14221412
# 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)
14281415

14291416

14301417
class Position:

0 commit comments

Comments
 (0)