diff --git a/cflib_groundstation/SetpointHandler.py b/cflib_groundstation/SetpointHandler.py index 352ef3c2ce18e969db3a0792a0d15ae5a253a3b7..9a93d361e9f458522a1f16252b4396cda2fd8e3d 100644 --- a/cflib_groundstation/SetpointHandler.py +++ b/cflib_groundstation/SetpointHandler.py @@ -5,10 +5,12 @@ the controls tab. """ +from ast import While, arg from enum import Enum +from time import sleep from PyQt5.QtCore import QTimer from uCartCommander import Commander -from threading import Semaphore, Timer +from threading import Semaphore, Thread, Timer class FlightMode(Enum): @@ -61,23 +63,28 @@ class SetpointHandler: self.setpoint_semaphore = Semaphore(1) self._flight_mode = FlightMode.TYPE_STOP self.is_running = False + self.setpoint_time = 0 + self.curr_time = 0 # Send setpoints to crazyflie every 20 ms. - def start(self): - if not self.is_running: - self.timer = Timer(0.2, self.update) - self.timer.start() - self.is_running = True - def stop(self): - self.timer.cancel() - self.is_running = False + def updateThread(self): + while self.is_running: + if self.curr_time < self.setpoint_time: + self.update() + sleep(.2) + + def startSetpointThread(self): + setpointThread = Thread(target = self.updateThread, args=None) + setpointThread.start() + """" def setTimer(self, time) : #A way to set the timer so the setpoint is reguluarly sent self.timer.stop() self.timer.timeout.connect(self.update) self.timer.start(time) + """ def setCommander(self, commander: Commander): @@ -92,9 +99,6 @@ class SetpointHandler: self.commander = None def update(self): - self.is_running = False - self.start() - print("update") """ If the flight mode is not stopped, send the current setpoint. """ if self._flight_mode != FlightMode.TYPE_STOP: self.sendSetpoint() @@ -148,7 +152,7 @@ class SetpointHandler: self.setpoint.pitch = pitch self.setpoint.roll = roll self.setpoint.thrust = thrust - self.sendSetpointUnsafe() + #self.sendSetpointUnsafe() self.setpoint_semaphore.release() diff --git a/cflib_groundstation/__pycache__/LogfileHandler.cpython-38.pyc b/cflib_groundstation/__pycache__/LogfileHandler.cpython-38.pyc index fac69a6d1b9e4014f14f747ad3fc8027b237b5fb..ffd3eb187ae669b573249628651bb2b325cdd03d 100644 Binary files a/cflib_groundstation/__pycache__/LogfileHandler.cpython-38.pyc and b/cflib_groundstation/__pycache__/LogfileHandler.cpython-38.pyc differ diff --git a/cflib_groundstation/__pycache__/SetpointHandler.cpython-38.pyc b/cflib_groundstation/__pycache__/SetpointHandler.cpython-38.pyc index 92c67d4aa6b16a61e2670e99263fe0b7ee77a2ff..088476dc88ca402313c06ba04de9260ad332b941 100644 Binary files a/cflib_groundstation/__pycache__/SetpointHandler.cpython-38.pyc and b/cflib_groundstation/__pycache__/SetpointHandler.cpython-38.pyc differ diff --git a/cflib_groundstation/__pycache__/crazyflie_connection.cpython-38.pyc b/cflib_groundstation/__pycache__/crazyflie_connection.cpython-38.pyc index 4c89ea7f02e6a8fa71da9a0958cffb32a399799b..e039163235a5740cf6f54c2b8bc4a2907e881d45 100644 Binary files a/cflib_groundstation/__pycache__/crazyflie_connection.cpython-38.pyc and b/cflib_groundstation/__pycache__/crazyflie_connection.cpython-38.pyc differ diff --git a/cflib_groundstation/__pycache__/groundstation_socket.cpython-38.pyc b/cflib_groundstation/__pycache__/groundstation_socket.cpython-38.pyc index a1ce4ff794d9ac33d55246bcee325aff4b671ac9..b0ef6e3fb8c859a32aa8281c5053a0b7b98eccde 100644 Binary files a/cflib_groundstation/__pycache__/groundstation_socket.cpython-38.pyc and b/cflib_groundstation/__pycache__/groundstation_socket.cpython-38.pyc differ diff --git a/cflib_groundstation/__pycache__/uCartCommander.cpython-38.pyc b/cflib_groundstation/__pycache__/uCartCommander.cpython-38.pyc index b459f6ac1b89232a83a696d2147df4b794fdad0b..60a4cea95f06d8a8f3144272a60da6dfd06f4fa1 100644 Binary files a/cflib_groundstation/__pycache__/uCartCommander.cpython-38.pyc and b/cflib_groundstation/__pycache__/uCartCommander.cpython-38.pyc differ diff --git a/cflib_groundstation/crazyflie_connection.py b/cflib_groundstation/crazyflie_connection.py index 8e98010d811ccb55a91ed6fa08b49a87067ed8b1..d079bf50ddede0c2106573f955058f27ef4c383a 100644 --- a/cflib_groundstation/crazyflie_connection.py +++ b/cflib_groundstation/crazyflie_connection.py @@ -80,7 +80,7 @@ class CrazyflieConnection: # refresh the logging page so that it displays the toc # refresh the parameter page so that it displays the correct information self.setpoint_handler.setCommander(self.scf.cf.commander) - #self.setpoint_handler.start() + self.setpoint_handler.startSetpointThread() def disconnect(self): """ Disconnect from crazyflie. """ @@ -135,8 +135,10 @@ class CrazyflieConnection: raise Exception # Not implemented else : raise Exception - - self.setpoint_handler.setSetpoint(yaw, pitch, roll, thrust) + if self.setpoint_handler.setpoint.pitch != pitch or self.setpoint_handler.setpoint.yaw != yaw or self.setpoint_handler.setpoint.roll != roll or self.setpoint_handler.setpoint.thrust != thrust: + self.setpoint_handler.setSetpoint(yaw, pitch, roll, thrust) + self.setpoint_handler.setpoint_time = time + self.setpoint_handler.curr_time = 0 #self.setpoint_handler.sendSetpoint() def GetNodeIds(): diff --git a/cflib_groundstation/logs/cflie1_2023_12_01_19:57:31.txt b/cflib_groundstation/logs/cflie1_2023_12_01_19:57:31.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2deb3d7f9194aecf66b8ffeb60d11618d2e5c67 --- /dev/null +++ b/cflib_groundstation/logs/cflie1_2023_12_01_19:57:31.txt @@ -0,0 +1 @@ +#Crazyflie #Controller:Unknown \ No newline at end of file diff --git a/cflib_groundstation/logs/cflie1_2023_12_01_19:57:44.txt b/cflib_groundstation/logs/cflie1_2023_12_01_19:57:44.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2deb3d7f9194aecf66b8ffeb60d11618d2e5c67 --- /dev/null +++ b/cflib_groundstation/logs/cflie1_2023_12_01_19:57:44.txt @@ -0,0 +1 @@ +#Crazyflie #Controller:Unknown \ No newline at end of file diff --git a/cflib_groundstation/logs/cflie1_2023_12_01_19:58:02.txt b/cflib_groundstation/logs/cflie1_2023_12_01_19:58:02.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/cflib_groundstation/logs/cflie1_2023_12_01_20:00:03.txt b/cflib_groundstation/logs/cflie1_2023_12_01_20:00:03.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2deb3d7f9194aecf66b8ffeb60d11618d2e5c67 --- /dev/null +++ b/cflib_groundstation/logs/cflie1_2023_12_01_20:00:03.txt @@ -0,0 +1 @@ +#Crazyflie #Controller:Unknown \ No newline at end of file diff --git a/cflib_groundstation/logs/cflie1_2023_12_01_20:05:31.txt b/cflib_groundstation/logs/cflie1_2023_12_01_20:05:31.txt new file mode 100644 index 0000000000000000000000000000000000000000..f2deb3d7f9194aecf66b8ffeb60d11618d2e5c67 --- /dev/null +++ b/cflib_groundstation/logs/cflie1_2023_12_01_20:05:31.txt @@ -0,0 +1 @@ +#Crazyflie #Controller:Unknown \ No newline at end of file