Skip to content
Snippets Groups Projects
Commit f36bf079 authored by 488_MP-4's avatar 488_MP-4
Browse files

attempting timer

parent 81fb6c53
No related branches found
No related tags found
4 merge requests!104adding cflib to this branch,!103Updating develop to current state of master branch,!95Cflib groundstation,!94Merge cflib adapter into main
Showing
with 26 additions and 16 deletions
......@@ -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()
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -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():
......
#Crazyflie #Controller:Unknown
\ No newline at end of file
#Crazyflie #Controller:Unknown
\ No newline at end of file
#Crazyflie #Controller:Unknown
\ No newline at end of file
#Crazyflie #Controller:Unknown
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment