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

output override works

parent a767fd60
No related branches found
No related tags found
5 merge requests!106Adding Pycrocart 2.1,!104adding cflib to this branch,!103Updating develop to current state of master branch,!98Pycrocart 2.1 will,!94Merge cflib adapter into main
...@@ -32,7 +32,7 @@ class Setpoint: ...@@ -32,7 +32,7 @@ class Setpoint:
self.yaw: float = 0 self.yaw: float = 0
self.pitch: float = 0 self.pitch: float = 0
self.roll: float = 0 self.roll: float = 0
self.thrust: int = 0 self.thrust: float = 0
class SetpointHandler: class SetpointHandler:
...@@ -184,7 +184,7 @@ class SetpointHandler: ...@@ -184,7 +184,7 @@ class SetpointHandler:
if self.commander: if self.commander:
if self._flight_mode == FlightMode.ATTITUDE_TYPE: if self._flight_mode == FlightMode.ATTITUDE_TYPE:
# scales thrust from 100 for slider control. # scales thrust from 100 for slider control.
thrust = self.setpoint.thrust * 60000 / 100 thrust = self.setpoint.thrust #* 60000 / 100
print(f"Set attitude: {self.setpoint.yaw}, {self.setpoint.pitch}, " print(f"Set attitude: {self.setpoint.yaw}, {self.setpoint.pitch}, "
f"{self.setpoint.roll}, {self.setpoint.thrust}") f"{self.setpoint.roll}, {self.setpoint.thrust}")
...@@ -193,8 +193,8 @@ class SetpointHandler: ...@@ -193,8 +193,8 @@ class SetpointHandler:
int(thrust)) int(thrust))
elif self._flight_mode == FlightMode.ATTITUDE_RATE_TYPE: elif self._flight_mode == FlightMode.ATTITUDE_RATE_TYPE:
print(self.setpoint.thrust)
thrust = self.setpoint.thrust * 60000 / 100 thrust = self.setpoint.thrust #* 60000 / 100
print(f"Set attitude rate: {self.setpoint.yaw}," print(f"Set attitude rate: {self.setpoint.yaw},"
f" {self.setpoint.pitch}, " f" {self.setpoint.pitch}, "
f"{self.setpoint.roll}, {thrust}") f"{self.setpoint.roll}, {thrust}")
...@@ -205,7 +205,7 @@ class SetpointHandler: ...@@ -205,7 +205,7 @@ class SetpointHandler:
elif self._flight_mode == FlightMode.MIXED_ATTITUDE_TYPE: elif self._flight_mode == FlightMode.MIXED_ATTITUDE_TYPE:
# scales thrust from 1000 for more fine-grained gamepad control. # scales thrust from 1000 for more fine-grained gamepad control.
thrust = self.setpoint.thrust * 60000 / 1000 thrust = self.setpoint.thrust #* 60000 / 1000
print(f"Set mixed attitude: {self.setpoint.yaw}," print(f"Set mixed attitude: {self.setpoint.yaw},"
f" {self.setpoint.pitch}, " f" {self.setpoint.pitch}, "
f"{self.setpoint.roll}, {thrust}") f"{self.setpoint.roll}, {thrust}")
......
File added
No preview for this file type
File added
This diff is collapsed.
This diff is collapsed.
...@@ -8,6 +8,7 @@ cflib library. ...@@ -8,6 +8,7 @@ cflib library.
from time import time from time import time
from typing import List from typing import List
import time import time
import struct
import cflib.crtp import cflib.crtp
from cflib.crazyflie import Crazyflie from cflib.crazyflie import Crazyflie
...@@ -82,8 +83,6 @@ class CrazyflieConnection: ...@@ -82,8 +83,6 @@ class CrazyflieConnection:
self.scf.close_link() self.scf.close_link()
self.scf = None self.scf = None
self.is_connected = False self.is_connected = False
# disconnect the commander from setpointhandler
self.setpoint_handler.disconnectCommander()
def Debug(): def Debug():
raise Exception raise Exception
...@@ -97,19 +96,21 @@ class CrazyflieConnection: ...@@ -97,19 +96,21 @@ class CrazyflieConnection:
raise Exception raise Exception
def OverrideOuput(self, command): def OverrideOuput(self, command):
"""Sends all setpoints for a given amount of time""" """Sends all setpoints for a given amount of time"""
print(command["data"])
mode = command['data'][0] mode = command['data'][0]
time = command['data'][1:4] # Currently sent every 20ms by setpoint_handler may change time = command['data'][1:5] # Currently sent every 20ms by setpoint_handler may change
thrust = command['data'][5:8] thrust = command['data'][5:9]
pitch = command['data'][9:12] pitch = command['data'][9:13]
roll = command['data'][13:16] roll = command['data'][13:17]
yaw = command['data'][17:20] yaw = command['data'][17:21]
# Error Handling # Error Handling
try: try:
yaw = float(yaw) yaw = struct.unpack('f', bytes(yaw))[0]
pitch = float(pitch) pitch = struct.unpack('f', bytes(pitch))[0]
roll = float(roll) roll = struct.unpack('f', bytes(roll))[0]
thrust = int(thrust) thrust = struct.unpack('f', bytes(thrust))[0]
print(thrust)
except ValueError: except ValueError:
raise Exception raise Exception
...@@ -166,21 +167,26 @@ class CrazyflieConnection: ...@@ -166,21 +167,26 @@ class CrazyflieConnection:
""" Retrieve parameter value from crazyflie toc. """ """ Retrieve parameter value from crazyflie toc. """
#Bytes 0 and 1 are node ID, ie group #Bytes 0 and 1 are node ID, ie group
#Bytes 2 and 3 are node paramID, ie name #Bytes 2 and 3 are node paramID, ie name
print("Getting Param...")
group = command['data'][0:1] group = command['data'][0:1]
name = command['data'][2:3] name = command['data'][2:3]
try: try:
if self.scf.is_link_open(): if self.scf.is_link_open():
val = self.scf.cf.param.values[group][name] val = self.scf.cf.param.values[group][name]
print(val)
except AttributeError: except AttributeError:
val = -1.234567 val = -1.234567
pass pass
data = bytearray(group) data = bytearray(group)
data.append(name) data.append(name)
data.append(val) data.append(val)
print(data)
responsedata = { responsedata = {
"msg_type": (MessageTypeID.RESPPARAM_ID), "msg_type": (MessageTypeID.RESPPARAM_ID),
"msg_id": command['msg_id'], "msg_id": command['msg_id'],
......
...@@ -17,6 +17,7 @@ class main(): ...@@ -17,6 +17,7 @@ class main():
self.inThread = Thread(target = gs.groundstation_connect, args = (self.inputQueue,)) self.inThread = Thread(target = gs.groundstation_connect, args = (self.inputQueue,))
self.inThread.start() self.inThread.start()
self.cfConnect = CrazyflieConnection() self.cfConnect = CrazyflieConnection()
self.cfConnect.connect("radio://0/20/2M/E7E7E7E7E7")
self.commandThread = Thread(target = self.processCommands) self.commandThread = Thread(target = self.processCommands)
self.commandThread.start() self.commandThread.start()
while True: while True:
...@@ -38,28 +39,13 @@ class main(): ...@@ -38,28 +39,13 @@ class main():
elif msg_type == MessageTypeID.BEGINUPDATE_ID.value: elif msg_type == MessageTypeID.BEGINUPDATE_ID.value:
self.cfConnect.BeginUpdate() self.cfConnect.BeginUpdate()
elif msg_type == MessageTypeID.OUTPUT_OVERRIDE_ID.value: elif msg_type == MessageTypeID.OUTPUT_OVERRIDE_ID.value:
self.cfConnect.OverrideOuput() self.cfConnect.OverrideOuput(command)
elif msg_type == MessageTypeID.GETNODES_ID.value: elif msg_type == MessageTypeID.GETNODES_ID.value:
self.cfConnect.GetNodes() self.cfConnect.GetNodes()
elif msg_type == MessageTypeID.SETPARAM_ID.value: elif msg_type == MessageTypeID.SETPARAM_ID.value:
self.cfConnect.SetParam() self.cfConnect.SetParam()
elif msg_type == MessageTypeID.GETPARAM_ID.value: elif msg_type == MessageTypeID.GETPARAM_ID.value:
group = command['data'][0:1] self.cfConnect.GetParam(command, self.outputQueue)
name = command['data'][2:3]
val = 10
data = bytearray(group)
data += name
data.append(val)
responsedata = {
"msg_type": (MessageTypeID.RESPPARAM_ID.value),
"msg_id": command['msg_id'],
"data_len": 8,
"data": data
}
self.outputQueue.put(responsedata)
#self.cfConnect.GetParam()
elif msg_type == MessageTypeID.SETSOURCE_ID.value: elif msg_type == MessageTypeID.SETSOURCE_ID.value:
self.cfConnect.SetSource() self.cfConnect.SetSource()
elif msg_type == MessageTypeID.GETSOURCE_ID.value: elif msg_type == MessageTypeID.GETSOURCE_ID.value:
......
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