From 911293e062e1f9a122f4b8d2274a5e512e5d0ff7 Mon Sep 17 00:00:00 2001 From: Wolfgang Hoenig Date: Wed, 10 Jan 2024 06:42:20 +0100 Subject: [PATCH 1/2] sim - vis - pdf: support multiple CFs The current implementation overrides the output pdf file for each UAV. This changes the implementation to write the data for all UAVs in one PDF. --- crazyflie_sim/crazyflie_sim/visualization/pdf.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crazyflie_sim/crazyflie_sim/visualization/pdf.py b/crazyflie_sim/crazyflie_sim/visualization/pdf.py index d3b04507d..2ad0016af 100644 --- a/crazyflie_sim/crazyflie_sim/visualization/pdf.py +++ b/crazyflie_sim/crazyflie_sim/visualization/pdf.py @@ -30,17 +30,17 @@ def step(self, t, states: list[State], states_desired: list[State], actions: lis self.all_actions.append(copy.deepcopy(actions)) def shutdown(self): + with PdfPages(self.filename) as pdf: - for k, name in enumerate(self.names): + for k, name in enumerate(self.names): - cf_states = np.array([s[k]._state for s in self.all_states]) - cf_states_desired = np.array([s[k]._state for s in self.all_states_desired]) - cf_actions = np.array([s[k]._action for s in self.all_actions]) - - with PdfPages(self.filename) as pdf: + cf_states = np.array([s[k]._state for s in self.all_states]) + cf_states_desired = np.array([s[k]._state for s in self.all_states_desired]) + cf_actions = np.array([s[k]._action for s in self.all_actions]) # position fig, axs = plt.subplots(3, 1, sharex=True) + fig.suptitle(name + " position") axs[0].set_ylabel('px [m]') axs[1].set_ylabel('py [m]') axs[2].set_ylabel('pz [m]') @@ -55,6 +55,7 @@ def shutdown(self): # velocity fig, axs = plt.subplots(3, 1, sharex=True) + fig.suptitle(name + " velocity") axs[0].set_ylabel('vx [m/s]') axs[1].set_ylabel('vy [m/s]') axs[2].set_ylabel('vz [m/s]') @@ -69,6 +70,7 @@ def shutdown(self): # orientation fig, axs = plt.subplots(3, 1, sharex=True) + fig.suptitle(name + " orientation") axs[0].set_ylabel('roll [deg]') axs[1].set_ylabel('pitch [deg]') axs[2].set_ylabel('yaw [deg]') @@ -87,6 +89,7 @@ def shutdown(self): # omega fig, axs = plt.subplots(3, 1, sharex=True) + fig.suptitle(name + " angular velocity") axs[0].set_ylabel('wx [deg/s]') axs[1].set_ylabel('wy [deg/s]') axs[2].set_ylabel('wz [deg/s]') @@ -101,6 +104,7 @@ def shutdown(self): # actions fig, axs = plt.subplots(2, 2, sharex=True, sharey=True) + fig.suptitle(name + " motor actions") axs[0, 0].set_ylabel('rpm') axs[1, 0].set_ylabel('rpm') axs[1, 0].set_xlabel('Time [s]') From 57ee45737d23c7e08cbc8fc8dd6562c948e3a5d9 Mon Sep 17 00:00:00 2001 From: Wolfgang Hoenig Date: Wed, 10 Jan 2024 06:50:09 +0100 Subject: [PATCH 2/2] fix flake8 issues --- crazyflie_sim/crazyflie_sim/visualization/pdf.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crazyflie_sim/crazyflie_sim/visualization/pdf.py b/crazyflie_sim/crazyflie_sim/visualization/pdf.py index 2ad0016af..6f72ec751 100644 --- a/crazyflie_sim/crazyflie_sim/visualization/pdf.py +++ b/crazyflie_sim/crazyflie_sim/visualization/pdf.py @@ -40,7 +40,7 @@ def shutdown(self): # position fig, axs = plt.subplots(3, 1, sharex=True) - fig.suptitle(name + " position") + fig.suptitle(name + ' position') axs[0].set_ylabel('px [m]') axs[1].set_ylabel('py [m]') axs[2].set_ylabel('pz [m]') @@ -55,7 +55,7 @@ def shutdown(self): # velocity fig, axs = plt.subplots(3, 1, sharex=True) - fig.suptitle(name + " velocity") + fig.suptitle(name + ' velocity') axs[0].set_ylabel('vx [m/s]') axs[1].set_ylabel('vy [m/s]') axs[2].set_ylabel('vz [m/s]') @@ -70,7 +70,7 @@ def shutdown(self): # orientation fig, axs = plt.subplots(3, 1, sharex=True) - fig.suptitle(name + " orientation") + fig.suptitle(name + ' orientation') axs[0].set_ylabel('roll [deg]') axs[1].set_ylabel('pitch [deg]') axs[2].set_ylabel('yaw [deg]') @@ -89,7 +89,7 @@ def shutdown(self): # omega fig, axs = plt.subplots(3, 1, sharex=True) - fig.suptitle(name + " angular velocity") + fig.suptitle(name + ' angular velocity') axs[0].set_ylabel('wx [deg/s]') axs[1].set_ylabel('wy [deg/s]') axs[2].set_ylabel('wz [deg/s]') @@ -104,7 +104,7 @@ def shutdown(self): # actions fig, axs = plt.subplots(2, 2, sharex=True, sharey=True) - fig.suptitle(name + " motor actions") + fig.suptitle(name + ' motor actions') axs[0, 0].set_ylabel('rpm') axs[1, 0].set_ylabel('rpm') axs[1, 0].set_xlabel('Time [s]')