Skip to content
Snippets Groups Projects
Commit 7e71f19b authored by abeinder's avatar abeinder
Browse files

current working version

parent dc9b5091
No related branches found
No related tags found
3 merge requests!104adding cflib to this branch,!94Merge cflib adapter into main,!84Pycrocart
...@@ -215,12 +215,15 @@ class ParameterWindow(QWidget): ...@@ -215,12 +215,15 @@ class ParameterWindow(QWidget):
def on_send(self): def on_send(self):
if not self.sending: if not self.sending:
self.sending = True
self.complete_label.setEnabled(False)
try: try:
with open('./mp4params.json', 'r') as f: with open('./mp4params.json', 'r') as f:
contents = json.load(f) contents = json.load(f)
self.sending = True
self.complete_label.setEnabled(False)
self.complete_label.setText("Complete ✓")
for key in contents: for key in contents:
for sub_key in contents[key]: for sub_key in contents[key]:
self.num_to_send += 1 self.num_to_send += 1
...@@ -229,9 +232,11 @@ class ParameterWindow(QWidget): ...@@ -229,9 +232,11 @@ class ParameterWindow(QWidget):
'value': contents[key][sub_key]}) 'value': contents[key][sub_key]})
self.timer.timeout.connect(self.send_callback) self.timer.timeout.connect(self.send_callback)
self.timer.start(100) self.timer.start(300)
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
print("File open") error_text = "Malformed Json"
self.complete_label.setText(
"<span style='color: red;'>" + error_text + "</span>")
def send_callback(self): def send_callback(self):
......
...@@ -94,11 +94,11 @@ class SetpointHandler: ...@@ -94,11 +94,11 @@ class SetpointHandler:
thrust = self.setpoint.thrust * 65000 / 100 thrust = self.setpoint.thrust * 65000 / 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}, {thrust}")
self.commander.send_attitude_setpoint( self.commander.send_attitude_setpoint(
self.setpoint.yaw, self.setpoint.pitch, self.setpoint.roll, self.setpoint.yaw, self.setpoint.pitch, self.setpoint.roll,
int(thrust)) thrust)
elif self._flight_mode == FlightMode.ATTITUDE_RATE_TYPE: elif self._flight_mode == FlightMode.ATTITUDE_RATE_TYPE:
...@@ -109,7 +109,7 @@ class SetpointHandler: ...@@ -109,7 +109,7 @@ class SetpointHandler:
self.commander.send_attitude_rate_setpoint( self.commander.send_attitude_rate_setpoint(
self.setpoint.yaw, self.setpoint.pitch, self.setpoint.roll, self.setpoint.yaw, self.setpoint.pitch, self.setpoint.roll,
int(thrust)) thrust)
self.setpoint_semaphore.release() self.setpoint_semaphore.release()
...@@ -134,4 +134,4 @@ class SetpointHandler: ...@@ -134,4 +134,4 @@ class SetpointHandler:
self.commander.send_attitude_rate_setpoint( self.commander.send_attitude_rate_setpoint(
self.setpoint.yaw, self.setpoint.pitch, self.setpoint.roll, self.setpoint.yaw, self.setpoint.pitch, self.setpoint.roll,
int(thrust)) thrust)
\ No newline at end of file
...@@ -209,5 +209,6 @@ class SetpointMenu(QWidget): ...@@ -209,5 +209,6 @@ class SetpointMenu(QWidget):
self.roll_box.setText(str(round(self.setpoint.roll, 2))) self.roll_box.setText(str(round(self.setpoint.roll, 2)))
self.pitch_box.setText(str(round(self.setpoint.pitch, 2))) self.pitch_box.setText(str(round(self.setpoint.pitch, 2)))
self.thrust_slider.setValue(int(round(self.setpoint.thrust, 2))) self.thrust_slider.setValue(int(round(self.setpoint.thrust, 2)))
self.send_setpoint()
self.setpoint_semaphore.release() self.setpoint_semaphore.release()
{ {
"group1": "group1":
{ {
"update_frequency_ms": 21, "update_frequency_ms": 50,
"vars": ["stateEstimate.pitch", "stateEstimate.roll", "stateEstimate.yaw"] "vars": ["ctrlStdnt.r_roll", "ctrlStdnt.rollRate", "stateEstimate.roll", "ctrlStdnt.roll"]
},
"group2":
{
"update_frequency_ms": 100,
"vars": ["health.motorVarXM1"]
} }
} }
\ No newline at end of file
...@@ -5,26 +5,26 @@ ...@@ -5,26 +5,26 @@
}, },
"s_pid_rate": "s_pid_rate":
{ {
"roll_kp" : 0, "roll_kp" : 300,
"roll_ki" : 0, "roll_ki" : 40,
"roll_kd" : 0, "roll_kd" : 0,
"pitch_kp": 0, "pitch_kp": 200,
"pitch_ki": 0, "pitch_ki": 40,
"pitch_kd": 0, "pitch_kd": 0,
"yaw_kp" : 0, "yaw_kp" : 2000,
"yaw_ki" : 0, "yaw_ki" : 0,
"yaw_kd" : 0 "yaw_kd" : 0
}, },
"s_pid_attitude": "s_pid_attitude":
{ {
"roll_kp" : 0, "roll_kp" : 15,
"roll_ki" : 0, "roll_ki" : 10,
"roll_kd" : 0, "roll_kd" : 3,
"pitch_kp": 0, "pitch_kp": 15,
"pitch_ki": 0, "pitch_ki": 10,
"pitch_kd": 0, "pitch_kd": 3,
"yaw_kp" : 0, "yaw_kp" : 10,
"yaw_ki" : 0, "yaw_ki" : 0,
"yaw_kd" : 0, "yaw_kd" : 0
} }
} }
\ No newline at end of file
...@@ -208,9 +208,9 @@ class Commander: ...@@ -208,9 +208,9 @@ class Commander:
pk = CRTPPacket() pk = CRTPPacket()
pk.port = CRTPPort.COMMANDER_GENERIC pk.port = CRTPPort.COMMANDER_GENERIC
pk.channel = SET_SETPOINT_CHANNEL pk.channel = SET_SETPOINT_CHANNEL
pk.data = struct.pack('<Bffff', ATTITUDE_RATE_TYPE, yawRate, pk.data = struct.pack('<Bffff', ATTITUDE_RATE_TYPE, rollRate,
pitchRate, pitchRate,
rollRate, thrust) # todo confirm struct is yawRate, thrust) # todo confirm struct is
# right, I tried to format it using H for the int of thrust and f for # right, I tried to format it using H for the int of thrust and f for
# floats otherwise. Kinda looks like what is above # floats otherwise. Kinda looks like what is above
self._cf.send_packet(pk) self._cf.send_packet(pk)
...@@ -230,7 +230,7 @@ class Commander: ...@@ -230,7 +230,7 @@ class Commander:
pk = CRTPPacket() pk = CRTPPacket()
pk.port = CRTPPort.COMMANDER_GENERIC pk.port = CRTPPort.COMMANDER_GENERIC
pk.channel = SET_SETPOINT_CHANNEL pk.channel = SET_SETPOINT_CHANNEL
pk.data = struct.pack('<Bffff', ATTITUDE_TYPE, yaw, pitch, roll, pk.data = struct.pack('<Bffff', ATTITUDE_TYPE, roll, pitch, yaw,
thrust) thrust)
self._cf.send_packet(pk) # todo confirm struct is right , I tried to self._cf.send_packet(pk) # todo confirm struct is right , I tried to
# format it using H for the int of thrust and f for # format it using H for the int of thrust and f for
......
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