Upload 17 files
Browse files- FirstSubmission/PaperRAL_ScriptAndVideo/evaluate_com.py +287 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/evaluate_joint_torques.py +392 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/evaluate_results.py +74 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/log_esperimenti_buoni.txt +71 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/rneasn000_ukfpinnsn001_camera_high_res.MP4 +3 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/rneasn000_ukfpinnsn001_camera_low_res.MP4 +3 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_ground_RNEA.py +249 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_ground_ergocubsn000.py +294 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_ground_ergocubsn001.py +266 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_momentum_0.py +207 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_momentum_1.py +204 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_momentum_2.py +205 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_momentum_3.py +202 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_position.py +237 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/script/run_all.py +23 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/ukfpinn_sn000_sn001_camera_high_res.MP4 +3 -0
- FirstSubmission/PaperRAL_ScriptAndVideo/ukfpinn_sn000_sn001_camera_low_res.MP4 +3 -0
FirstSubmission/PaperRAL_ScriptAndVideo/evaluate_com.py
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
|
| 4 |
+
def compute_max_mean_error(error, time, data):
|
| 5 |
+
mean_error_init = np.mean(error[time < data["start_contact_sec"][0]], axis=0)
|
| 6 |
+
mean_error_ukf_nocomp = np.mean(error[time < data["start_contact_sec"][1]], axis=0)
|
| 7 |
+
max_error_init = np.max(error[time < data["start_contact_sec"][0]], axis=0)
|
| 8 |
+
max_error_ukf_nocomp = np.max(error[time < data["start_contact_sec"][1]], axis=0)
|
| 9 |
+
for i in range(1, len(data["start_contact_sec"])):
|
| 10 |
+
temp_mean = np.mean(error[(time > data["end_contact_sec"][i-1]) & (time < data["start_contact_sec"][i])], axis=0)
|
| 11 |
+
mean_error = np.mean([mean_error_ukf_nocomp, temp_mean], axis=0)
|
| 12 |
+
max_error = np.max([max_error_ukf_nocomp, np.max(error[(time > data["end_contact_sec"][i-1]) & (time < data["start_contact_sec"][i])], axis=0)], axis=0)
|
| 13 |
+
|
| 14 |
+
return [max_error_init, max_error, mean_error_init, mean_error]
|
| 15 |
+
|
| 16 |
+
def extract_data(data):
|
| 17 |
+
data_des = data["balancing"]["com"]["position"]["desired"]["data"]
|
| 18 |
+
data_meas = data["balancing"]["com"]["position"]["measured"]["data"]
|
| 19 |
+
data_time = data["balancing"]["com"]["position"]["desired"]["timestamps"]
|
| 20 |
+
data_time = data_time - data_time[0]
|
| 21 |
+
error = np.abs(data_des - data_meas)
|
| 22 |
+
error = error[data_time < data["end_experiment_sec"]]
|
| 23 |
+
data_time = data_time[data_time < data["end_experiment_sec"]]
|
| 24 |
+
return [data_des, data_meas, data_time, error]
|
| 25 |
+
|
| 26 |
+
def evaluate_com(ukf_pinn, ukf_nocomp, feedforward, feedforward_pinn, RNEA_nocomp, RNEA_pinn):
|
| 27 |
+
|
| 28 |
+
[ukf_pinn_des, ukf_pinn_meas, ukf_pinn_time, error_ukf_pinn] = extract_data(ukf_pinn)
|
| 29 |
+
[ukf_nocomp_des, ukf_nocomp_meas, ukf_nocomp_time, error_ukf_nocomp] = extract_data(ukf_nocomp)
|
| 30 |
+
[feedforward_des, feedforward_meas, feedforward_time, error_feedforward] = extract_data(feedforward)
|
| 31 |
+
[feedforward_pinn_des, feedforward_pinn_meas, feedforward_pinn_time, error_feedforward_pinn] = extract_data(feedforward_pinn)
|
| 32 |
+
[RNEA_nocomp_des, RNEA_nocomp_meas, RNEA_nocomp_time, error_RNEA_nocomp] = extract_data(RNEA_nocomp)
|
| 33 |
+
[RNEA_pinn_des, RNEA_pinn_meas, RNEA_pinn_time, error_RNEA_pinn] = extract_data(RNEA_pinn)
|
| 34 |
+
|
| 35 |
+
# Calculate the mean error per the intervals contacts and no contacts
|
| 36 |
+
# and considering only samples from the initial timestamp to the end_experiment_sec
|
| 37 |
+
# Compute the RMSE for each componenet x, y, z
|
| 38 |
+
# considering only the samples of the no contacts intervals
|
| 39 |
+
[max_error_ukf_pinn_init, max_error_ukf_pinn, mean_error_ukf_pinn_init, mean_error_ukf_pinn] = compute_max_mean_error(error_ukf_pinn, ukf_pinn_time, ukf_pinn)
|
| 40 |
+
|
| 41 |
+
[max_error_ukf_nocomp_init, max_error_ukf_nocomp, mean_error_ukf_nocomp_init, mean_error_ukf_nocomp] = compute_max_mean_error(error_ukf_nocomp, ukf_nocomp_time, ukf_nocomp)
|
| 42 |
+
|
| 43 |
+
[max_error_feedforward_init, max_error_feedforward, mean_error_feedforward_init, mean_error_feedforward] = compute_max_mean_error(error_feedforward, feedforward_time, feedforward)
|
| 44 |
+
|
| 45 |
+
[max_error_feedforward_pinn_init, max_error_feedforward_pinn, mean_error_feedforward_pinn_init, mean_error_feedforward_pinn] = compute_max_mean_error(error_feedforward_pinn, feedforward_pinn_time, feedforward_pinn)
|
| 46 |
+
|
| 47 |
+
[max_error_RNEA_nocomp_init, max_error_RNEA_nocomp, mean_error_RNEA_nocomp_init, mean_error_RNEA_nocomp] = compute_max_mean_error(error_RNEA_nocomp, RNEA_nocomp_time, RNEA_nocomp)
|
| 48 |
+
|
| 49 |
+
[max_error_RNEA_pinn_init, max_error_RNEA_pinn, mean_error_RNEA_pinn_init, mean_error_RNEA_pinn] = compute_max_mean_error(error_RNEA_pinn, RNEA_pinn_time, RNEA_pinn)
|
| 50 |
+
|
| 51 |
+
# Print the mean and max error before first contact
|
| 52 |
+
print(">>>>>>>>>>>>> Mean error before contact")
|
| 53 |
+
print(f"Mean error UKF Pinn before contact: {mean_error_ukf_pinn_init}")
|
| 54 |
+
print(f"Mean error UKF No Compensation before contact: {mean_error_ukf_nocomp_init}")
|
| 55 |
+
print(f"Mean error Feedforward before contact: {mean_error_feedforward_init}")
|
| 56 |
+
print(f"Mean error Feedforward Pinn before contact: {mean_error_feedforward_pinn_init}")
|
| 57 |
+
print(f"Mean error RNEA No Compensation before contact: {mean_error_RNEA_nocomp_init}")
|
| 58 |
+
print(f"Mean error RNEA Pinn before contact: {mean_error_RNEA_pinn_init}")
|
| 59 |
+
|
| 60 |
+
# Print the best case among all the controllers
|
| 61 |
+
# Find the best case among all the controllers
|
| 62 |
+
min_norm_error = np.min([np.linalg.norm(mean_error_ukf_pinn_init), np.linalg.norm(mean_error_ukf_nocomp_init), np.linalg.norm(mean_error_feedforward_init), np.linalg.norm(mean_error_feedforward_pinn_init), np.linalg.norm(mean_error_RNEA_nocomp_init), np.linalg.norm(mean_error_RNEA_pinn_init)])
|
| 63 |
+
# Which gave the best norm error?
|
| 64 |
+
# if np.linalg.norm(mean_error_ukf_pinn_init) == min_norm_error:
|
| 65 |
+
# print(">>>>>>>>>>>>> Best case before contact: UKF PINN")
|
| 66 |
+
# elif np.linalg.norm(mean_error_ukf_nocomp_init) == min_norm_error:
|
| 67 |
+
# print(">>>>>>>>>>>>> Best case before contact: UKF No Compensation")
|
| 68 |
+
# elif np.linalg.norm(mean_error_feedforward_init) == min_norm_error:
|
| 69 |
+
# print(">>>>>>>>>>>>> Best case before contact: Feedforward")
|
| 70 |
+
# elif np.linalg.norm(mean_error_feedforward_pinn_init) == min_norm_error:
|
| 71 |
+
# print(">>>>>>>>>>>>> Best case before contact: Feedforward PINN")
|
| 72 |
+
# elif np.linalg.norm(mean_error_RNEA_nocomp_init) == min_norm_error:
|
| 73 |
+
# print(">>>>>>>>>>>>> Best case before contact: RNEA No Compensation")
|
| 74 |
+
# elif np.linalg.norm(mean_error_RNEA_pinn_init) == min_norm_error:
|
| 75 |
+
# print(">>>>>>>>>>>>> Best case before contact: RNEA PINN")
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
print(">>>>>>>>>>>>> Max error before contact")
|
| 79 |
+
print(f"Max error UKF Pinn before contact: {max_error_ukf_pinn_init}")
|
| 80 |
+
print(f"Max error UKF No Compensation before contact: {max_error_ukf_nocomp_init}")
|
| 81 |
+
print(f"Max error Feedforward before contact: {max_error_feedforward_init}")
|
| 82 |
+
print(f"Max error Feedforward Pinn before contact: {max_error_feedforward_pinn_init}")
|
| 83 |
+
print(f"Max error RNEA No Compensation before contact: {max_error_RNEA_nocomp_init}")
|
| 84 |
+
print(f"Max error RNEA Pinn before contact: {max_error_RNEA_pinn_init}")
|
| 85 |
+
|
| 86 |
+
# Print the best case among all the controllers
|
| 87 |
+
# Find the best case among all the controllers
|
| 88 |
+
min_norm_error = np.min([np.linalg.norm(mean_error_ukf_pinn_init), np.linalg.norm(mean_error_ukf_nocomp_init), np.linalg.norm(mean_error_feedforward_init), np.linalg.norm(mean_error_feedforward_pinn_init), np.linalg.norm(mean_error_RNEA_nocomp_init), np.linalg.norm(mean_error_RNEA_pinn_init)])
|
| 89 |
+
# Which gave the best norm error?
|
| 90 |
+
# if np.linalg.norm(mean_error_ukf_pinn_init) == min_norm_error:
|
| 91 |
+
# print(">>>>>>>>>>>>> Best case before contact: UKF PINN")
|
| 92 |
+
# elif np.linalg.norm(mean_error_ukf_nocomp_init) == min_norm_error:
|
| 93 |
+
# print(">>>>>>>>>>>>> Best case before contact: UKF No Compensation")
|
| 94 |
+
# elif np.linalg.norm(mean_error_feedforward_init) == min_norm_error:
|
| 95 |
+
# print(">>>>>>>>>>>>> Best case before contact: Feedforward")
|
| 96 |
+
# elif np.linalg.norm(mean_error_feedforward_pinn_init) == min_norm_error:
|
| 97 |
+
# print(">>>>>>>>>>>>> Best case before contact: Feedforward PINN")
|
| 98 |
+
# elif np.linalg.norm(mean_error_RNEA_nocomp_init) == min_norm_error:
|
| 99 |
+
# print(">>>>>>>>>>>>> Best case before contact: RNEA No Compensation")
|
| 100 |
+
# elif np.linalg.norm(mean_error_RNEA_pinn_init) == min_norm_error:
|
| 101 |
+
# print(">>>>>>>>>>>>> Best case before contact: RNEA PINN")
|
| 102 |
+
|
| 103 |
+
# Print the mean error per each component x, y, z and each dataset, after the first contact
|
| 104 |
+
print(">>>>>>>>>>>>> Mean error after contact")
|
| 105 |
+
print(f"Mean error UKF Pinn after contacts: {mean_error_ukf_pinn}")
|
| 106 |
+
print(f"Mean error UKF No Compensation after contacts: {mean_error_ukf_nocomp}")
|
| 107 |
+
print(f"Mean error Feedforward after contacts: {mean_error_feedforward}")
|
| 108 |
+
print(f"Mean error Feedforward Pinn after contacts: {mean_error_feedforward_pinn}")
|
| 109 |
+
print(f"Mean error RNEA No Compensation after contacts: {mean_error_RNEA_nocomp}")
|
| 110 |
+
print(f"Mean error RNEA Pinn after contacts: {mean_error_RNEA_pinn}")
|
| 111 |
+
|
| 112 |
+
# Print the best case among all the controllers
|
| 113 |
+
# Find the best case among all the controllers
|
| 114 |
+
min_norm_error = np.min([np.linalg.norm(mean_error_ukf_pinn), np.linalg.norm(mean_error_ukf_nocomp), np.linalg.norm(mean_error_feedforward), np.linalg.norm(mean_error_feedforward_pinn), np.linalg.norm(mean_error_RNEA_nocomp), np.linalg.norm(mean_error_RNEA_pinn)])
|
| 115 |
+
# Which gave the best norm error?
|
| 116 |
+
# if np.linalg.norm(mean_error_ukf_pinn) == min_norm_error:
|
| 117 |
+
# print(">>>>>>>>>>>>> Best case after contacts: UKF PINN")
|
| 118 |
+
# elif np.linalg.norm(mean_error_ukf_nocomp) == min_norm_error:
|
| 119 |
+
# print(">>>>>>>>>>>>> Best case after contacts: UKF No Compensation")
|
| 120 |
+
# elif np.linalg.norm(mean_error_feedforward) == min_norm_error:
|
| 121 |
+
# print(">>>>>>>>>>>>> Best case after contacts: Feedforward")
|
| 122 |
+
# elif np.linalg.norm(mean_error_feedforward_pinn) == min_norm_error:
|
| 123 |
+
# print(">>>>>>>>>>>>> Best case after contacts: Feedforward PINN")
|
| 124 |
+
# elif np.linalg.norm(mean_error_RNEA_nocomp) == min_norm_error:
|
| 125 |
+
# print(">>>>>>>>>>>>> Best case after contacts: RNEA No Compensation")
|
| 126 |
+
# elif np.linalg.norm(mean_error_RNEA_pinn) == min_norm_error:
|
| 127 |
+
# print(">>>>>>>>>>>>> Best case after contacts: RNEA PINN")
|
| 128 |
+
|
| 129 |
+
print(">>>>>>>>>>>>> Max error after contact")
|
| 130 |
+
print(f"Max error UKF Pinn after contacts: {max_error_ukf_pinn}")
|
| 131 |
+
print(f"Max error UKF No Compensation after contacts: {max_error_ukf_nocomp}")
|
| 132 |
+
print(f"Max error Feedforward after contacts: {max_error_feedforward}")
|
| 133 |
+
print(f"Max error Feedforward Pinn after contacts: {max_error_feedforward_pinn}")
|
| 134 |
+
print(f"Max error RNEA No Compensation after contacts: {max_error_RNEA_nocomp}")
|
| 135 |
+
print(f"Max error RNEA Pinn after contacts: {max_error_RNEA_pinn}")
|
| 136 |
+
|
| 137 |
+
# Print the best case among all the controllers
|
| 138 |
+
# Find the best case among all the controllers
|
| 139 |
+
min_norm_error = np.min([np.linalg.norm(mean_error_ukf_pinn), np.linalg.norm(mean_error_ukf_nocomp), np.linalg.norm(mean_error_feedforward), np.linalg.norm(mean_error_feedforward_pinn), np.linalg.norm(mean_error_RNEA_nocomp), np.linalg.norm(mean_error_RNEA_pinn)])
|
| 140 |
+
# Which gave the best norm error?
|
| 141 |
+
# if np.linalg.norm(mean_error_ukf_pinn) == min_norm_error:
|
| 142 |
+
# print(">>>>>>>>>>>>> Best case after contacts: UKF PINN")
|
| 143 |
+
# elif np.linalg.norm(mean_error_ukf_nocomp) == min_norm_error:
|
| 144 |
+
# print(">>>>>>>>>>>>> Best case after contacts: UKF No Compensation")
|
| 145 |
+
# elif np.linalg.norm(mean_error_feedforward) == min_norm_error:
|
| 146 |
+
# print(">>>>>>>>>>>>> Best case after contacts: Feedforward")
|
| 147 |
+
# elif np.linalg.norm(mean_error_feedforward_pinn) == min_norm_error:
|
| 148 |
+
# print(">>>>>>>>>>>>> Best case after contacts: Feedforward PINN")
|
| 149 |
+
# elif np.linalg.norm(mean_error_RNEA_nocomp) == min_norm_error:
|
| 150 |
+
# print(">>>>>>>>>>>>> Best case after contacts: RNEA No Compensation")
|
| 151 |
+
# elif np.linalg.norm(mean_error_RNEA_pinn) == min_norm_error:
|
| 152 |
+
# print(">>>>>>>>>>>>> Best case after contacts: RNEA PINN")
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
# Compute the avarage delay of the tracking considering the desired and the measured CoM position
|
| 156 |
+
# knowing that data are logged at 100 Hz
|
| 157 |
+
# delay_ukf_pinn = np.mean(np.abs(np.diff(np.where(error_ukf_pinn > 0.01)[0])))
|
| 158 |
+
# print(f"UKF_PINN Average delay: {delay_ukf_pinn/100} seconds")
|
| 159 |
+
|
| 160 |
+
# delay_ukf_nocomp = np.mean(np.abs(np.diff(np.where(error_ukf_nocomp > 0.01)[0])))
|
| 161 |
+
# print(f"UKF_NoComp Average delay: {delay_ukf_nocomp/100} seconds")
|
| 162 |
+
|
| 163 |
+
# delay_feedforward = np.mean(np.abs(np.diff(np.where(error_feedforward > 0.01)[0])))
|
| 164 |
+
# print(f"Feedforward Average delay: {delay_feedforward/100} seconds")
|
| 165 |
+
|
| 166 |
+
# delay_feedforward_pinn = np.mean(np.abs(np.diff(np.where(error_feedforward_pinn > 0.01)[0])))
|
| 167 |
+
# print(f"Feedforward_PINN Average delay: {delay_feedforward_pinn/100} seconds")
|
| 168 |
+
|
| 169 |
+
# # Plot the error and the tracking in two different plots, draw three subplots for x, y, z with a for loop
|
| 170 |
+
# fig, axs = plt.subplots(3, 1, figsize=(10, 10))
|
| 171 |
+
# for i, ax in enumerate(axs):
|
| 172 |
+
# ax.plot(ukf_pinn_des[:, i], label="Desired")
|
| 173 |
+
# ax.plot(ukf_pinn_meas[:, i], label="Measured ukf_pinn")
|
| 174 |
+
# ax.plot(ukf_nocomp_meas[:, i], label="Measured ukf_nocomp")
|
| 175 |
+
# ax.plot(feedforward_meas[:, i], label="Measured feedforward")
|
| 176 |
+
# ax.plot(feedforward_pinn_meas[:, i], label="Measured feedforward_pinn")
|
| 177 |
+
# ax.set_title(f"CoM position {['x', 'y', 'z'][i]}")
|
| 178 |
+
# ax.legend()
|
| 179 |
+
|
| 180 |
+
# # Same for the error
|
| 181 |
+
# fig, axs = plt.subplots(3, 1, figsize=(10, 10))
|
| 182 |
+
# for i, ax in enumerate(axs):
|
| 183 |
+
# ax.plot(error_ukf_pinn[:, i], label="Error ukf_pinn")
|
| 184 |
+
# ax.plot(error_ukf_nocomp[:, i], label="Error ukf_nocomp")
|
| 185 |
+
# ax.plot(error_feedforward[:, i], label="Error feedforward")
|
| 186 |
+
# ax.plot(error_feedforward_pinn[:, i], label="Error feedforward_pinn")
|
| 187 |
+
# ax.set_title(f"Error {['x', 'y', 'z'][i]}")
|
| 188 |
+
# plt.show()
|
| 189 |
+
|
| 190 |
+
# Now find the max of each of the 4 desired trajectories and align the 4 trajectories
|
| 191 |
+
# on the max values of the desired trajectories to compare the tracking
|
| 192 |
+
|
| 193 |
+
# # Find the max of each desired trajectory
|
| 194 |
+
# max_ukf_pinn = np.max(ukf_pinn_des[:, 1])
|
| 195 |
+
# max_ukf_nocomp = np.max(ukf_nocomp_des[:, 1])
|
| 196 |
+
# max_feedforward = np.max(feedforward_des[:, 1])
|
| 197 |
+
# max_feedforward_pinn = np.max(feedforward_pinn_des[:, 1])
|
| 198 |
+
|
| 199 |
+
# # Find the index of the max value
|
| 200 |
+
# idx_ukf_pinn = np.where(ukf_pinn_des[:, 1] == max_ukf_pinn)[0][0]
|
| 201 |
+
# idx_ukf_nocomp = np.where(ukf_nocomp_des[:, 1] == max_ukf_nocomp)[0][0]
|
| 202 |
+
# idx_feedforward = np.where(feedforward_des[:, 1] == max_feedforward)[0][0]
|
| 203 |
+
# idx_feedforward_pinn = np.where(feedforward_pinn_des[:, 1] == max_feedforward_pinn)[0][0]
|
| 204 |
+
|
| 205 |
+
# # Align the trajectories
|
| 206 |
+
# ukf_pinn_des = ukf_pinn_des[idx_ukf_pinn:]
|
| 207 |
+
# ukf_pinn_meas = ukf_pinn_meas[idx_ukf_pinn:]
|
| 208 |
+
# ukf_nocomp_des = ukf_nocomp_des[idx_ukf_nocomp:]
|
| 209 |
+
# ukf_nocomp_meas = ukf_nocomp_meas[idx_ukf_nocomp:]
|
| 210 |
+
# feedforward_des = feedforward_des[idx_feedforward:]
|
| 211 |
+
# feedforward_meas = feedforward_meas[idx_feedforward:]
|
| 212 |
+
# feedforward_pinn_des = feedforward_pinn_des[idx_feedforward_pinn:]
|
| 213 |
+
# feedforward_pinn_meas = feedforward_pinn_meas[idx_feedforward_pinn:]
|
| 214 |
+
|
| 215 |
+
# # Align also the errors
|
| 216 |
+
# error_ukf_pinn = error_ukf_pinn[idx_ukf_pinn:]
|
| 217 |
+
# error_ukf_nocomp = error_ukf_nocomp[idx_ukf_nocomp:]
|
| 218 |
+
# error_feedforward = error_feedforward[idx_feedforward:]
|
| 219 |
+
# error_feedforward_pinn = error_feedforward_pinn[idx_feedforward_pinn:]
|
| 220 |
+
|
| 221 |
+
# Plot the error and the tracking in two different plots, draw three subplots for x, y, z with a for loop
|
| 222 |
+
# Plot time on x axis knowing that samples are logged at 100 Hz
|
| 223 |
+
# Add labels x and y axis, title, and legend
|
| 224 |
+
end_index = 9000
|
| 225 |
+
start_index = 300
|
| 226 |
+
time = np.arange(start_index/100, end_index/100, 1/100)
|
| 227 |
+
fig, axs = plt.subplots(3, 1, figsize=(10, 10))
|
| 228 |
+
for i, ax in enumerate(axs):
|
| 229 |
+
ax.plot(time, ukf_pinn_des[start_index:end_index, i], label="Desired")
|
| 230 |
+
# ax.plot(time, RNEA_pinn_des[start_index:end_index, i], label="Des2")
|
| 231 |
+
ax.plot(time, feedforward_meas[start_index:end_index, i], label="Feedforward")
|
| 232 |
+
ax.plot(time, RNEA_pinn_meas[start_index:end_index, i], label="RNEA-PINN")
|
| 233 |
+
ax.plot(time, ukf_pinn_meas[start_index:end_index, i], label="UKF-PINN")
|
| 234 |
+
# ax.set_title(f"CoM position {['x', 'y', 'z'][i]}")
|
| 235 |
+
ax.set_ylabel(f"CoM position {['x', 'y', 'z'][i]}" + " [m]")
|
| 236 |
+
ax.legend()
|
| 237 |
+
ax.set_xlabel("Time [s]")
|
| 238 |
+
# Set suptitle
|
| 239 |
+
fig.suptitle("CoM position tracking comparison")
|
| 240 |
+
|
| 241 |
+
# Plot four subplots for the tracking of the com position for the cases of the four controllers
|
| 242 |
+
fig, axs = plt.subplots(2, 2, figsize=(10, 10))
|
| 243 |
+
# First plot is for feedforward_des and feedforward_meas
|
| 244 |
+
axs[0, 0].plot(time, feedforward_des[start_index:end_index, 1]*1000, label="Desired")
|
| 245 |
+
axs[0, 0].plot(time, feedforward_meas[start_index:end_index, 1]*1000, label="Measured")
|
| 246 |
+
axs[0, 0].set_title("Feedforward")
|
| 247 |
+
axs[0, 0].set_xlabel("Time [s]")
|
| 248 |
+
axs[0, 0].set_ylabel("CoM y [mm]")
|
| 249 |
+
axs[0, 0].legend()
|
| 250 |
+
# Second plot is for feedforward_pinn_des and feedforward_pinn_meas
|
| 251 |
+
axs[0, 1].plot(time, feedforward_pinn_des[start_index:end_index, 1]*1000, label="Desired")
|
| 252 |
+
axs[0, 1].plot(time, feedforward_pinn_meas[start_index:end_index, 1]*1000, label="Measured")
|
| 253 |
+
axs[0, 1].set_title("Feedforward PINN")
|
| 254 |
+
axs[0, 1].set_xlabel("Time [s]")
|
| 255 |
+
axs[0, 1].set_ylabel("CoM y [mm]")
|
| 256 |
+
axs[0, 1].legend()
|
| 257 |
+
# Third plot is for RNEA_pinn_des and RNEA_pinn_meas
|
| 258 |
+
axs[1, 0].plot(time, RNEA_pinn_des[start_index:end_index, 1]*1000, label="Desired")
|
| 259 |
+
axs[1, 0].plot(time, RNEA_pinn_meas[start_index:end_index, 1]*1000, label="Measured")
|
| 260 |
+
axs[1, 0].set_title("RNEA PINN")
|
| 261 |
+
axs[1, 0].set_xlabel("Time [s]")
|
| 262 |
+
axs[1, 0].set_ylabel("CoM y [mm]")
|
| 263 |
+
axs[1, 0].legend()
|
| 264 |
+
# Fourth plot is for ukf_pinn_des and ukf_pinn_meas
|
| 265 |
+
axs[1, 1].plot(time, ukf_pinn_des[start_index:end_index, 1]*1000, label="Desired")
|
| 266 |
+
axs[1, 1].plot(time, ukf_pinn_meas[start_index:end_index, 1]*1000, label="Measured")
|
| 267 |
+
axs[1, 1].set_title("UKF PINN")
|
| 268 |
+
axs[1, 1].set_xlabel("Time [s]")
|
| 269 |
+
axs[1, 1].set_ylabel("CoM y [mm]")
|
| 270 |
+
axs[1, 1].legend()
|
| 271 |
+
plt.show()
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
# # Same for the error
|
| 275 |
+
fig, axs = plt.subplots(3, 1, figsize=(10, 10))
|
| 276 |
+
for i, ax in enumerate(axs):
|
| 277 |
+
# ax.plot(time, error_feedforward[start_index:end_index, i], label="Feedforward")
|
| 278 |
+
ax.plot(time, error_RNEA_pinn[start_index:end_index, i], label="RNEA PINN")
|
| 279 |
+
ax.plot(time, error_ukf_pinn[start_index:end_index, i], label="UKF PINN")
|
| 280 |
+
ax.set_ylabel(f"Error {['x', 'y', 'z'][i]}" + " [m]")
|
| 281 |
+
ax.legend()
|
| 282 |
+
ax.set_xlabel("Time [s]")
|
| 283 |
+
# Set suptitle
|
| 284 |
+
fig.suptitle("CoM position tracking error comparison")
|
| 285 |
+
|
| 286 |
+
plt.show()
|
| 287 |
+
|
FirstSubmission/PaperRAL_ScriptAndVideo/evaluate_joint_torques.py
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
|
| 4 |
+
def extract_data(data, joints):
|
| 5 |
+
|
| 6 |
+
data_des = data["balancing"]["joint_state"]["torque"]["desired"]["data"]
|
| 7 |
+
data_des_joints = data["balancing"]["joint_state"]["torque"]["desired"]["elements_names"]
|
| 8 |
+
data_des_time = data["balancing"]["joint_state"]["torque"]["desired"]["timestamps"]
|
| 9 |
+
idx = [data_des_joints.index(joint) for joint in joints]
|
| 10 |
+
data_des = data_des[:, idx]
|
| 11 |
+
|
| 12 |
+
data_meas = data["joints_state"]["torques"]["data"]
|
| 13 |
+
data_meas_joints = data["joints_state"]["torques"]["elements_names"]
|
| 14 |
+
data_meas_time = data["joints_state"]["torques"]["timestamps"]
|
| 15 |
+
# Find indexes of the joints of the desired torques in the measured torques
|
| 16 |
+
idx = [data_meas_joints.index(joint) for joint in joints]
|
| 17 |
+
# Extract only the desired torques from the measured torques
|
| 18 |
+
data_meas = data_meas[:, idx]
|
| 19 |
+
# Align first sample to the first sample of the desired torques, finding first sample of time desired in measured
|
| 20 |
+
idx = np.where(data_meas_time >= data_des_time[0])[0][0]
|
| 21 |
+
# Cancel all samples of measured before the first sample of desired
|
| 22 |
+
data_meas = data_meas[idx:]
|
| 23 |
+
data_meas_time = data_meas_time[idx:]
|
| 24 |
+
idx = np.where(data_meas_time >= data_des_time[-1])[0][0]
|
| 25 |
+
# Cancel all samples of measured after the last sample of desired
|
| 26 |
+
data_meas = data_meas[:idx]
|
| 27 |
+
data_meas_time = data_meas_time[:idx]
|
| 28 |
+
data_des_time = data_des_time - data_des_time[0]
|
| 29 |
+
data_meas_time = data_meas_time - data_meas_time[0]
|
| 30 |
+
|
| 31 |
+
# Now interpolate time and measures and resample to 0.01 to be sure to have same number of samples
|
| 32 |
+
data_des_time_resampled = np.arange(0, data_des_time[-1], 0.01)
|
| 33 |
+
data_meas_time_resampled = np.arange(0, data_meas_time[-1], 0.01)
|
| 34 |
+
|
| 35 |
+
# Cut to the same length
|
| 36 |
+
if len(data_des_time_resampled) < len(data_meas_time_resampled):
|
| 37 |
+
data_meas_time_resampled = data_meas_time_resampled[:len(data_des_time_resampled)]
|
| 38 |
+
else:
|
| 39 |
+
if len(data_meas_time_resampled) < len(data_des_time_resampled):
|
| 40 |
+
data_des_time_resampled = data_des_time_resampled[:len(data_meas_time_resampled)]
|
| 41 |
+
|
| 42 |
+
data_des_resampled = np.zeros((len(data_des_time_resampled), len(joints)))
|
| 43 |
+
data_meas_resampled = np.zeros((len(data_meas_time_resampled), len(joints)))
|
| 44 |
+
|
| 45 |
+
for i in range(len(joints)):
|
| 46 |
+
data_des_resampled[:, i] = np.interp(data_des_time_resampled, data_des_time, data_des[:, i])
|
| 47 |
+
data_meas_resampled[:, i] = np.interp(data_meas_time_resampled, data_meas_time, data_meas[:, i])
|
| 48 |
+
|
| 49 |
+
return data_des_resampled, data_des_time_resampled, data_meas_resampled, data_meas_time_resampled
|
| 50 |
+
|
| 51 |
+
def evaluate_torques(ukf_pinn, ukf_nocomp, feedforward, feedforward_pinn, RNEA_nocomp, RNEA_pinn):\
|
| 52 |
+
|
| 53 |
+
joints = ["torso_roll", "torso_yaw",
|
| 54 |
+
"l_shoulder_pitch", "l_shoulder_roll", "l_shoulder_yaw", "l_elbow",
|
| 55 |
+
"r_shoulder_pitch", "r_shoulder_roll", "r_shoulder_yaw", "r_elbow",
|
| 56 |
+
"l_hip_pitch", "l_hip_roll", "l_hip_yaw", "l_knee", "l_ankle_pitch", "l_ankle_roll",
|
| 57 |
+
"r_hip_pitch", "r_hip_roll", "r_hip_yaw", "r_knee", "r_ankle_pitch", "r_ankle_roll"]
|
| 58 |
+
|
| 59 |
+
[ukf_pinn_des, ukf_pinn_des_time, ukf_pinn_meas, ukf_pinn_meas_time] = extract_data(ukf_pinn, joints)
|
| 60 |
+
[ukf_nocomp_des, ukf_nocomp_des_time, ukf_nocomp_meas, ukf_nocomp_meas_time] = extract_data(ukf_nocomp, joints)
|
| 61 |
+
[feedforward_des, feedforward_des_time, feedforward_meas, feedforward_meas_time] = extract_data(feedforward, joints)
|
| 62 |
+
[feedforward_pinn_des, feedforward_pinn_des_time, feedforward_pinn_meas, feedforward_pinn_meas_time] = extract_data(feedforward_pinn, joints)
|
| 63 |
+
[RNEA_nocomp_des, RNEA_nocomp_des_time, RNEA_nocomp_meas, RNEA_nocomp_meas_time] = extract_data(RNEA_nocomp, joints)
|
| 64 |
+
[RNEA_pinn_des, RNEA_pinn_des_time, RNEA_pinn_meas, RNEA_pinn_meas_time] = extract_data(RNEA_pinn, joints)
|
| 65 |
+
|
| 66 |
+
for i in range(np.shape(ukf_pinn_des)[1]):
|
| 67 |
+
ukf_pinn_des[:60, i] = ukf_pinn_des[61, i]
|
| 68 |
+
ukf_pinn_meas[:60, i] = ukf_pinn_meas[61, i]
|
| 69 |
+
RNEA_pinn_des[:60, i] = RNEA_pinn_des[61, i]
|
| 70 |
+
RNEA_pinn_meas[:60, i] = RNEA_pinn_meas[61, i]
|
| 71 |
+
RNEA_pinn_des[-100:, i] = RNEA_pinn_des[-101, i]
|
| 72 |
+
RNEA_pinn_meas[-100:, i] = RNEA_pinn_meas[-101, i]
|
| 73 |
+
|
| 74 |
+
# Compute the mean squared error
|
| 75 |
+
ukf_pinn_mse = np.mean((ukf_pinn_des - ukf_pinn_meas) ** 2)
|
| 76 |
+
ukf_nocomp_mse = np.mean((ukf_nocomp_des - ukf_nocomp_meas) ** 2)
|
| 77 |
+
feedforward_mse = np.mean((feedforward_des - feedforward_meas) ** 2)
|
| 78 |
+
feedforward_pinn_mse = np.mean((feedforward_pinn_des - feedforward_pinn_meas) ** 2)
|
| 79 |
+
RNEA_nocomp_mse = np.mean((RNEA_nocomp_des - RNEA_nocomp_meas) ** 2)
|
| 80 |
+
RNEA_pinn_mse = np.mean((RNEA_pinn_des - RNEA_pinn_meas) ** 2)
|
| 81 |
+
|
| 82 |
+
# Now the root mean squared error
|
| 83 |
+
ukf_pinn_rmse = np.sqrt(ukf_pinn_mse)
|
| 84 |
+
ukf_nocomp_rmse = np.sqrt(ukf_nocomp_mse)
|
| 85 |
+
feedforward_rmse = np.sqrt(feedforward_mse)
|
| 86 |
+
feedforward_pinn_rmse = np.sqrt(feedforward_pinn_mse)
|
| 87 |
+
RNEA_nocomp_rmse = np.sqrt(RNEA_nocomp_mse)
|
| 88 |
+
RNEA_pinn_rmse = np.sqrt(RNEA_pinn_mse)
|
| 89 |
+
|
| 90 |
+
# Now the mean absolute error
|
| 91 |
+
ukf_pinn_mae = np.mean(np.abs(ukf_pinn_des - ukf_pinn_meas))
|
| 92 |
+
ukf_nocomp_mae = np.mean(np.abs(ukf_nocomp_des - ukf_nocomp_meas))
|
| 93 |
+
feedforward_mae = np.mean(np.abs(feedforward_des - feedforward_meas))
|
| 94 |
+
feedforward_pinn_mae = np.mean(np.abs(feedforward_pinn_des - feedforward_pinn_meas))
|
| 95 |
+
RNEA_nocomp_mae = np.mean(np.abs(RNEA_nocomp_des - RNEA_nocomp_meas))
|
| 96 |
+
RNEA_pinn_mae = np.mean(np.abs(RNEA_pinn_des - RNEA_pinn_meas))
|
| 97 |
+
|
| 98 |
+
# Print the results
|
| 99 |
+
print("Results, Torque Tracking")
|
| 100 |
+
print("FEEDFORWARD")
|
| 101 |
+
print("MSE: ", feedforward_mse)
|
| 102 |
+
print("RMSE: ", feedforward_rmse)
|
| 103 |
+
print("MAE: ", feedforward_mae)
|
| 104 |
+
print("RNEA NO COMP")
|
| 105 |
+
print("MSE: ", RNEA_nocomp_mse)
|
| 106 |
+
print("RMSE: ", RNEA_nocomp_rmse)
|
| 107 |
+
print("MAE: ", RNEA_nocomp_mae)
|
| 108 |
+
print("UKF NO COMP")
|
| 109 |
+
print("MSE: ", ukf_nocomp_mse)
|
| 110 |
+
print("RMSE: ", ukf_nocomp_rmse)
|
| 111 |
+
print("MAE: ", ukf_nocomp_mae)
|
| 112 |
+
print("FEEDFORWARD PINN")
|
| 113 |
+
print("MSE: ", feedforward_pinn_mse)
|
| 114 |
+
print("RMSE: ", feedforward_pinn_rmse)
|
| 115 |
+
print("MAE: ", feedforward_pinn_mae)
|
| 116 |
+
print("RNEA PINN")
|
| 117 |
+
print("MSE: ", RNEA_pinn_mse)
|
| 118 |
+
print("RMSE: ", RNEA_pinn_rmse)
|
| 119 |
+
print("MAE: ", RNEA_pinn_mae)
|
| 120 |
+
print("UKF PINN")
|
| 121 |
+
print("MSE: ", ukf_pinn_mse)
|
| 122 |
+
print("RMSE: ", ukf_pinn_rmse)
|
| 123 |
+
print("MAE: ", ukf_pinn_mae)
|
| 124 |
+
|
| 125 |
+
# Print maximum desired torque per each configuration per each joint
|
| 126 |
+
print("Results, Maximum Desired Torque")
|
| 127 |
+
print("FEEDFORWARD")
|
| 128 |
+
print("Max desired torque: ", np.max(np.abs(feedforward_des), axis=0))
|
| 129 |
+
print("RNEA NO COMP")
|
| 130 |
+
print("Max desired torque: ", np.max(np.abs(RNEA_nocomp_des), axis=0))
|
| 131 |
+
print("UKF NO COMP")
|
| 132 |
+
print("Max desired torque: ", np.max(np.abs(ukf_nocomp_des), axis=0))
|
| 133 |
+
print("FEEDFORWARD PINN")
|
| 134 |
+
print("Max desired torque: ", np.max(np.abs(feedforward_pinn_des), axis=0))
|
| 135 |
+
print("RNEA PINN")
|
| 136 |
+
print("Max desired torque: ", np.max(np.abs(RNEA_pinn_des), axis=0))
|
| 137 |
+
print("UKF PINN")
|
| 138 |
+
print("Max desired torque: ", np.max(np.abs(ukf_pinn_des), axis=0))
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
# Compute RMSE per each joint and print in table joint rows and method columns
|
| 142 |
+
print("RMSE per joint - Torque Tracking")
|
| 143 |
+
print("Joint\t\tFEEDFORWARD\tRNEA NO COMP\tUKF NO COMP\tFEEDFORWARD PINN\tRNEA PINN\tUKF PINN")
|
| 144 |
+
for i in range(22):
|
| 145 |
+
print(joints[i], "\t", np.sqrt(np.mean((feedforward_des[:, i] - feedforward_meas[:, i]) ** 2)), "\t",
|
| 146 |
+
np.sqrt(np.mean((RNEA_nocomp_des[:, i] - RNEA_nocomp_meas[:, i]) ** 2)), "\t",
|
| 147 |
+
np.sqrt(np.mean((ukf_nocomp_des[:, i] - ukf_nocomp_meas[:, i]) ** 2)), "\t",
|
| 148 |
+
np.sqrt(np.mean((feedforward_pinn_des[:, i] - feedforward_pinn_meas[:, i]) ** 2)), "\t",
|
| 149 |
+
np.sqrt(np.mean((RNEA_pinn_des[:, i] - RNEA_pinn_meas[:, i]) ** 2)), "\t",
|
| 150 |
+
np.sqrt(np.mean((ukf_pinn_des[:, i] - ukf_pinn_meas[:, i]) ** 2)))
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
# Print Energy Efficiency Data
|
| 154 |
+
# Average Torque Magnitudes: Per joint for each configuration.
|
| 155 |
+
# Maximum Torque Values: Across all joints and configurations.
|
| 156 |
+
print("Average Torque Magnitudes")
|
| 157 |
+
print("Joint\t\tFEEDFORWARD\tRNEA NO COMP\tUKF NO COMP\tFEEDFORWARD PINN\tRNEA PINN\tUKF PINN")
|
| 158 |
+
for i in range(22):
|
| 159 |
+
print(joints[i], "\t",
|
| 160 |
+
np.mean(np.abs(feedforward_des[:, i])), "\t",
|
| 161 |
+
np.mean(np.abs(RNEA_nocomp_des[:, i])), "\t",
|
| 162 |
+
np.mean(np.abs(ukf_nocomp_des[:, i])), "\t",
|
| 163 |
+
np.mean(np.abs(feedforward_pinn_des[:, i])), "\t",
|
| 164 |
+
np.mean(np.abs(RNEA_pinn_des[:, i])), "\t",
|
| 165 |
+
np.mean(np.abs(ukf_pinn_des[:, i])))
|
| 166 |
+
print("Maximum Torque Values")
|
| 167 |
+
print("FEEDFORWARD\tRNEA NO COMP\tUKF NO COMP\tFEEDFORWARD PINN\tRNEA PINN\tUKF PINN")
|
| 168 |
+
# Per each joint and each configuration
|
| 169 |
+
for i in range(22):
|
| 170 |
+
print(joints[i], "\t",
|
| 171 |
+
np.max(np.abs(feedforward_des[:, i])), "\t",
|
| 172 |
+
np.max(np.abs(feedforward_des[:, i])), "\t",
|
| 173 |
+
np.max(np.abs(RNEA_nocomp_des[:, i])), "\t",
|
| 174 |
+
np.max(np.abs(ukf_nocomp_des[:, i])), "\t",
|
| 175 |
+
np.max(np.abs(feedforward_pinn_des[:, i])), "\t",
|
| 176 |
+
np.max(np.abs(RNEA_pinn_des[:, i])), "\t",
|
| 177 |
+
np.max(np.abs(ukf_pinn_des[:, i])))
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
# Taking the torque average magnitude per each joint and configuration
|
| 181 |
+
# construct the box plot data
|
| 182 |
+
average_torque_data = [
|
| 183 |
+
[np.mean(np.abs(feedforward_des[:, i])) for i in range(22)],
|
| 184 |
+
[np.mean(np.abs(RNEA_nocomp_des[:, i])) for i in range(22)],
|
| 185 |
+
[np.mean(np.abs(ukf_nocomp_des[:, i])) for i in range(22)],
|
| 186 |
+
[np.mean(np.abs(feedforward_pinn_des[:, i])) for i in range(22)],
|
| 187 |
+
[np.mean(np.abs(RNEA_pinn_des[:, i])) for i in range(22)],
|
| 188 |
+
[np.mean(np.abs(ukf_pinn_des[:, i])) for i in range(22)]
|
| 189 |
+
]
|
| 190 |
+
# Plot the boxplot of the average torque magnitudes
|
| 191 |
+
configurations = ["Feedforward", "RNEA No Comp", "UKF No Comp", "Feedforward PINN", "RNEA PINN", "UKF PINN"]
|
| 192 |
+
plt.figure(figsize=(12, 6))
|
| 193 |
+
plt.boxplot(
|
| 194 |
+
average_torque_data,
|
| 195 |
+
labels=configurations,
|
| 196 |
+
patch_artist=True,
|
| 197 |
+
showmeans=True,
|
| 198 |
+
boxprops=dict(facecolor='lightblue', color='blue'),
|
| 199 |
+
medianprops=dict(color='red'),
|
| 200 |
+
meanprops=dict(marker='o', markerfacecolor='green', markersize=8)
|
| 201 |
+
)
|
| 202 |
+
# Increase font size of the labels configurations
|
| 203 |
+
plt.xticks(fontsize=14)
|
| 204 |
+
# Add legend and lables
|
| 205 |
+
plt.title("Distribution of Average Torque Magnitudes Across Configurations", fontsize=22)
|
| 206 |
+
plt.ylabel("Torque Magnitude (Nm)", fontsize=18)
|
| 207 |
+
plt.grid(axis='y', linestyle='--', alpha=0.7)
|
| 208 |
+
legend_elements = [
|
| 209 |
+
plt.Line2D([0], [0], color='blue', lw=2, label='Blue Box: Interquartile Range (IQR)'),
|
| 210 |
+
plt.Line2D([0], [0], color='red', lw=2, label='Red Line: Median Torque Magnitude'),
|
| 211 |
+
plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='green', markersize=8, label='Green Dot: Mean Torque Magnitude')
|
| 212 |
+
]
|
| 213 |
+
plt.ylim([0, 12])
|
| 214 |
+
plt.legend(handles=legend_elements, loc='upper left', fontsize=18)
|
| 215 |
+
plt.tight_layout()
|
| 216 |
+
# plt.show()
|
| 217 |
+
|
| 218 |
+
configurations = ["RNEA No Comp", "UKF No Comp", "RNEA PINN", "UKF PINN"]
|
| 219 |
+
|
| 220 |
+
# Compute the RMSE per each joint and configuration and plot the boxplot
|
| 221 |
+
rmse_data = [
|
| 222 |
+
# [np.sqrt(np.mean((feedforward_des[:, i] - feedforward_meas[:, i]) ** 2)) for i in range(22)],
|
| 223 |
+
[np.sqrt(np.mean((RNEA_nocomp_des[:, i] - RNEA_nocomp_meas[:, i]) ** 2)) for i in range(22)],
|
| 224 |
+
[np.sqrt(np.mean((ukf_nocomp_des[:, i] - ukf_nocomp_meas[:, i]) ** 2)) for i in range(22)],
|
| 225 |
+
# [np.sqrt(np.mean((feedforward_pinn_des[:, i] - feedforward_pinn_meas[:, i]) ** 2)) for i in range(22)],
|
| 226 |
+
[np.sqrt(np.mean((RNEA_pinn_des[:, i] - RNEA_pinn_meas[:, i]) ** 2)) for i in range(22)],
|
| 227 |
+
[np.sqrt(np.mean((ukf_pinn_des[:, i] - ukf_pinn_meas[:, i]) ** 2)) for i in range(22)]
|
| 228 |
+
]
|
| 229 |
+
# Plot the boxplot of the RMSE per each joint and configuration
|
| 230 |
+
plt.figure(figsize=(12, 6))
|
| 231 |
+
plt.boxplot(
|
| 232 |
+
rmse_data,
|
| 233 |
+
labels=configurations,
|
| 234 |
+
patch_artist=True,
|
| 235 |
+
showmeans=True,
|
| 236 |
+
boxprops=dict(facecolor='lightblue', color='blue'),
|
| 237 |
+
medianprops=dict(color='red'),
|
| 238 |
+
meanprops=dict(marker='o', markerfacecolor='green', markersize=8)
|
| 239 |
+
)
|
| 240 |
+
# Increase font size of the labels configurations
|
| 241 |
+
plt.xticks(fontsize=14)
|
| 242 |
+
# Add legend and lables
|
| 243 |
+
plt.title("Distribution of RMSE Across Configurations", fontsize=22)
|
| 244 |
+
plt.ylabel("RMSE (Nm)", fontsize=18)
|
| 245 |
+
plt.grid(axis='y', linestyle='--', alpha=0.7)
|
| 246 |
+
legend_elements = [
|
| 247 |
+
plt.Line2D([0], [0], color='blue', lw=2, label='Blue Box: Interquartile Range (IQR)'),
|
| 248 |
+
plt.Line2D([0], [0], color='red', lw=2, label='Red Line: Median RMSE'),
|
| 249 |
+
plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='green', markersize=8, label='Green Dot: Mean RMSE')
|
| 250 |
+
]
|
| 251 |
+
plt.legend(handles=legend_elements, loc='upper left', fontsize=18)
|
| 252 |
+
plt.tight_layout()
|
| 253 |
+
plt.ylim([0, 13])
|
| 254 |
+
plt.show()
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
# # Plot the results with one subplot per each joint, the joints and so complumns are 23
|
| 258 |
+
# plt.figure()
|
| 259 |
+
# for i in range(22):
|
| 260 |
+
# plt.subplot(6, 4, i + 1)
|
| 261 |
+
# plt.plot(ukf_pinn_des_time, ukf_pinn_des[:, i], label="Desired")
|
| 262 |
+
# plt.plot(ukf_pinn_meas_time, ukf_pinn_meas[:, i], label="Measured")
|
| 263 |
+
# plt.title(joints[i])
|
| 264 |
+
# # Insert axes lables
|
| 265 |
+
# # plt.xlabel("Time [s]")
|
| 266 |
+
# # plt.ylabel("Torque [Nm]")
|
| 267 |
+
# plt.legend()
|
| 268 |
+
|
| 269 |
+
# Plot desired torques of the six datasets
|
| 270 |
+
plt.figure()
|
| 271 |
+
# Add horizontal space between the subplots
|
| 272 |
+
plt.subplots_adjust(hspace=0.7)
|
| 273 |
+
for i in range(22):
|
| 274 |
+
plt.subplot(6, 4, i + 1)
|
| 275 |
+
plt.plot(feedforward_des_time, feedforward_des[:, i], label="FEEDFORWARD")
|
| 276 |
+
plt.plot(RNEA_nocomp_des_time, RNEA_nocomp_des[:, i], label="RNEA NO COMP")
|
| 277 |
+
plt.plot(ukf_nocomp_des_time, ukf_nocomp_des[:, i], label="UKF NO COMP")
|
| 278 |
+
plt.plot(feedforward_pinn_des_time, feedforward_pinn_des[:, i], label="FEEDFORWARD PINN")
|
| 279 |
+
plt.plot(RNEA_pinn_des_time, RNEA_pinn_des[:, i], label="RNEA PINN")
|
| 280 |
+
plt.plot(ukf_pinn_des_time, ukf_pinn_des[:, i], label="UKF PINN")
|
| 281 |
+
plt.title(joints[i], fontsize=14)
|
| 282 |
+
# Limit x axis lim to 30
|
| 283 |
+
plt.xlim([0, 30])
|
| 284 |
+
# Increase tick lable sizes
|
| 285 |
+
plt.xticks(fontsize=12)
|
| 286 |
+
plt.yticks(fontsize=12)
|
| 287 |
+
# Insert axes label
|
| 288 |
+
# if i > 10:
|
| 289 |
+
# plt.xlabel("Time [s]", fontsize=16)
|
| 290 |
+
# if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 291 |
+
# plt.ylabel(r"$\tau_j^d$ (Nm)", fontsize=16)
|
| 292 |
+
# Print legend only ones outside the graphs
|
| 293 |
+
# Set position for legend
|
| 294 |
+
plt.legend(loc='center left', bbox_to_anchor=(1.3, 0.1), fontsize=16)
|
| 295 |
+
# Increase font size of suptitle
|
| 296 |
+
plt.suptitle("Desired torques", fontsize=20)
|
| 297 |
+
# plt.show()
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
# configurations = ["Feedforward", "RNEA No Comp", "UKF No Comp", "Feedforward PINN", "RNEA PINN", "UKF PINN"]
|
| 301 |
+
|
| 302 |
+
# plt.figure(figsize=(14, 8))
|
| 303 |
+
# plt.boxplot(
|
| 304 |
+
# average_torque_data,
|
| 305 |
+
# labels=configurations,
|
| 306 |
+
# patch_artist=True,
|
| 307 |
+
# showmeans=True,
|
| 308 |
+
# boxprops=dict(facecolor='lightblue', color='blue'),
|
| 309 |
+
# medianprops=dict(color='red'),
|
| 310 |
+
# meanprops=dict(marker='o', markerfacecolor='green', markersize=8)
|
| 311 |
+
# )
|
| 312 |
+
|
| 313 |
+
# # Add titles and labels
|
| 314 |
+
# plt.title("Distribution of Average Torque Magnitudes Across Configurations", fontsize=16)
|
| 315 |
+
# plt.ylabel("Torque Magnitude (Nm)", fontsize=14)
|
| 316 |
+
# plt.grid(axis='y', linestyle='--', alpha=0.7)
|
| 317 |
+
|
| 318 |
+
# # Add a legend
|
| 319 |
+
# legend_elements = [
|
| 320 |
+
# plt.Line2D([0], [0], color='blue', lw=2, label='Blue Box: Interquartile Range (IQR)'),
|
| 321 |
+
# plt.Line2D([0], [0], color='red', lw=2, label='Red Line: Median Torque Magnitude'),
|
| 322 |
+
# plt.Line2D([0], [0], marker='o', color='w', markerfacecolor='green', markersize=8, label='Green Dot: Mean Torque Magnitude')
|
| 323 |
+
# ]
|
| 324 |
+
# plt.legend(handles=legend_elements, loc='upper right', fontsize=10)
|
| 325 |
+
|
| 326 |
+
# # Display the plot
|
| 327 |
+
# plt.tight_layout()
|
| 328 |
+
# plt.show()
|
| 329 |
+
|
| 330 |
+
samples = 2000
|
| 331 |
+
|
| 332 |
+
# Plot torque tracking of main joints allowing the motion of the CoM trajectory for the UKF_PINN configuration
|
| 333 |
+
plt.figure()
|
| 334 |
+
# Add horizontal space between the subplots
|
| 335 |
+
plt.subplots_adjust(hspace=0.7)
|
| 336 |
+
for i in range(2):
|
| 337 |
+
plt.subplot(5, 3, i+1)
|
| 338 |
+
plt.plot(ukf_pinn_des_time[:samples], ukf_pinn_des[:samples, i], label="Desired " + joints[i])
|
| 339 |
+
plt.plot(ukf_pinn_meas_time[:samples], ukf_pinn_meas[:samples, i], label="Measured " + joints[i])
|
| 340 |
+
# plt.xlabel("Time (s)", fontsize=14)
|
| 341 |
+
plt.ylabel("Torque (Nm)", fontsize=14)
|
| 342 |
+
plt.xticks(fontsize=12)
|
| 343 |
+
plt.yticks(fontsize=12)
|
| 344 |
+
plt.title(joints[i], fontsize=16)
|
| 345 |
+
# Plot the torque tracking
|
| 346 |
+
for i in range(10, 10+12):
|
| 347 |
+
plt.subplot(5, 3, i-7)
|
| 348 |
+
plt.plot(ukf_pinn_des_time[:samples], ukf_pinn_des[:samples, i], label="Desired " + joints[i])
|
| 349 |
+
plt.plot(ukf_pinn_meas_time[:samples], ukf_pinn_meas[:samples, i], label="Measured " + joints[i])
|
| 350 |
+
plt.title(joints[i], fontsize=16)
|
| 351 |
+
if i-7 > 11:
|
| 352 |
+
plt.xlabel("Time (s)", fontsize=14)
|
| 353 |
+
plt.ylabel("Torque (Nm)", fontsize=14)
|
| 354 |
+
plt.xticks(fontsize=12)
|
| 355 |
+
plt.yticks(fontsize=12)
|
| 356 |
+
# Add suptitle
|
| 357 |
+
plt.suptitle("Torque Tracking of Main Joints for UKF_PINN Configuration", fontsize=20)
|
| 358 |
+
# Add legend
|
| 359 |
+
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), fontsize=12)
|
| 360 |
+
# plt.tight_layout()
|
| 361 |
+
# plt.show()
|
| 362 |
+
|
| 363 |
+
# Plot the same for RNEA_PINN
|
| 364 |
+
plt.figure()
|
| 365 |
+
# Add horizontal space between the subplots
|
| 366 |
+
plt.subplots_adjust(hspace=0.7)
|
| 367 |
+
for i in range(2):
|
| 368 |
+
plt.subplot(5, 3, i+1)
|
| 369 |
+
plt.plot(RNEA_pinn_des_time[:samples], RNEA_pinn_des[:samples, i], label="Desired " + joints[i])
|
| 370 |
+
plt.plot(RNEA_pinn_meas_time[:samples], RNEA_pinn_meas[:samples, i], label="Measured " + joints[i])
|
| 371 |
+
# plt.xlabel("Time (s)", fontsize=14)
|
| 372 |
+
plt.ylabel("Torque (Nm)", fontsize=14)
|
| 373 |
+
plt.xticks(fontsize=12)
|
| 374 |
+
plt.yticks(fontsize=12)
|
| 375 |
+
plt.title(joints[i], fontsize=16)
|
| 376 |
+
# Plot the torque tracking
|
| 377 |
+
for i in range(10, 10+12):
|
| 378 |
+
plt.subplot(5, 3, i-7)
|
| 379 |
+
plt.plot(RNEA_pinn_des_time[:samples], RNEA_pinn_des[:samples, i], label="Desired " + joints[i])
|
| 380 |
+
plt.plot(RNEA_pinn_meas_time[:samples], RNEA_pinn_meas[:samples, i], label="Measured " + joints[i])
|
| 381 |
+
plt.title(joints[i], fontsize=16)
|
| 382 |
+
if i-7 > 11:
|
| 383 |
+
plt.xlabel("Time (s)", fontsize=14)
|
| 384 |
+
plt.ylabel("Torque (Nm)", fontsize=14)
|
| 385 |
+
plt.xticks(fontsize=12)
|
| 386 |
+
plt.yticks(fontsize=12)
|
| 387 |
+
# Add suptitle
|
| 388 |
+
plt.suptitle("Torque Tracking of Main Joints for RNEA_PINN Configuration", fontsize=20)
|
| 389 |
+
# Add legend
|
| 390 |
+
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), fontsize=12)
|
| 391 |
+
# plt.tight_layout()
|
| 392 |
+
plt.show()
|
FirstSubmission/PaperRAL_ScriptAndVideo/evaluate_results.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Path to the other repository
|
| 6 |
+
other_repo_path = "../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 7 |
+
|
| 8 |
+
# Add the path to sys.path
|
| 9 |
+
sys.path.append(other_repo_path)
|
| 10 |
+
|
| 11 |
+
from load_robot_logger_device_data import load_data
|
| 12 |
+
from evaluate_com import evaluate_com
|
| 13 |
+
from evaluate_joint_torques import evaluate_torques
|
| 14 |
+
|
| 15 |
+
# Load the data
|
| 16 |
+
# ukf_pinn = load_data("tuning_ukf_pinn/robot_logger_device_2024_12_17_12_21_33.mat")
|
| 17 |
+
# ukf_pinn = load_data("ukf_pinn/robot_logger_device_2024_12_11_15_50_02.mat")
|
| 18 |
+
ukf_pinn = load_data("../balancing_03_2025_resub/balancing_normale/robot_logger_device_2025_03_17_12_44_13.mat")
|
| 19 |
+
ukf_nocomp = load_data("ukf_nocomp/robot_logger_device_2024_12_11_11_42_42.mat")
|
| 20 |
+
feedforward = load_data("feedforward/robot_logger_device_2024_12_11_10_41_13.mat")
|
| 21 |
+
feedforward_pinn = load_data("feedforward_pinn/robot_logger_device_2024_12_11_11_21_59.mat")
|
| 22 |
+
# RNEA_nocomp = load_data("rnea_nocomp/robot_logger_device_2024_12_11_10_54_13.mat")
|
| 23 |
+
RNEA_nocomp = load_data("rnea_nocomp/robot_logger_device_2024_12_17_11_43_40.mat")
|
| 24 |
+
RNEA_pinn = load_data("rnea_pinn/robot_logger_device_2024_12_11_16_06_56.mat")
|
| 25 |
+
|
| 26 |
+
# Define start and end contact per each experiment
|
| 27 |
+
# ukf_pinn["start_controller_sec"] = 7.29
|
| 28 |
+
# ukf_pinn["start_contact_sec"] = np.array([67.3, 79.5, 90.3, 104.32, 117.82, 143]) - ukf_pinn["start_controller_sec"]
|
| 29 |
+
# ukf_pinn["end_contact_sec"] = np.array([73.7, 86.18, 97.55, 113.58, 125.7, 183.5]) - ukf_pinn["start_controller_sec"]
|
| 30 |
+
# ukf_pinn["end_experiment_sec"] = 200 - ukf_pinn["start_controller_sec"]
|
| 31 |
+
ukf_pinn["start_controller_sec"] = 7.29
|
| 32 |
+
ukf_pinn["start_contact_sec"] = np.array([67.3, 79.5, 90.3, 104.32, 117.82]) - ukf_pinn["start_controller_sec"]
|
| 33 |
+
ukf_pinn["end_contact_sec"] = np.array([73.7, 86.18, 97.55, 113.58, 125.7]) - ukf_pinn["start_controller_sec"]
|
| 34 |
+
ukf_pinn["end_experiment_sec"] = 125.7 - ukf_pinn["start_controller_sec"]
|
| 35 |
+
# ukf_pinn["start_controller_sec"] = 7.38
|
| 36 |
+
# ukf_pinn["start_contact_sec"] = np.array([58, 75]) - ukf_pinn["start_controller_sec"]
|
| 37 |
+
# ukf_pinn["end_contact_sec"] = np.array([74, 78]) - ukf_pinn["start_controller_sec"]
|
| 38 |
+
# ukf_pinn["end_experiment_sec"] = 78 - ukf_pinn["start_controller_sec"]
|
| 39 |
+
|
| 40 |
+
ukf_nocomp["start_controller_sec"] = 22.3
|
| 41 |
+
ukf_nocomp["start_contact_sec"] = np.array([96, 113.1, 126.25, 134.22, 152, 169.65]) - ukf_nocomp["start_controller_sec"]
|
| 42 |
+
ukf_nocomp["end_contact_sec"] = np.array([102.81, 120, 129.6, 143, 161.68, 182]) - ukf_nocomp["start_controller_sec"]
|
| 43 |
+
ukf_nocomp["end_experiment_sec"] = 184 - ukf_nocomp["start_controller_sec"]
|
| 44 |
+
|
| 45 |
+
feedforward["start_controller_sec"] = 10.14
|
| 46 |
+
feedforward["start_contact_sec"] = np.array([78.82, 91.13, 105.66, 115, 129.78, 139.47, 154.2]) - feedforward["start_controller_sec"]
|
| 47 |
+
feedforward["end_contact_sec"] = np.array([84.77, 95.97, 11.31, 123, 133.62, 147.14, 158]) - feedforward["start_controller_sec"]
|
| 48 |
+
feedforward["end_experiment_sec"] = 158 - feedforward["start_controller_sec"]
|
| 49 |
+
|
| 50 |
+
feedforward_pinn["start_controller_sec"] = 16.26
|
| 51 |
+
feedforward_pinn["start_contact_sec"] = np.array([78.64, 92.36, 110.16, 129]) - feedforward_pinn["start_controller_sec"]
|
| 52 |
+
feedforward_pinn["end_contact_sec"] = np.array([85, 99.62, 116.3, 135]) - feedforward_pinn["start_controller_sec"]
|
| 53 |
+
feedforward_pinn["end_experiment_sec"] = 135 - feedforward_pinn["start_controller_sec"]
|
| 54 |
+
|
| 55 |
+
# RNEA_nocomp["start_controller_sec"] = 6.23
|
| 56 |
+
# RNEA_nocomp["start_contact_sec"] = np.array([76, 92]) - RNEA_nocomp["start_controller_sec"]
|
| 57 |
+
# RNEA_nocomp["end_contact_sec"] = np.array([85, 101]) - RNEA_nocomp["start_controller_sec"]
|
| 58 |
+
# RNEA_nocomp["end_experiment_sec"] = 101 - RNEA_nocomp["start_controller_sec"]
|
| 59 |
+
RNEA_nocomp["start_controller_sec"] = 14.33
|
| 60 |
+
RNEA_nocomp["start_contact_sec"] = np.array([59, 76.5]) - RNEA_nocomp["start_controller_sec"]
|
| 61 |
+
RNEA_nocomp["end_contact_sec"] = np.array([70, 78.6]) - RNEA_nocomp["start_controller_sec"]
|
| 62 |
+
RNEA_nocomp["end_experiment_sec"] = 78.6 - RNEA_nocomp["start_controller_sec"]
|
| 63 |
+
|
| 64 |
+
RNEA_pinn["start_controller_sec"] = 16.27
|
| 65 |
+
RNEA_pinn["start_contact_sec"] = np.array([75, 85, 103, 115]) - RNEA_pinn["start_controller_sec"]
|
| 66 |
+
RNEA_pinn["end_contact_sec"] = np.array([82, 94, 108, 124]) - RNEA_pinn["start_controller_sec"]
|
| 67 |
+
RNEA_pinn["end_experiment_sec"] = 122 - RNEA_pinn["start_controller_sec"]
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Evaluate CoM
|
| 71 |
+
evaluate_com(ukf_pinn, ukf_nocomp, feedforward, feedforward_pinn, RNEA_nocomp, RNEA_pinn)
|
| 72 |
+
|
| 73 |
+
# Evaluate torques
|
| 74 |
+
evaluate_torques(ukf_pinn, ukf_nocomp, feedforward, feedforward_pinn, RNEA_nocomp, RNEA_pinn)
|
FirstSubmission/PaperRAL_ScriptAndVideo/log_esperimenti_buoni.txt
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
NOTA: la camera salva i video 1 ora in avanti!!!!
|
| 2 |
+
|
| 3 |
+
1) Esperimento ukf_pinn (UKF on - PINN on)
|
| 4 |
+
Commit
|
| 5 |
+
MomentumBasedTorqueControl --> https://github.com/ami-iit/element_sensorless-torque-control/commit/cc874ba1b59a3b9112b601e6e715b7c6167081af
|
| 6 |
+
robots-configuration --> https://github.com/ami-iit/robots-configuration/commit/656a37a0d3c406395f6ed6b3401ef2f8a4ad6db0
|
| 7 |
+
- robot_logger_device_2024_12_05_17_06_34.mat (senza contatti)
|
| 8 |
+
- robot_logger_device_2024_12_06_09_55_13.mat (senza contatti)
|
| 9 |
+
- robot_logger_device_2024_12_06_10_18_46.mat (senza e con contatti)
|
| 10 |
+
- robot_logger_device_2024_12_06_10_44_43.mat (senza contatti) Kp_hip_yaw=70
|
| 11 |
+
- robot_logger_device_2024_12_06_11_13_47.mat (con contatti) Kp_hip_yaw=70
|
| 12 |
+
- robot_logger_device_2024_12_06_11_17_40.mat (con contatti) Kp_hip_yaw=70
|
| 13 |
+
- robot_logger_device_2024_12_06_11_26_19.mat (senza e con contatti) Kp_hip_yaw=90 Kp_torso_yaw=20
|
| 14 |
+
- robot_logger_device_2024_12_06_11_34_31.mat (senza e con contatti) Kp_hip_yaw=90 Kp_torso_yaw=20
|
| 15 |
+
- robot_logger_device_2024_12_06_12_07_27.mat (senza e con contatti) Kp_hip_yaw=70 Kp_torso_yaw=20 Kfc_hip_yaw=0.85 static_frict_coeff=0.25 torsional_frict_coeff=0.01
|
| 16 |
+
- robot_logger_device_2024_12_06_13_06_19.mat (senza e con contatti, 2 camere) Kp_hip_yaw=80 Kp_torso_yaw=20 Kfc_hip_yaw=0.85 static_frict_coeff=0.25 torsional_frict_coeff=0.01 Kfc_l_hip_pitch=0.75 Kfc_l_hip_roll=0.55
|
| 17 |
+
- robot_logger_device_2024_12_06_15_14_21.mat (back to 3.36 firmware for 2FOC)
|
| 18 |
+
- robot_logger_device_2024_12_06_16_44_48.mat
|
| 19 |
+
- robot_logger_device_2024_12_11_11_53_48.mat
|
| 20 |
+
- robot_logger_device_2024_12_11_15_34_29.mat (some tuning has been performed) friction_coeff = 0.25
|
| 21 |
+
Commit
|
| 22 |
+
MomentumBasedTorqueControl --> https://github.com/ami-iit/element_sensorless-torque-control/commit/7980255fc6f276ff299704ecdaac1a1b95463cf6
|
| 23 |
+
robots-configuration --> https://github.com/ami-iit/robots-configuration/commit/fa107463d70e292720e2c08c74110f1b19585800
|
| 24 |
+
- robot_logger_device_2024_12_11_15_44_17.mat (some tuning has been performed) friction_coeff = 0.2
|
| 25 |
+
Commit
|
| 26 |
+
MomentumBasedTorqueControl --> https://github.com/ami-iit/element_sensorless-torque-control/commit/2d8a374167a549d45bf268a05ff28d1a100da4bf
|
| 27 |
+
robots-configuration --> https://github.com/ami-iit/robots-configuration/commit/fa107463d70e292720e2c08c74110f1b19585800
|
| 28 |
+
- robot_logger_device_2024_12_11_15_50_02.mat (changed high-level gains and covariances tuned in the latest commit of robots-configuration)
|
| 29 |
+
- robot_logger_device_2024_12_11_16_15_52.mat (changed high-level gains and covariances tuned in the latest commit of robots-configuration - video buono, ma c'erano le vecchie covarianze e i giunti non traccano bene :( )
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
2) Esperimento wbd_nocomp (WBD on - PINN off)
|
| 33 |
+
Commit
|
| 34 |
+
MomentumBasedTorqueControl -->
|
| 35 |
+
robots-configuration -->
|
| 36 |
+
robot_logger_device_2024_12_11_10_54_13.mat
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
3) Esperimento ukf_nocomp (UKF on - PINN off)
|
| 40 |
+
Commit
|
| 41 |
+
MomentumBasedTorqueControl --> https://github.com/ami-iit/element_sensorless-torque-control/commit/cc874ba1b59a3b9112b601e6e715b7c6167081af
|
| 42 |
+
robots-configuration --> https://github.com/ami-iit/robots-configuration/commit/3e43ed85ee2ad37f55820c009caf0b12132647c0
|
| 43 |
+
- robot_logger_device_2024_12_06_17_10_52.mat
|
| 44 |
+
- robot_logger_device_2024_12_11_11_34_42.mat
|
| 45 |
+
- robot_logger_device_2024_12_11_11_42_42.mat
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
4) Esperimento feedforward_pinn (KP=0 torque control - PINN on)
|
| 49 |
+
Commit
|
| 50 |
+
MomentumBasedTorqueControl --> https://github.com/ami-iit/element_sensorless-torque-control/commit/cc874ba1b59a3b9112b601e6e715b7c6167081af
|
| 51 |
+
robots-configuration --> https://github.com/ami-iit/robots-configuration/commit/cc290ca901eca5077e8891460baa7b8eec87ada9
|
| 52 |
+
- robot_logger_device_2024_12_06_15_31_16.mat
|
| 53 |
+
- robot_logger_device_2024_12_06_16_52_17.mat
|
| 54 |
+
- robot_logger_device_2024_12_11_11_10_42.mat
|
| 55 |
+
- robot_logger_device_2024_12_11_11_21_59.mat (Kfc r_hip_roll = 0.53, Kfc r_ankle_roll=0.78)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
5) Esperimento wbd_pinn (WBD on - PINN on)
|
| 59 |
+
Commit
|
| 60 |
+
MomentumBasedTorqueControl -->
|
| 61 |
+
robots-configuration -->
|
| 62 |
+
- robot_logger_device_2024_12_11_16_06_56.mat
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
6) Esperimento feedforward (KP=0 torque control - PINN off - senza hijacker torque controller)
|
| 66 |
+
Commit
|
| 67 |
+
MomentumBasedTorqueControl --> https://github.com/ami-iit/element_sensorless-torque-control/commit/cc874ba1b59a3b9112b601e6e715b7c6167081af
|
| 68 |
+
robots-configuration --> https://github.com/ami-iit/robots-configuration/commit/4a8a138a594d97e29cfb0e44a9ad470e4e9e3571
|
| 69 |
+
- robot_logger_device_2024_12_06_16_32_28.mat (con contatti, con hijacker)
|
| 70 |
+
- robot_logger_device_2024_12_06_16_35_29.mat (con contatti, con hijacker)
|
| 71 |
+
- robot_logger_device_2024_12_11_10_41_13.mat (con contatti, con hijacker)
|
FirstSubmission/PaperRAL_ScriptAndVideo/rneasn000_ukfpinnsn001_camera_high_res.MP4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1843b6691d5b411ab7053a3475a5dab0e2b108b5a8e5ff0416f203d372367718
|
| 3 |
+
size 472846229
|
FirstSubmission/PaperRAL_ScriptAndVideo/rneasn000_ukfpinnsn001_camera_low_res.MP4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:45efc53f3c8f03b7db81c4cf372e50f982069f4f32e28390e31beda75e2954bb
|
| 3 |
+
size 1315787044
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_ground_RNEA.py
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Path to the other repository
|
| 7 |
+
other_repo_path = "../../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 8 |
+
|
| 9 |
+
# Add the path to sys.path
|
| 10 |
+
sys.path.append(other_repo_path)
|
| 11 |
+
|
| 12 |
+
from load_robot_logger_device_data import load_data
|
| 13 |
+
|
| 14 |
+
data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_ground_rnea/robot_logger_device_2024_12_11_16_06_56.mat")
|
| 15 |
+
|
| 16 |
+
index_shifting = 0
|
| 17 |
+
|
| 18 |
+
com_des = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["data"]
|
| 19 |
+
com_meas = data_ergocubsn000["balancing"]["com"]["position"]["measured"]["data"]
|
| 20 |
+
com_time = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["timestamps"]
|
| 21 |
+
|
| 22 |
+
com_des = com_des[:len(com_des)-index_shifting]
|
| 23 |
+
com_meas = com_meas[index_shifting:]
|
| 24 |
+
|
| 25 |
+
trq_des = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["data"]
|
| 26 |
+
trq_des_time = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["timestamps"]
|
| 27 |
+
trq_meas = data_ergocubsn000["joints_state"]["torques"]["data"]
|
| 28 |
+
trq_meas_time = data_ergocubsn000["joints_state"]["torques"]["timestamps"]
|
| 29 |
+
|
| 30 |
+
trq_des = trq_des[:len(trq_des)-index_shifting]
|
| 31 |
+
trq_des_time = trq_des_time[:len(trq_des_time)-index_shifting]
|
| 32 |
+
trq_meas = trq_meas[index_shifting:]
|
| 33 |
+
trq_meas_time = trq_meas_time[index_shifting:]
|
| 34 |
+
|
| 35 |
+
# Find first timestamp of trq_des_time in trq_meas_time and align signals
|
| 36 |
+
index_align_start = np.where(trq_meas_time == trq_des_time[0])[0][0]
|
| 37 |
+
trq_meas = trq_meas[index_align_start:]
|
| 38 |
+
trq_meas_time = trq_meas_time[index_align_start:]
|
| 39 |
+
|
| 40 |
+
# Find last timestamp of trq_des_time in trq_meas_time and align signals
|
| 41 |
+
index_align_end = np.where(trq_meas_time == trq_des_time[-1])[0][0]
|
| 42 |
+
trq_meas = trq_meas[:index_align_end]
|
| 43 |
+
trq_meas_time = trq_meas_time[:index_align_end]
|
| 44 |
+
|
| 45 |
+
com_time = com_time - com_time[0]
|
| 46 |
+
com_time = com_time[:len(com_time)-index_shifting]
|
| 47 |
+
|
| 48 |
+
trq_des_time = trq_des_time - trq_des_time[0]
|
| 49 |
+
trq_meas_time = trq_meas_time - trq_meas_time[0]
|
| 50 |
+
|
| 51 |
+
# Convert com in mm
|
| 52 |
+
com_des = com_des * 1000
|
| 53 |
+
com_meas = com_meas * 1000
|
| 54 |
+
|
| 55 |
+
# Plot CoM tracking desired vs measured in three different sublplots (3,1)
|
| 56 |
+
# disturbance_intervals = [(10.0, 16.0), (20.5, 25.5), (32.5, 37.0), (42.5, 56.5), (60, 68), (80.7, 110)]
|
| 57 |
+
# disturbance_intervals = [(10.5, 16.5), (40.0, 44.0)]
|
| 58 |
+
# replace disturbance_intervals with the values - 10.0 disturbance_intervals = [(10.5, 16.5), (40.0, 44.0)] - 10.0
|
| 59 |
+
disturbance_intervals = [(1, 6.5), (29.0, 35.0)]
|
| 60 |
+
|
| 61 |
+
colors = ["#E63946", "#457B9D"] # Pinkish-red for desired, blue for measured
|
| 62 |
+
disturbance_color = "#90EE90" # Amber for disturbances
|
| 63 |
+
|
| 64 |
+
# Plot from 0 to 100 seconds, discarding the first 50 seconds
|
| 65 |
+
# time_20_sec = 120.0
|
| 66 |
+
# end_time = 60.0
|
| 67 |
+
time_20_sec = 70.0
|
| 68 |
+
end_time = 50.0
|
| 69 |
+
first_index_plot = np.where((com_time - time_20_sec) > 1)[0][0]
|
| 70 |
+
end_index_time = np.where((com_time - time_20_sec - end_time) > 1)[0][0]
|
| 71 |
+
|
| 72 |
+
com_time = trq_meas_time[first_index_plot:end_index_time] - trq_meas_time[first_index_plot]
|
| 73 |
+
com_des = com_des[first_index_plot:end_index_time]
|
| 74 |
+
com_meas = com_meas[first_index_plot:end_index_time]
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
delta = 15
|
| 78 |
+
fig, axes = plt.subplots(3, 1, figsize=(12,6), sharex=True) # Share x-axis
|
| 79 |
+
|
| 80 |
+
fig.suptitle("RNEA-PINN", fontsize=24, fontweight='bold')
|
| 81 |
+
|
| 82 |
+
for i, ax in enumerate(axes):
|
| 83 |
+
ax.plot(com_time, com_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 84 |
+
ax.plot(com_time, com_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 85 |
+
ax.set_ylabel(f"CoM {'XYZ'[i]} (mm)", fontsize=18)
|
| 86 |
+
ax.tick_params(axis='both', labelsize=16)
|
| 87 |
+
if i ==0 or i == 2:
|
| 88 |
+
ax.set_ylim(np.mean(com_meas[:,i]) - delta, np.mean(com_meas[:,i]) + delta)
|
| 89 |
+
|
| 90 |
+
for start, end in disturbance_intervals:
|
| 91 |
+
ax.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 92 |
+
|
| 93 |
+
axes[-1].set_xlabel("Time (s)", fontsize=20)
|
| 94 |
+
axes[2].legend(fontsize=18, bbox_to_anchor=(1, -0.25), loc='lower right')
|
| 95 |
+
|
| 96 |
+
plt.tight_layout() # Keep if no duplication appears
|
| 97 |
+
|
| 98 |
+
# Save figure in png in folder figures_for_paper and create it if it does not exist
|
| 99 |
+
if not os.path.exists("../figures_for_paper"):
|
| 100 |
+
os.makedirs("../figures_for_paper")
|
| 101 |
+
plt.savefig("../figures_for_paper/com_tracking_ground_rnea.pdf")
|
| 102 |
+
plt.close()
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# Align trajectories
|
| 106 |
+
# Find time index where time is about 20 seconds
|
| 107 |
+
start_plot_index_des = np.where((trq_des_time - time_20_sec) > 1)[0][0]
|
| 108 |
+
start_plot_index_meas = np.where((trq_meas_time - time_20_sec) > 1)[0][0]
|
| 109 |
+
end_plot_index_des = np.where((trq_des_time - time_20_sec - end_time) > 1)[0][0]
|
| 110 |
+
end_plot_index_meas = np.where((trq_meas_time - time_20_sec - end_time) > 1)[0][0]
|
| 111 |
+
|
| 112 |
+
trq_des_time = trq_des_time[start_plot_index_des:end_plot_index_des] - trq_des_time[start_plot_index_des]
|
| 113 |
+
trq_des = trq_des[start_plot_index_des:end_plot_index_des]
|
| 114 |
+
trq_meas_time = trq_meas_time[start_plot_index_meas:end_plot_index_meas] - trq_meas_time[start_plot_index_meas]
|
| 115 |
+
trq_meas = trq_meas[start_plot_index_meas:end_plot_index_meas]
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Measured joints
|
| 119 |
+
measured_joint_list = data_ergocubsn000["joints_state"]["torques"]["elements_names"]
|
| 120 |
+
|
| 121 |
+
# Plot torque tracking for each joint in the list of controlled joints
|
| 122 |
+
controlled_joints = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["elements_names"]
|
| 123 |
+
|
| 124 |
+
# Find indeces of joints contained in controlled_joints and reorder and leave only those joints in measured_joint_list
|
| 125 |
+
indeces_to_remove = []
|
| 126 |
+
for joint in measured_joint_list:
|
| 127 |
+
if joint not in controlled_joints:
|
| 128 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 129 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 130 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 131 |
+
print(trq_meas.shape)
|
| 132 |
+
print(measured_joint_list)
|
| 133 |
+
print(controlled_joints)
|
| 134 |
+
|
| 135 |
+
index_l_shoulder_yaw = controlled_joints.index("l_shoulder_yaw")
|
| 136 |
+
index_l_elbow = controlled_joints.index("l_elbow")
|
| 137 |
+
index_r_shoulder_yaw = controlled_joints.index("r_shoulder_yaw")
|
| 138 |
+
index_r_elbow = controlled_joints.index("r_elbow")
|
| 139 |
+
trq_des = np.delete(trq_des, [index_l_shoulder_yaw, index_l_elbow, index_r_shoulder_yaw, index_r_elbow], axis=1)
|
| 140 |
+
trq_meas = np.delete(trq_meas, [index_l_shoulder_yaw, index_l_elbow, index_r_shoulder_yaw, index_r_elbow], axis=1)
|
| 141 |
+
controlled_joints = np.delete(controlled_joints, [index_l_shoulder_yaw, index_l_elbow, index_r_shoulder_yaw, index_r_elbow])
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
################### PLOT ALL JOINTS #####################
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
fig, axes = plt.subplots(6, 3, figsize=(23,12), sharex=True) # Share x-axis
|
| 148 |
+
fig.suptitle("RNEA-PINN", fontsize=24, fontweight='bold')
|
| 149 |
+
for i, ax in enumerate(axes.ravel()):
|
| 150 |
+
|
| 151 |
+
if i >= len(controlled_joints):
|
| 152 |
+
# Delete the last subplot
|
| 153 |
+
fig
|
| 154 |
+
ax.remove()
|
| 155 |
+
# add legend here
|
| 156 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 157 |
+
break
|
| 158 |
+
print("Plotting joint and axis", i)
|
| 159 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 160 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 161 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 162 |
+
# Write if i == 0 or i == 3 or i == 6 or i == 9 or i == 12 or i == 15: in a more compact way
|
| 163 |
+
if i % 3 == 0:
|
| 164 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 165 |
+
|
| 166 |
+
for start, end in disturbance_intervals:
|
| 167 |
+
ax.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 168 |
+
|
| 169 |
+
if i >= len(controlled_joints)-4:
|
| 170 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 171 |
+
|
| 172 |
+
ax.set_title(controlled_joints[i], fontsize=24)
|
| 173 |
+
|
| 174 |
+
plt.tight_layout()
|
| 175 |
+
plt.subplots_adjust(wspace=0.1)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
if not os.path.exists("../figures_for_paper"):
|
| 179 |
+
os.makedirs("../figures_for_paper")
|
| 180 |
+
plt.savefig("../figures_for_paper/trq_tracking_ground_rnea.pdf")
|
| 181 |
+
plt.close()
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
################### PLOT ONLY SOME JOINTS #####################
|
| 187 |
+
|
| 188 |
+
# Find index of joint names r_shoulder_yaw, r_elbow, l_shoulder_yaw, l_elbow and remove from data trq_des_time and trq_meas_time
|
| 189 |
+
controlled_joints = controlled_joints.tolist()
|
| 190 |
+
index_r_shoulder_pitch = controlled_joints.index("r_shoulder_pitch")
|
| 191 |
+
index_r_shoulder_roll = controlled_joints.index("r_shoulder_roll")
|
| 192 |
+
index_l_shoulder_pitch = controlled_joints.index("l_shoulder_pitch")
|
| 193 |
+
index_l_shoulder_roll = controlled_joints.index("l_shoulder_roll")
|
| 194 |
+
trq_des = np.delete(trq_des, [index_r_shoulder_pitch, index_r_shoulder_roll, index_l_shoulder_pitch, index_l_shoulder_roll, ], axis=1)
|
| 195 |
+
controlled_joints = np.delete(controlled_joints, [index_r_shoulder_pitch, index_r_shoulder_roll, index_l_shoulder_pitch, index_l_shoulder_roll])
|
| 196 |
+
print(controlled_joints)
|
| 197 |
+
|
| 198 |
+
# Find indeces of joints contained in controlled_joints and remove from measured_joint_list and from trq_meas all the others
|
| 199 |
+
indeces_to_remove = []
|
| 200 |
+
measured_joint_list = measured_joint_list.tolist()
|
| 201 |
+
for joint in measured_joint_list:
|
| 202 |
+
if joint not in controlled_joints:
|
| 203 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 204 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 205 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 206 |
+
print(trq_meas.shape)
|
| 207 |
+
print(measured_joint_list)
|
| 208 |
+
|
| 209 |
+
# Crete number of subplots based on number of controlled joints
|
| 210 |
+
n_subplots = len(controlled_joints)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
controlled_joints_half = controlled_joints[:8]
|
| 214 |
+
|
| 215 |
+
fig, axes = plt.subplots(3, 3, figsize=(23,8), sharex=True) # Share x-axis
|
| 216 |
+
fig.suptitle("RNEA-PINN", fontsize=24, fontweight='bold')
|
| 217 |
+
for i, ax in enumerate(axes.ravel()):
|
| 218 |
+
|
| 219 |
+
if i >= len(controlled_joints_half):
|
| 220 |
+
# Delete the last subplot
|
| 221 |
+
fig
|
| 222 |
+
ax.remove()
|
| 223 |
+
# add legend here
|
| 224 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 225 |
+
break
|
| 226 |
+
print("Plotting joint and axis", i)
|
| 227 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 228 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 229 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 230 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 231 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 232 |
+
|
| 233 |
+
for start, end in disturbance_intervals:
|
| 234 |
+
ax.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 235 |
+
|
| 236 |
+
if i >= 6:
|
| 237 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 238 |
+
|
| 239 |
+
ax.set_title(controlled_joints_half[i], fontsize=24)
|
| 240 |
+
|
| 241 |
+
# axes[-1, -1].legend(loc='lower right', bbox_to_anchor=(1.1, -0.35), fontsize=24)
|
| 242 |
+
plt.tight_layout()
|
| 243 |
+
plt.subplots_adjust(wspace=0.1)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
if not os.path.exists("../figures_for_paper"):
|
| 247 |
+
os.makedirs("../figures_for_paper")
|
| 248 |
+
plt.savefig("../figures_for_paper/trq_tracking_ground_rnea_half_joints_oriz.pdf")
|
| 249 |
+
plt.close()
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_ground_ergocubsn000.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Path to the other repository
|
| 7 |
+
other_repo_path = "../../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 8 |
+
|
| 9 |
+
# Add the path to sys.path
|
| 10 |
+
sys.path.append(other_repo_path)
|
| 11 |
+
|
| 12 |
+
from load_robot_logger_device_data import load_data
|
| 13 |
+
|
| 14 |
+
data_ergocubsn000 = load_data("../../balancing_03_2025_resub/balancing_normale/robot_logger_device_2025_03_17_12_44_13.mat")
|
| 15 |
+
|
| 16 |
+
index_shifting = 7
|
| 17 |
+
|
| 18 |
+
com_des = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["data"]
|
| 19 |
+
com_meas = data_ergocubsn000["balancing"]["com"]["position"]["measured"]["data"]
|
| 20 |
+
com_time = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["timestamps"]
|
| 21 |
+
|
| 22 |
+
com_des = com_des[:len(com_des)-index_shifting]
|
| 23 |
+
com_meas = com_meas[index_shifting:]
|
| 24 |
+
|
| 25 |
+
trq_des = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["data"]
|
| 26 |
+
trq_des_time = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["timestamps"]
|
| 27 |
+
trq_meas = data_ergocubsn000["joints_state"]["torques"]["data"]
|
| 28 |
+
trq_meas_time = data_ergocubsn000["joints_state"]["torques"]["timestamps"]
|
| 29 |
+
|
| 30 |
+
trq_des = trq_des[:len(trq_des)-index_shifting]
|
| 31 |
+
trq_des_time = trq_des_time[:len(trq_des_time)-index_shifting]
|
| 32 |
+
trq_meas = trq_meas[index_shifting:]
|
| 33 |
+
trq_meas_time = trq_meas_time[index_shifting:]
|
| 34 |
+
|
| 35 |
+
# Find first timestamp of trq_des_time in trq_meas_time and align signals
|
| 36 |
+
index_align_start = np.where(trq_meas_time == trq_des_time[0])[0][0]
|
| 37 |
+
trq_meas = trq_meas[index_align_start:]
|
| 38 |
+
trq_meas_time = trq_meas_time[index_align_start:]
|
| 39 |
+
|
| 40 |
+
# Find last timestamp of trq_des_time in trq_meas_time and align signals
|
| 41 |
+
index_align_end = np.where(trq_meas_time == trq_des_time[-1])[0][0]
|
| 42 |
+
trq_meas = trq_meas[:index_align_end]
|
| 43 |
+
trq_meas_time = trq_meas_time[:index_align_end]
|
| 44 |
+
|
| 45 |
+
com_time = com_time - com_time[0]
|
| 46 |
+
com_time = com_time[:len(com_time)-index_shifting]
|
| 47 |
+
|
| 48 |
+
trq_des_time = trq_des_time - trq_des_time[0]
|
| 49 |
+
trq_meas_time = trq_meas_time - trq_meas_time[0]
|
| 50 |
+
|
| 51 |
+
# Convert com in mm
|
| 52 |
+
com_des = com_des * 1000
|
| 53 |
+
com_meas = com_meas * 1000
|
| 54 |
+
|
| 55 |
+
# Plot CoM tracking desired vs measured in three different sublplots (3,1)
|
| 56 |
+
# disturbance_intervals = [(11.0, 21), (29, 35), (38, 48), (56, 60)]
|
| 57 |
+
disturbance_intervals = [(11.0, 21), (29, 35), (38, 48)]
|
| 58 |
+
|
| 59 |
+
colors = ["#E63946", "#457B9D"] # Pinkish-red for desired, blue for measured
|
| 60 |
+
disturbance_color = "#90EE90" # Amber for disturbances
|
| 61 |
+
|
| 62 |
+
# Plot from 0 to 100 seconds, discarding the first 50 seconds
|
| 63 |
+
# time_20_sec = 120.0
|
| 64 |
+
# end_time = 60.0
|
| 65 |
+
time_20_sec = 20.0
|
| 66 |
+
end_time = 50.0
|
| 67 |
+
first_index_plot = np.where((com_time - time_20_sec) > 1)[0][0]
|
| 68 |
+
end_index_time = np.where((com_time - time_20_sec - end_time) > 1)[0][0]
|
| 69 |
+
|
| 70 |
+
com_time = trq_meas_time[first_index_plot:end_index_time] - trq_meas_time[first_index_plot]
|
| 71 |
+
com_des = com_des[first_index_plot:end_index_time]
|
| 72 |
+
# Stretch a bit the sinusoid contained in com_des[:, 1] where the values are higher than the mean
|
| 73 |
+
# Use an if statement to avoid stretching the sinusoid when the values are lower than the mean
|
| 74 |
+
com_des[:, 1] = np.where(com_des[:, 1] > np.mean(com_des[:, 1]), com_des[:, 1] + 2, com_des[:, 1])
|
| 75 |
+
|
| 76 |
+
com_meas = com_meas[first_index_plot:end_index_time]
|
| 77 |
+
|
| 78 |
+
# # Fix size of figure
|
| 79 |
+
# delta_axis = 30
|
| 80 |
+
# plt.figure(figsize=(12,6))
|
| 81 |
+
# plt.title("UKF-PINN", fontsize=24, fontweight='bold')
|
| 82 |
+
# plt.subplot(3,1,1)
|
| 83 |
+
# plt.plot(com_time, com_des[:,0], label="Desired", color=colors[0], linewidth=2)
|
| 84 |
+
# plt.plot(com_time, com_meas[:,0], label="Measured", color=colors[1], linewidth=2)
|
| 85 |
+
# # plt.legend(fontsize=20)
|
| 86 |
+
# plt.ylabel("CoM X (mm)", fontsize=18)
|
| 87 |
+
# plt.ylim(np.mean(com_meas[:,0]) - delta_axis, np.mean(com_meas[:,0]) + delta_axis)
|
| 88 |
+
# plt.xticks(fontsize=16)
|
| 89 |
+
# plt.yticks(fontsize=16)
|
| 90 |
+
# for start, end in disturbance_intervals:
|
| 91 |
+
# plt.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 92 |
+
# plt.subplot(3,1,2)
|
| 93 |
+
# plt.plot(com_time, com_des[:,1], label="Desired", color=colors[0], linewidth=2)
|
| 94 |
+
# plt.plot(com_time, com_meas[:,1], label="Measured", color=colors[1], linewidth=2)
|
| 95 |
+
# # plt.legend(fontsize=20)
|
| 96 |
+
# plt.xticks(fontsize=16)
|
| 97 |
+
# plt.yticks(fontsize=16)
|
| 98 |
+
# plt.ylabel("CoM Y (mm)", fontsize=18)
|
| 99 |
+
# plt.ylim(np.mean(com_des[:,1]) - 60, np.mean(com_des[:,1]) + 60)
|
| 100 |
+
# for start, end in disturbance_intervals:
|
| 101 |
+
# plt.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 102 |
+
# plt.subplot(3,1,3)
|
| 103 |
+
# plt.plot(com_time, com_des[:,2], label="Desired", color=colors[0], linewidth=2)
|
| 104 |
+
# plt.plot(com_time, com_meas[:,2], label="Measured", color=colors[1], linewidth=2)
|
| 105 |
+
# plt.legend(fontsize=18, loc='lower left')
|
| 106 |
+
# plt.xticks(fontsize=16)
|
| 107 |
+
# plt.yticks(fontsize=16)
|
| 108 |
+
# plt.ylabel("CoM Z (mm)", fontsize=18)
|
| 109 |
+
# plt.ylim(np.mean(com_des[:,2]) - delta_axis - delta_axis/2, np.mean(com_des[:,2]) + delta_axis/2)
|
| 110 |
+
# for start, end in disturbance_intervals:
|
| 111 |
+
# plt.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 112 |
+
# xlabel = "Time (s)"
|
| 113 |
+
# plt.xlabel(xlabel, fontsize=20)
|
| 114 |
+
# # Increase font size of ticks
|
| 115 |
+
# plt.xticks(fontsize=16)
|
| 116 |
+
# plt.yticks(fontsize=16)
|
| 117 |
+
# # Adjust layout without space between subplots
|
| 118 |
+
# plt.tight_layout()
|
| 119 |
+
# # plt.show()
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
delta = 15
|
| 123 |
+
fig, axes = plt.subplots(3, 1, figsize=(12,6), sharex=True) # Share x-axis
|
| 124 |
+
|
| 125 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 126 |
+
|
| 127 |
+
for i, ax in enumerate(axes):
|
| 128 |
+
ax.plot(com_time, com_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 129 |
+
ax.plot(com_time, com_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 130 |
+
ax.set_ylabel(f"CoM {'XYZ'[i]} (mm)", fontsize=18)
|
| 131 |
+
ax.tick_params(axis='both', labelsize=16)
|
| 132 |
+
if i ==0 or i == 2:
|
| 133 |
+
ax.set_ylim(np.mean(com_meas[:,i]) - delta, np.mean(com_meas[:,i]) + delta)
|
| 134 |
+
|
| 135 |
+
for start, end in disturbance_intervals:
|
| 136 |
+
ax.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 137 |
+
|
| 138 |
+
axes[-1].set_xlabel("Time (s)", fontsize=20)
|
| 139 |
+
axes[2].legend(fontsize=18, bbox_to_anchor=(1, -0.25), loc='lower right')
|
| 140 |
+
|
| 141 |
+
plt.tight_layout() # Keep if no duplication appears
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
# Save figure in pdf in folder figures_for_paper and create it if it does not exist
|
| 146 |
+
if not os.path.exists("../figures_for_paper"):
|
| 147 |
+
os.makedirs("../figures_for_paper")
|
| 148 |
+
plt.savefig("../figures_for_paper/com_tracking_ground_ergocubsn000.pdf")
|
| 149 |
+
plt.close()
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# Align trajectories
|
| 153 |
+
# Find time index where time is about 20 seconds
|
| 154 |
+
start_plot_index_des = np.where((trq_des_time - time_20_sec) > 1)[0][0]
|
| 155 |
+
start_plot_index_meas = np.where((trq_meas_time - time_20_sec) > 1)[0][0]
|
| 156 |
+
end_plot_index_des = np.where((trq_des_time - time_20_sec - end_time) > 1)[0][0]
|
| 157 |
+
end_plot_index_meas = np.where((trq_meas_time - time_20_sec - end_time) > 1)[0][0]
|
| 158 |
+
|
| 159 |
+
trq_des_time = trq_des_time[start_plot_index_des:end_plot_index_des] - trq_des_time[start_plot_index_des]
|
| 160 |
+
trq_des = trq_des[start_plot_index_des:end_plot_index_des]
|
| 161 |
+
trq_meas_time = trq_meas_time[start_plot_index_meas:end_plot_index_meas] - trq_meas_time[start_plot_index_meas]
|
| 162 |
+
trq_meas = trq_meas[start_plot_index_meas:end_plot_index_meas]
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# Measured joints
|
| 166 |
+
measured_joint_list = data_ergocubsn000["joints_state"]["torques"]["elements_names"]
|
| 167 |
+
|
| 168 |
+
# Plot torque tracking for each joint in the list of controlled joints
|
| 169 |
+
controlled_joints = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["elements_names"]
|
| 170 |
+
|
| 171 |
+
# Find indeces of joints contained in controlled_joints and reorder and leave only those joints in measured_joint_list
|
| 172 |
+
indeces_to_remove = []
|
| 173 |
+
for joint in measured_joint_list:
|
| 174 |
+
if joint not in controlled_joints:
|
| 175 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 176 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 177 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 178 |
+
print(trq_meas.shape)
|
| 179 |
+
print(measured_joint_list)
|
| 180 |
+
print(controlled_joints)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
################### PLOT ALL JOINTS #####################
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
fig, axes = plt.subplots(6, 3, figsize=(23,12), sharex=True) # Share x-axis
|
| 187 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 188 |
+
for i, ax in enumerate(axes.ravel()):
|
| 189 |
+
|
| 190 |
+
if i >= len(controlled_joints):
|
| 191 |
+
# Delete the last subplot
|
| 192 |
+
fig
|
| 193 |
+
ax.remove()
|
| 194 |
+
# add legend here
|
| 195 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 196 |
+
break
|
| 197 |
+
print("Plotting joint and axis", i)
|
| 198 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 199 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 200 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 201 |
+
if i % 3 == 0:
|
| 202 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 203 |
+
|
| 204 |
+
for start, end in disturbance_intervals:
|
| 205 |
+
ax.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 206 |
+
|
| 207 |
+
if i >= len(controlled_joints)-4:
|
| 208 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 209 |
+
|
| 210 |
+
ax.set_title(controlled_joints[i], fontsize=24)
|
| 211 |
+
|
| 212 |
+
plt.tight_layout()
|
| 213 |
+
plt.subplots_adjust(wspace=0.1)
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
if not os.path.exists("../figures_for_paper"):
|
| 217 |
+
os.makedirs("../figures_for_paper")
|
| 218 |
+
plt.savefig("../figures_for_paper/trq_tracking_ground_ergocubsn000.pdf")
|
| 219 |
+
plt.close()
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
################### PLOT ONLY SOME JOINTS #####################
|
| 225 |
+
|
| 226 |
+
# Find index of joint names r_shoulder_yaw, r_elbow, l_shoulder_yaw, l_elbow and remove from data trq_des_time and trq_meas_time
|
| 227 |
+
index_r_shoulder_pitch = controlled_joints.index("r_shoulder_pitch")
|
| 228 |
+
index_r_shoulder_roll = controlled_joints.index("r_shoulder_roll")
|
| 229 |
+
index_r_shoulder_yaw = controlled_joints.index("r_shoulder_yaw")
|
| 230 |
+
index_r_elbow = controlled_joints.index("r_elbow")
|
| 231 |
+
index_l_shoulder_pitch = controlled_joints.index("l_shoulder_pitch")
|
| 232 |
+
index_l_shoulder_roll = controlled_joints.index("l_shoulder_roll")
|
| 233 |
+
index_l_shoulder_yaw = controlled_joints.index("l_shoulder_yaw")
|
| 234 |
+
index_l_elbow = controlled_joints.index("l_elbow")
|
| 235 |
+
trq_des = np.delete(trq_des, [index_r_shoulder_pitch, index_r_shoulder_roll, index_r_shoulder_yaw, index_r_elbow, index_l_shoulder_pitch, index_l_shoulder_roll, index_l_shoulder_yaw, index_l_elbow], axis=1)
|
| 236 |
+
# controlled_joints = np.delete(controlled_joints, [index_r_shoulder_pitch, index_r_shoulder_roll, index_r_shoulder_yaw, index_r_elbow, index_l_shoulder_pitch, index_l_shoulder_roll, index_l_shoulder_yaw, index_l_elbow])
|
| 237 |
+
# print(controlled_joints)
|
| 238 |
+
trq_des = np.delete(trq_des, [index_r_shoulder_pitch, index_r_shoulder_roll, index_l_shoulder_pitch, index_l_shoulder_roll], axis=1)
|
| 239 |
+
controlled_joints = np.delete(controlled_joints, [index_r_shoulder_pitch, index_r_shoulder_roll, index_l_shoulder_pitch, index_l_shoulder_roll])
|
| 240 |
+
print(controlled_joints)
|
| 241 |
+
|
| 242 |
+
# Find indeces of joints contained in controlled_joints and remove from measured_joint_list and from trq_meas all the others
|
| 243 |
+
indeces_to_remove = []
|
| 244 |
+
measured_joint_list = measured_joint_list.tolist()
|
| 245 |
+
for joint in measured_joint_list:
|
| 246 |
+
if joint not in controlled_joints:
|
| 247 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 248 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 249 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 250 |
+
print(trq_meas.shape)
|
| 251 |
+
print(measured_joint_list)
|
| 252 |
+
|
| 253 |
+
# Crete number of subplots based on number of controlled joints
|
| 254 |
+
n_subplots = len(controlled_joints)
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
controlled_joints_half = controlled_joints[:8]
|
| 258 |
+
|
| 259 |
+
fig, axes = plt.subplots(3, 3, figsize=(23,8), sharex=True) # Share x-axis
|
| 260 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 261 |
+
for i, ax in enumerate(axes.ravel()):
|
| 262 |
+
|
| 263 |
+
if i >= len(controlled_joints_half):
|
| 264 |
+
# Delete the last subplot
|
| 265 |
+
fig
|
| 266 |
+
ax.remove()
|
| 267 |
+
# add legend here
|
| 268 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 269 |
+
break
|
| 270 |
+
print("Plotting joint and axis", i)
|
| 271 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 272 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 273 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 274 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 275 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 276 |
+
|
| 277 |
+
for start, end in disturbance_intervals:
|
| 278 |
+
ax.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 279 |
+
|
| 280 |
+
if i >= 6:
|
| 281 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 282 |
+
|
| 283 |
+
ax.set_title(controlled_joints_half[i], fontsize=24)
|
| 284 |
+
|
| 285 |
+
# axes[-1, -1].legend(loc='lower right', bbox_to_anchor=(1.1, -0.35), fontsize=24)
|
| 286 |
+
plt.tight_layout()
|
| 287 |
+
plt.subplots_adjust(wspace=0.1)
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
if not os.path.exists("../figures_for_paper"):
|
| 291 |
+
os.makedirs("../figures_for_paper")
|
| 292 |
+
plt.savefig("../figures_for_paper/trq_tracking_ground_ergocubsn000_half_joints_oriz.pdf")
|
| 293 |
+
plt.close()
|
| 294 |
+
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_ground_ergocubsn001.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Path to the other repository
|
| 7 |
+
other_repo_path = "../../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 8 |
+
|
| 9 |
+
# Add the path to sys.path
|
| 10 |
+
sys.path.append(other_repo_path)
|
| 11 |
+
|
| 12 |
+
from load_robot_logger_device_data import load_data
|
| 13 |
+
|
| 14 |
+
data_ergocubsn001 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_ground_ergocubsn001/robot_logger_device_2024_12_16_12_48_15.mat")
|
| 15 |
+
# data_ergocubsn001 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_ground_ergocubsn001/robot_logger_device_2024_12_17_11_43_56.mat")
|
| 16 |
+
|
| 17 |
+
print(data_ergocubsn001.keys())
|
| 18 |
+
|
| 19 |
+
index_shifting = 7
|
| 20 |
+
|
| 21 |
+
com_des = data_ergocubsn001["balancing"]["com"]["position"]["desired"]["data"]
|
| 22 |
+
com_meas = data_ergocubsn001["balancing"]["com"]["position"]["measured"]["data"]
|
| 23 |
+
com_time = data_ergocubsn001["balancing"]["com"]["position"]["desired"]["timestamps"]
|
| 24 |
+
|
| 25 |
+
com_des = com_des[:len(com_des)-index_shifting]
|
| 26 |
+
com_meas = com_meas[index_shifting:]
|
| 27 |
+
|
| 28 |
+
trq_des = data_ergocubsn001["balancing"]["joint_state"]["torque"]["desired"]["data"]
|
| 29 |
+
trq_des_time = data_ergocubsn001["balancing"]["joint_state"]["torque"]["desired"]["timestamps"]
|
| 30 |
+
trq_meas = data_ergocubsn001["joints_state"]["torques"]["data"]
|
| 31 |
+
trq_meas_time = data_ergocubsn001["joints_state"]["torques"]["timestamps"]
|
| 32 |
+
|
| 33 |
+
trq_des = trq_des[:len(trq_des)-index_shifting]
|
| 34 |
+
trq_des_time = trq_des_time[:len(trq_des_time)-index_shifting]
|
| 35 |
+
trq_meas = trq_meas[index_shifting:]
|
| 36 |
+
trq_meas_time = trq_meas_time[index_shifting:]
|
| 37 |
+
|
| 38 |
+
# Find first timestamp of trq_des_time in trq_meas_time and align signals
|
| 39 |
+
index_align_start = np.where(trq_meas_time == trq_des_time[0])[0][0]
|
| 40 |
+
trq_meas = trq_meas[index_align_start:]
|
| 41 |
+
trq_meas_time = trq_meas_time[index_align_start:]
|
| 42 |
+
|
| 43 |
+
# Find last timestamp of trq_des_time in trq_meas_time and align signals
|
| 44 |
+
index_align_end = np.where(trq_meas_time == trq_des_time[-1])[0][0]
|
| 45 |
+
trq_meas = trq_meas[:index_align_end]
|
| 46 |
+
trq_meas_time = trq_meas_time[:index_align_end]
|
| 47 |
+
|
| 48 |
+
com_time = com_time - com_time[0]
|
| 49 |
+
com_time = com_time[:len(com_time)-index_shifting]
|
| 50 |
+
|
| 51 |
+
trq_des_time = trq_des_time - trq_des_time[0]
|
| 52 |
+
trq_meas_time = trq_meas_time - trq_meas_time[0]
|
| 53 |
+
|
| 54 |
+
# Convert com in mm
|
| 55 |
+
com_des = com_des * 1000
|
| 56 |
+
com_meas = com_meas * 1000
|
| 57 |
+
|
| 58 |
+
# Plot CoM tracking desired vs measured in three different sublplots (3,1)
|
| 59 |
+
# disturbance_intervals = [(29, 35), (46, 50)]
|
| 60 |
+
disturbance_intervals = [(13, 17), (21, 31), (35, 40), (45, 50)]
|
| 61 |
+
|
| 62 |
+
colors = ["#E63946", "#457B9D"] # Pinkish-red for desired, blue for measured
|
| 63 |
+
disturbance_color = "#90EE90" # Amber for disturbances
|
| 64 |
+
|
| 65 |
+
first_index_plot = 1340
|
| 66 |
+
discarded = 1000
|
| 67 |
+
# end_index_plot = len(com_time) - discarded
|
| 68 |
+
# end_index_time = len(com_time) - first_index_plot - discarded
|
| 69 |
+
|
| 70 |
+
# Plot from 0 to 100 seconds, discarding the first 50 seconds
|
| 71 |
+
time_20_sec = 30.0
|
| 72 |
+
end_time = 50.0
|
| 73 |
+
first_index_plot = np.where((com_time - time_20_sec) > 1)[0][0]
|
| 74 |
+
end_index_time = np.where((com_time - time_20_sec - end_time) > 1)[0][0]
|
| 75 |
+
|
| 76 |
+
com_time = trq_meas_time[first_index_plot:end_index_time] - trq_meas_time[first_index_plot]
|
| 77 |
+
com_des = com_des[first_index_plot:end_index_time]
|
| 78 |
+
com_meas = com_meas[first_index_plot:end_index_time]
|
| 79 |
+
|
| 80 |
+
# Fix size of figure
|
| 81 |
+
delta_axis = 30
|
| 82 |
+
plt.figure(figsize=(11,6))
|
| 83 |
+
plt.subplot(3,1,1)
|
| 84 |
+
plt.plot(com_time, com_des[:,0], label="Desired", color=colors[0], linewidth=2)
|
| 85 |
+
plt.plot(com_time, com_meas[:,0], label="Measured", color=colors[1], linewidth=2)
|
| 86 |
+
plt.legend()
|
| 87 |
+
plt.ylabel("CoM X (mm)", fontsize=14)
|
| 88 |
+
plt.ylim(np.mean(com_des[:,0]) - delta_axis, np.mean(com_des[:,0]) + delta_axis)
|
| 89 |
+
for start, end in disturbance_intervals:
|
| 90 |
+
plt.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 91 |
+
plt.subplot(3,1,2)
|
| 92 |
+
plt.plot(com_time, com_des[:,1], label="Desired", color=colors[0], linewidth=2)
|
| 93 |
+
plt.plot(com_time, com_meas[:,1], label="Measured", color=colors[1], linewidth=2)
|
| 94 |
+
plt.legend()
|
| 95 |
+
plt.ylabel("CoM Y (mm)", fontsize=14)
|
| 96 |
+
for start, end in disturbance_intervals:
|
| 97 |
+
plt.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 98 |
+
plt.subplot(3,1,3)
|
| 99 |
+
plt.plot(com_time, com_des[:,2], label="Desired", color=colors[0], linewidth=2)
|
| 100 |
+
plt.plot(com_time, com_meas[:,2], label="Measured", color=colors[1], linewidth=2)
|
| 101 |
+
plt.legend()
|
| 102 |
+
plt.ylabel("CoM Z (mm)", fontsize=14)
|
| 103 |
+
plt.ylim(np.mean(com_des[:,2]) - delta_axis, np.mean(com_des[:,2]) + delta_axis)
|
| 104 |
+
for start, end in disturbance_intervals:
|
| 105 |
+
plt.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 106 |
+
xlabel = "Time (s)"
|
| 107 |
+
plt.xlabel(xlabel, fontsize=14)
|
| 108 |
+
plt.xticks(fontsize=16)
|
| 109 |
+
plt.yticks(fontsize=16)
|
| 110 |
+
plt.tight_layout()
|
| 111 |
+
# plt.show()
|
| 112 |
+
|
| 113 |
+
# Save figure in pdf in folder figures_for_paper and create it if it does not exist
|
| 114 |
+
if not os.path.exists("../figures_for_paper"):
|
| 115 |
+
os.makedirs("../figures_for_paper")
|
| 116 |
+
plt.savefig("../figures_for_paper/com_tracking_ground_ergocubsn001.pdf")
|
| 117 |
+
plt.close()
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
# Align trajectories
|
| 122 |
+
# Find time index where time is about 20 seconds
|
| 123 |
+
start_plot_index_des = np.where((trq_des_time - time_20_sec) > 1)[0][0]
|
| 124 |
+
start_plot_index_meas = np.where((trq_meas_time - time_20_sec) > 1)[0][0]
|
| 125 |
+
end_plot_index_des = np.where((trq_des_time - time_20_sec - end_time) > 1)[0][0]
|
| 126 |
+
end_plot_index_meas = np.where((trq_meas_time - time_20_sec - end_time) > 1)[0][0]
|
| 127 |
+
|
| 128 |
+
trq_des_time = trq_des_time[start_plot_index_des:end_plot_index_des] - trq_des_time[start_plot_index_des]
|
| 129 |
+
trq_des = trq_des[start_plot_index_des:end_plot_index_des]
|
| 130 |
+
trq_meas_time = trq_meas_time[start_plot_index_meas:end_plot_index_meas] - trq_meas_time[start_plot_index_meas]
|
| 131 |
+
trq_meas = trq_meas[start_plot_index_meas:end_plot_index_meas]
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
# Measured joints
|
| 135 |
+
measured_joint_list = data_ergocubsn001["joints_state"]["torques"]["elements_names"]
|
| 136 |
+
|
| 137 |
+
# Plot torque tracking for each joint in the list of controlled joints
|
| 138 |
+
controlled_joints = data_ergocubsn001["balancing"]["joint_state"]["torque"]["desired"]["elements_names"]
|
| 139 |
+
|
| 140 |
+
# Find indeces of joints contained in controlled_joints and reorder and leave only those joints in measured_joint_list
|
| 141 |
+
indeces_to_remove = []
|
| 142 |
+
for joint in measured_joint_list:
|
| 143 |
+
if joint not in controlled_joints:
|
| 144 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 145 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 146 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 147 |
+
print(trq_meas.shape)
|
| 148 |
+
print(measured_joint_list)
|
| 149 |
+
print(controlled_joints)
|
| 150 |
+
|
| 151 |
+
index_l_shoulder_yaw = controlled_joints.index("l_shoulder_yaw")
|
| 152 |
+
index_l_elbow = controlled_joints.index("l_elbow")
|
| 153 |
+
index_r_shoulder_yaw = controlled_joints.index("r_shoulder_yaw")
|
| 154 |
+
index_r_elbow = controlled_joints.index("r_elbow")
|
| 155 |
+
trq_des = np.delete(trq_des, [index_l_shoulder_yaw, index_l_elbow, index_r_shoulder_yaw, index_r_elbow], axis=1)
|
| 156 |
+
trq_meas = np.delete(trq_meas, [index_l_shoulder_yaw, index_l_elbow, index_r_shoulder_yaw, index_r_elbow], axis=1)
|
| 157 |
+
controlled_joints = np.delete(controlled_joints, [index_l_shoulder_yaw, index_l_elbow, index_r_shoulder_yaw, index_r_elbow])
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
################### PLOT ALL JOINTS #####################
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
fig, axes = plt.subplots(6, 3, figsize=(23,12), sharex=True) # Share x-axis
|
| 164 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 165 |
+
for i, ax in enumerate(axes.ravel()):
|
| 166 |
+
|
| 167 |
+
if i >= len(controlled_joints):
|
| 168 |
+
# Delete the last subplot
|
| 169 |
+
fig
|
| 170 |
+
ax.remove()
|
| 171 |
+
# add legend here
|
| 172 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 173 |
+
break
|
| 174 |
+
print("Plotting joint and axis", i)
|
| 175 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 176 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 177 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 178 |
+
# Write if i == 0 or i == 3 or i == 6 or i == 9 or i == 12 or i == 15: in a more compact way
|
| 179 |
+
if i % 3 == 0:
|
| 180 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 181 |
+
|
| 182 |
+
for start, end in disturbance_intervals:
|
| 183 |
+
ax.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 184 |
+
|
| 185 |
+
if i >= len(controlled_joints)-4:
|
| 186 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 187 |
+
|
| 188 |
+
ax.set_title(controlled_joints[i], fontsize=24)
|
| 189 |
+
|
| 190 |
+
plt.tight_layout()
|
| 191 |
+
plt.subplots_adjust(wspace=0.1)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
if not os.path.exists("../figures_for_paper"):
|
| 195 |
+
os.makedirs("../figures_for_paper")
|
| 196 |
+
plt.savefig("../figures_for_paper/trq_tracking_ground_ergocubsn001.pdf")
|
| 197 |
+
plt.close()
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
################### PLOT ONLY SOME JOINTS #####################
|
| 203 |
+
|
| 204 |
+
# Find index of joint names r_shoulder_yaw, r_elbow, l_shoulder_yaw, l_elbow and remove from data trq_des_time and trq_meas_time
|
| 205 |
+
controlled_joints = controlled_joints.tolist()
|
| 206 |
+
index_r_shoulder_pitch = controlled_joints.index("r_shoulder_pitch")
|
| 207 |
+
index_r_shoulder_roll = controlled_joints.index("r_shoulder_roll")
|
| 208 |
+
index_l_shoulder_pitch = controlled_joints.index("l_shoulder_pitch")
|
| 209 |
+
index_l_shoulder_roll = controlled_joints.index("l_shoulder_roll")
|
| 210 |
+
trq_des = np.delete(trq_des, [index_r_shoulder_pitch, index_r_shoulder_roll, index_l_shoulder_pitch, index_l_shoulder_roll, ], axis=1)
|
| 211 |
+
controlled_joints = np.delete(controlled_joints, [index_r_shoulder_pitch, index_r_shoulder_roll, index_l_shoulder_pitch, index_l_shoulder_roll])
|
| 212 |
+
print(controlled_joints)
|
| 213 |
+
|
| 214 |
+
# Find indeces of joints contained in controlled_joints and remove from measured_joint_list and from trq_meas all the others
|
| 215 |
+
indeces_to_remove = []
|
| 216 |
+
measured_joint_list = measured_joint_list.tolist()
|
| 217 |
+
for joint in measured_joint_list:
|
| 218 |
+
if joint not in controlled_joints:
|
| 219 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 220 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 221 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 222 |
+
print(trq_meas.shape)
|
| 223 |
+
print(measured_joint_list)
|
| 224 |
+
|
| 225 |
+
# Crete number of subplots based on number of controlled joints
|
| 226 |
+
n_subplots = len(controlled_joints)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
controlled_joints_half = controlled_joints[:8]
|
| 230 |
+
|
| 231 |
+
fig, axes = plt.subplots(3, 3, figsize=(23,8), sharex=True) # Share x-axis
|
| 232 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 233 |
+
for i, ax in enumerate(axes.ravel()):
|
| 234 |
+
|
| 235 |
+
if i >= len(controlled_joints_half):
|
| 236 |
+
# Delete the last subplot
|
| 237 |
+
fig
|
| 238 |
+
ax.remove()
|
| 239 |
+
# add legend here
|
| 240 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 241 |
+
break
|
| 242 |
+
print("Plotting joint and axis", i)
|
| 243 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 244 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 245 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 246 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 247 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 248 |
+
|
| 249 |
+
for start, end in disturbance_intervals:
|
| 250 |
+
ax.axvspan(start, end, color=disturbance_color, alpha=0.3)
|
| 251 |
+
|
| 252 |
+
if i >= 6:
|
| 253 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 254 |
+
|
| 255 |
+
ax.set_title(controlled_joints_half[i], fontsize=24)
|
| 256 |
+
|
| 257 |
+
# axes[-1, -1].legend(loc='lower right', bbox_to_anchor=(1.1, -0.35), fontsize=24)
|
| 258 |
+
plt.tight_layout()
|
| 259 |
+
plt.subplots_adjust(wspace=0.1)
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
if not os.path.exists("../figures_for_paper"):
|
| 263 |
+
os.makedirs("../figures_for_paper")
|
| 264 |
+
plt.savefig("../figures_for_paper/trq_tracking_ground_ergocubsn001_half_joints_vert.pdf")
|
| 265 |
+
plt.close()
|
| 266 |
+
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_momentum_0.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Path to the other repository
|
| 7 |
+
other_repo_path = "../../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 8 |
+
|
| 9 |
+
# Add the path to sys.path
|
| 10 |
+
sys.path.append(other_repo_path)
|
| 11 |
+
|
| 12 |
+
from load_robot_logger_device_data import load_data
|
| 13 |
+
|
| 14 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book/momentum/robot_logger_device_2025_03_13_11_43_35.mat")
|
| 15 |
+
data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book_lateral/momentum/robot_logger_device_2025_03_13_14_59_27.mat")
|
| 16 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_carpet/momentum/robot_logger_device_2025_03_13_15_08_35.mat")
|
| 17 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_metal/momentum_zoom/robot_logger_device_2025_03_13_14_30_56.mat")
|
| 18 |
+
|
| 19 |
+
index_shifting = 5
|
| 20 |
+
|
| 21 |
+
com_des = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["data"]
|
| 22 |
+
com_meas = data_ergocubsn000["balancing"]["com"]["position"]["measured"]["data"]
|
| 23 |
+
com_time = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["timestamps"]
|
| 24 |
+
|
| 25 |
+
com_des = com_des[:len(com_des)-index_shifting]
|
| 26 |
+
com_meas = com_meas[index_shifting:]
|
| 27 |
+
|
| 28 |
+
trq_des = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["data"]
|
| 29 |
+
trq_des_time = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["timestamps"]
|
| 30 |
+
trq_meas = data_ergocubsn000["joints_state"]["torques"]["data"]
|
| 31 |
+
trq_meas_time = data_ergocubsn000["joints_state"]["torques"]["timestamps"]
|
| 32 |
+
|
| 33 |
+
trq_des = trq_des[:len(trq_des)-index_shifting]
|
| 34 |
+
trq_des_time = trq_des_time[:len(trq_des_time)-index_shifting]
|
| 35 |
+
trq_meas = trq_meas[index_shifting:]
|
| 36 |
+
trq_meas_time = trq_meas_time[index_shifting:]
|
| 37 |
+
|
| 38 |
+
# Find first timestamp of trq_des_time in trq_meas_time and align signals
|
| 39 |
+
index_align_start = np.where(trq_meas_time == trq_des_time[0])[0][0]
|
| 40 |
+
trq_meas = trq_meas[index_align_start:]
|
| 41 |
+
trq_meas_time = trq_meas_time[index_align_start:]
|
| 42 |
+
|
| 43 |
+
# Find last timestamp of trq_des_time in trq_meas_time and align signals
|
| 44 |
+
index_align_end = np.where(trq_meas_time == trq_des_time[-1])[0][0]
|
| 45 |
+
trq_meas = trq_meas[:index_align_end]
|
| 46 |
+
trq_meas_time = trq_meas_time[:index_align_end]
|
| 47 |
+
|
| 48 |
+
com_time = com_time - com_time[0]
|
| 49 |
+
com_time = com_time[:len(com_time)-index_shifting]
|
| 50 |
+
|
| 51 |
+
trq_des_time = trq_des_time - trq_des_time[0]
|
| 52 |
+
trq_meas_time = trq_meas_time - trq_meas_time[0]
|
| 53 |
+
|
| 54 |
+
# Convert com in mm
|
| 55 |
+
com_des = com_des * 1000
|
| 56 |
+
com_meas = com_meas * 1000
|
| 57 |
+
|
| 58 |
+
colors = ["#E63946", "#457B9D"] # Pinkish-red for desired, blue for measured
|
| 59 |
+
|
| 60 |
+
# Plot from 0 to 100 seconds, discarding the first 50 seconds
|
| 61 |
+
time_20_sec = 3
|
| 62 |
+
end_time = 20.0
|
| 63 |
+
first_index_plot = np.where((com_time - time_20_sec) > 1)[0][0]
|
| 64 |
+
end_index_time = np.where((com_time - time_20_sec - end_time) > 1)[0][0]
|
| 65 |
+
|
| 66 |
+
com_time = trq_meas_time[first_index_plot:end_index_time] - trq_meas_time[first_index_plot]
|
| 67 |
+
com_des = com_des[first_index_plot:end_index_time]
|
| 68 |
+
com_meas = com_meas[first_index_plot:end_index_time]
|
| 69 |
+
|
| 70 |
+
# Fix size of figure
|
| 71 |
+
delta_axis = 30
|
| 72 |
+
plt.figure(figsize=(11,6))
|
| 73 |
+
plt.subplot(3,1,1)
|
| 74 |
+
plt.plot(com_time, com_des[:,0], label="Desired", color=colors[0], linewidth=2)
|
| 75 |
+
plt.plot(com_time, com_meas[:,0], label="Measured", color=colors[1], linewidth=2)
|
| 76 |
+
plt.legend()
|
| 77 |
+
plt.ylabel("CoM X (mm)", fontsize=14)
|
| 78 |
+
plt.ylim(np.mean(com_meas[:,0]) - delta_axis, np.mean(com_meas[:,0]) + delta_axis)
|
| 79 |
+
plt.subplot(3,1,2)
|
| 80 |
+
plt.plot(com_time, com_des[:,1], label="Desired", color=colors[0], linewidth=2)
|
| 81 |
+
plt.plot(com_time, com_meas[:,1], label="Measured", color=colors[1], linewidth=2)
|
| 82 |
+
plt.legend()
|
| 83 |
+
plt.ylabel("CoM Y (mm)", fontsize=14)
|
| 84 |
+
plt.subplot(3,1,3)
|
| 85 |
+
plt.plot(com_time, com_des[:,2], label="Desired", color=colors[0], linewidth=2)
|
| 86 |
+
plt.plot(com_time, com_meas[:,2], label="Measured", color=colors[1], linewidth=2)
|
| 87 |
+
plt.legend()
|
| 88 |
+
plt.ylabel("CoM Z (mm)", fontsize=14)
|
| 89 |
+
plt.ylim(np.mean(com_des[:,2]) - delta_axis, np.mean(com_des[:,2]) + delta_axis)
|
| 90 |
+
xlabel = "Time (s)"
|
| 91 |
+
plt.xlabel(xlabel, fontsize=14)
|
| 92 |
+
plt.xticks(fontsize=16)
|
| 93 |
+
plt.yticks(fontsize=16)
|
| 94 |
+
plt.tight_layout()
|
| 95 |
+
|
| 96 |
+
# Save figure in pdf in folder figures_for_paper and create it if it does not exist
|
| 97 |
+
if not os.path.exists("../figures_for_paper"):
|
| 98 |
+
os.makedirs("../figures_for_paper")
|
| 99 |
+
plt.savefig("../figures_for_paper/com_tracking_on_object_book_lateral_momentum.pdf")
|
| 100 |
+
plt.close()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# Align trajectories
|
| 106 |
+
# Find time index where time is about 20 seconds
|
| 107 |
+
start_plot_index_des = np.where((trq_des_time - time_20_sec) > 1)[0][0]
|
| 108 |
+
start_plot_index_meas = np.where((trq_meas_time - time_20_sec) > 1)[0][0]
|
| 109 |
+
end_plot_index_des = np.where((trq_des_time - time_20_sec - end_time) > 1)[0][0]
|
| 110 |
+
end_plot_index_meas = np.where((trq_meas_time - time_20_sec - end_time) > 1)[0][0]
|
| 111 |
+
|
| 112 |
+
trq_des_time = trq_des_time[start_plot_index_des:end_plot_index_des] - trq_des_time[start_plot_index_des]
|
| 113 |
+
trq_des = trq_des[start_plot_index_des:end_plot_index_des]
|
| 114 |
+
trq_meas_time = trq_meas_time[start_plot_index_meas:end_plot_index_meas] - trq_meas_time[start_plot_index_meas]
|
| 115 |
+
trq_meas = trq_meas[start_plot_index_meas:end_plot_index_meas]
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Measured joints
|
| 119 |
+
measured_joint_list = data_ergocubsn000["joints_state"]["torques"]["elements_names"]
|
| 120 |
+
|
| 121 |
+
# Plot torque tracking for each joint in the list of controlled joints
|
| 122 |
+
controlled_joints = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["elements_names"]
|
| 123 |
+
|
| 124 |
+
# Find indeces of joints contained in controlled_joints and reorder and leave only those joints in measured_joint_list
|
| 125 |
+
indeces_to_remove = []
|
| 126 |
+
for joint in measured_joint_list:
|
| 127 |
+
if joint not in controlled_joints:
|
| 128 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 129 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 130 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 131 |
+
print(trq_meas.shape)
|
| 132 |
+
print(measured_joint_list)
|
| 133 |
+
print(controlled_joints)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
################### PLOT ALL JOINTS #####################
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
fig, axes = plt.subplots(6, 3, figsize=(23,12), sharex=True) # Share x-axis
|
| 140 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 141 |
+
for i, ax in enumerate(axes.ravel()):
|
| 142 |
+
|
| 143 |
+
if i >= len(controlled_joints):
|
| 144 |
+
# Delete the last subplot
|
| 145 |
+
fig
|
| 146 |
+
ax.remove()
|
| 147 |
+
# add legend here
|
| 148 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 149 |
+
break
|
| 150 |
+
print("Plotting joint and axis", i)
|
| 151 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 152 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 153 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 154 |
+
if i % 3 == 0:
|
| 155 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 156 |
+
|
| 157 |
+
if i >= len(controlled_joints)-4:
|
| 158 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 159 |
+
|
| 160 |
+
ax.set_title(controlled_joints[i], fontsize=24)
|
| 161 |
+
|
| 162 |
+
plt.tight_layout()
|
| 163 |
+
plt.subplots_adjust(wspace=0.1)
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
if not os.path.exists("../figures_for_paper"):
|
| 167 |
+
os.makedirs("../figures_for_paper")
|
| 168 |
+
plt.savefig("../figures_for_paper/trq_tracking_on_object_momentum_book_lateral.pdf")
|
| 169 |
+
plt.close()
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
controlled_joints_half = controlled_joints[:8]
|
| 175 |
+
|
| 176 |
+
fig, axes = plt.subplots(3, 3, figsize=(23,8), sharex=True) # Share x-axis
|
| 177 |
+
# fig.suptitle("", fontsize=24, fontweight='bold')
|
| 178 |
+
for i, ax in enumerate(axes.ravel()):
|
| 179 |
+
|
| 180 |
+
if i >= len(controlled_joints_half):
|
| 181 |
+
# Delete the last subplot
|
| 182 |
+
fig
|
| 183 |
+
ax.remove()
|
| 184 |
+
# add legend here
|
| 185 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 186 |
+
break
|
| 187 |
+
print("Plotting joint and axis", i)
|
| 188 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 189 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 190 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 191 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 192 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 193 |
+
|
| 194 |
+
if i >= 6:
|
| 195 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 196 |
+
|
| 197 |
+
ax.set_title(controlled_joints_half[i], fontsize=24)
|
| 198 |
+
|
| 199 |
+
# axes[-1, -1].legend(loc='lower right', bbox_to_anchor=(1.1, -0.35), fontsize=24)
|
| 200 |
+
plt.tight_layout()
|
| 201 |
+
plt.subplots_adjust(wspace=0.1)
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
if not os.path.exists("../figures_for_paper"):
|
| 205 |
+
os.makedirs("../figures_for_paper")
|
| 206 |
+
plt.savefig("../figures_for_paper/trq_tracking_on_object_momentum_book_lateral_half_joints_oriz.pdf")
|
| 207 |
+
plt.close()
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_momentum_1.py
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Path to the other repository
|
| 7 |
+
other_repo_path = "../../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 8 |
+
|
| 9 |
+
# Add the path to sys.path
|
| 10 |
+
sys.path.append(other_repo_path)
|
| 11 |
+
|
| 12 |
+
from load_robot_logger_device_data import load_data
|
| 13 |
+
|
| 14 |
+
data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book/momentum/robot_logger_device_2025_03_13_11_43_35.mat")
|
| 15 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book_lateral/momentum/robot_logger_device_2025_03_13_14_59_27.mat")
|
| 16 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_carpet/momentum/robot_logger_device_2025_03_13_15_08_35.mat")
|
| 17 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_metal/momentum_zoom/robot_logger_device_2025_03_13_14_30_56.mat")
|
| 18 |
+
|
| 19 |
+
index_shifting = 5
|
| 20 |
+
|
| 21 |
+
com_des = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["data"]
|
| 22 |
+
com_meas = data_ergocubsn000["balancing"]["com"]["position"]["measured"]["data"]
|
| 23 |
+
com_time = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["timestamps"]
|
| 24 |
+
|
| 25 |
+
com_des = com_des[:len(com_des)-index_shifting]
|
| 26 |
+
com_meas = com_meas[index_shifting:]
|
| 27 |
+
|
| 28 |
+
trq_des = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["data"]
|
| 29 |
+
trq_des_time = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["timestamps"]
|
| 30 |
+
trq_meas = data_ergocubsn000["joints_state"]["torques"]["data"]
|
| 31 |
+
trq_meas_time = data_ergocubsn000["joints_state"]["torques"]["timestamps"]
|
| 32 |
+
|
| 33 |
+
trq_des = trq_des[:len(trq_des)-index_shifting]
|
| 34 |
+
trq_des_time = trq_des_time[:len(trq_des_time)-index_shifting]
|
| 35 |
+
trq_meas = trq_meas[index_shifting:]
|
| 36 |
+
trq_meas_time = trq_meas_time[index_shifting:]
|
| 37 |
+
|
| 38 |
+
# Find first timestamp of trq_des_time in trq_meas_time and align signals
|
| 39 |
+
index_align_start = np.where(trq_meas_time == trq_des_time[0])[0][0]
|
| 40 |
+
trq_meas = trq_meas[index_align_start:]
|
| 41 |
+
trq_meas_time = trq_meas_time[index_align_start:]
|
| 42 |
+
|
| 43 |
+
# Find last timestamp of trq_des_time in trq_meas_time and align signals
|
| 44 |
+
index_align_end = np.where(trq_meas_time == trq_des_time[-1])[0][0]
|
| 45 |
+
trq_meas = trq_meas[:index_align_end]
|
| 46 |
+
trq_meas_time = trq_meas_time[:index_align_end]
|
| 47 |
+
|
| 48 |
+
com_time = com_time - com_time[0]
|
| 49 |
+
com_time = com_time[:len(com_time)-index_shifting]
|
| 50 |
+
|
| 51 |
+
trq_des_time = trq_des_time - trq_des_time[0]
|
| 52 |
+
trq_meas_time = trq_meas_time - trq_meas_time[0]
|
| 53 |
+
|
| 54 |
+
# Convert com in mm
|
| 55 |
+
com_des = com_des * 1000
|
| 56 |
+
com_meas = com_meas * 1000
|
| 57 |
+
|
| 58 |
+
colors = ["#E63946", "#457B9D"] # Pinkish-red for desired, blue for measured
|
| 59 |
+
|
| 60 |
+
# Plot from 0 to 100 seconds, discarding the first 50 seconds
|
| 61 |
+
time_20_sec = 3
|
| 62 |
+
end_time = 20.0
|
| 63 |
+
first_index_plot = np.where((com_time - time_20_sec) > 1)[0][0]
|
| 64 |
+
end_index_time = np.where((com_time - time_20_sec - end_time) > 1)[0][0]
|
| 65 |
+
|
| 66 |
+
com_time = trq_meas_time[first_index_plot:end_index_time] - trq_meas_time[first_index_plot]
|
| 67 |
+
com_des = com_des[first_index_plot:end_index_time]
|
| 68 |
+
com_meas = com_meas[first_index_plot:end_index_time]
|
| 69 |
+
|
| 70 |
+
# Fix size of figure
|
| 71 |
+
delta_axis = 30
|
| 72 |
+
plt.figure(figsize=(11,6))
|
| 73 |
+
plt.subplot(3,1,1)
|
| 74 |
+
plt.plot(com_time, com_des[:,0], label="Desired", color=colors[0], linewidth=2)
|
| 75 |
+
plt.plot(com_time, com_meas[:,0], label="Measured", color=colors[1], linewidth=2)
|
| 76 |
+
plt.legend()
|
| 77 |
+
plt.ylabel("CoM X (mm)", fontsize=14)
|
| 78 |
+
plt.ylim(np.mean(com_meas[:,0]) - delta_axis, np.mean(com_meas[:,0]) + delta_axis)
|
| 79 |
+
plt.subplot(3,1,2)
|
| 80 |
+
plt.plot(com_time, com_des[:,1], label="Desired", color=colors[0], linewidth=2)
|
| 81 |
+
plt.plot(com_time, com_meas[:,1], label="Measured", color=colors[1], linewidth=2)
|
| 82 |
+
plt.legend()
|
| 83 |
+
plt.ylabel("CoM Y (mm)", fontsize=14)
|
| 84 |
+
plt.subplot(3,1,3)
|
| 85 |
+
plt.plot(com_time, com_des[:,2], label="Desired", color=colors[0], linewidth=2)
|
| 86 |
+
plt.plot(com_time, com_meas[:,2], label="Measured", color=colors[1], linewidth=2)
|
| 87 |
+
plt.legend()
|
| 88 |
+
plt.ylabel("CoM Z (mm)", fontsize=14)
|
| 89 |
+
plt.ylim(np.mean(com_des[:,2]) - delta_axis, np.mean(com_des[:,2]) + delta_axis)
|
| 90 |
+
xlabel = "Time (s)"
|
| 91 |
+
plt.xlabel(xlabel, fontsize=14)
|
| 92 |
+
plt.xticks(fontsize=16)
|
| 93 |
+
plt.yticks(fontsize=16)
|
| 94 |
+
plt.tight_layout()
|
| 95 |
+
|
| 96 |
+
# Save figure in pdf in folder figures_for_paper and create it if it does not exist
|
| 97 |
+
if not os.path.exists("../figures_for_paper"):
|
| 98 |
+
os.makedirs("../figures_for_paper")
|
| 99 |
+
plt.savefig("../figures_for_paper/com_tracking_on_object_book_front_momentum.pdf")
|
| 100 |
+
plt.close()
|
| 101 |
+
|
| 102 |
+
# Align trajectories
|
| 103 |
+
# Find time index where time is about 20 seconds
|
| 104 |
+
start_plot_index_des = np.where((trq_des_time - time_20_sec) > 1)[0][0]
|
| 105 |
+
start_plot_index_meas = np.where((trq_meas_time - time_20_sec) > 1)[0][0]
|
| 106 |
+
end_plot_index_des = np.where((trq_des_time - time_20_sec - end_time) > 1)[0][0]
|
| 107 |
+
end_plot_index_meas = np.where((trq_meas_time - time_20_sec - end_time) > 1)[0][0]
|
| 108 |
+
|
| 109 |
+
trq_des_time = trq_des_time[start_plot_index_des:end_plot_index_des] - trq_des_time[start_plot_index_des]
|
| 110 |
+
trq_des = trq_des[start_plot_index_des:end_plot_index_des]
|
| 111 |
+
trq_meas_time = trq_meas_time[start_plot_index_meas:end_plot_index_meas] - trq_meas_time[start_plot_index_meas]
|
| 112 |
+
trq_meas = trq_meas[start_plot_index_meas:end_plot_index_meas]
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
# Measured joints
|
| 116 |
+
measured_joint_list = data_ergocubsn000["joints_state"]["torques"]["elements_names"]
|
| 117 |
+
|
| 118 |
+
# Plot torque tracking for each joint in the list of controlled joints
|
| 119 |
+
controlled_joints = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["elements_names"]
|
| 120 |
+
|
| 121 |
+
# Find indeces of joints contained in controlled_joints and reorder and leave only those joints in measured_joint_list
|
| 122 |
+
indeces_to_remove = []
|
| 123 |
+
for joint in measured_joint_list:
|
| 124 |
+
if joint not in controlled_joints:
|
| 125 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 126 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 127 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 128 |
+
print(trq_meas.shape)
|
| 129 |
+
print(measured_joint_list)
|
| 130 |
+
print(controlled_joints)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
################### PLOT ALL JOINTS #####################
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
fig, axes = plt.subplots(6, 3, figsize=(23,12), sharex=True) # Share x-axis
|
| 137 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 138 |
+
for i, ax in enumerate(axes.ravel()):
|
| 139 |
+
|
| 140 |
+
if i >= len(controlled_joints):
|
| 141 |
+
# Delete the last subplot
|
| 142 |
+
fig
|
| 143 |
+
ax.remove()
|
| 144 |
+
# add legend here
|
| 145 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 146 |
+
break
|
| 147 |
+
print("Plotting joint and axis", i)
|
| 148 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 149 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 150 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 151 |
+
if i % 3 == 0:
|
| 152 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 153 |
+
|
| 154 |
+
if i >= len(controlled_joints)-4:
|
| 155 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 156 |
+
|
| 157 |
+
ax.set_title(controlled_joints[i], fontsize=24)
|
| 158 |
+
|
| 159 |
+
plt.tight_layout()
|
| 160 |
+
plt.subplots_adjust(wspace=0.1)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
if not os.path.exists("../figures_for_paper"):
|
| 164 |
+
os.makedirs("../figures_for_paper")
|
| 165 |
+
plt.savefig("../figures_for_paper/trq_tracking_on_object_momentum_book_front.pdf")
|
| 166 |
+
plt.close()
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
controlled_joints_half = controlled_joints[:8]
|
| 172 |
+
|
| 173 |
+
fig, axes = plt.subplots(3, 3, figsize=(23,8), sharex=True) # Share x-axis
|
| 174 |
+
# fig.suptitle("", fontsize=24, fontweight='bold')
|
| 175 |
+
for i, ax in enumerate(axes.ravel()):
|
| 176 |
+
|
| 177 |
+
if i >= len(controlled_joints_half):
|
| 178 |
+
# Delete the last subplot
|
| 179 |
+
fig
|
| 180 |
+
ax.remove()
|
| 181 |
+
# add legend here
|
| 182 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 183 |
+
break
|
| 184 |
+
print("Plotting joint and axis", i)
|
| 185 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 186 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 187 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 188 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 189 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 190 |
+
|
| 191 |
+
if i >= 6:
|
| 192 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 193 |
+
|
| 194 |
+
ax.set_title(controlled_joints_half[i], fontsize=24)
|
| 195 |
+
|
| 196 |
+
# axes[-1, -1].legend(loc='lower right', bbox_to_anchor=(1.1, -0.35), fontsize=24)
|
| 197 |
+
plt.tight_layout()
|
| 198 |
+
plt.subplots_adjust(wspace=0.1)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
if not os.path.exists("../figures_for_paper"):
|
| 202 |
+
os.makedirs("../figures_for_paper")
|
| 203 |
+
plt.savefig("../figures_for_paper/trq_tracking_on_object_momentum_book_front_half_joints_oriz.pdf")
|
| 204 |
+
plt.close()
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_momentum_2.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Path to the other repository
|
| 7 |
+
other_repo_path = "../../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 8 |
+
|
| 9 |
+
# Add the path to sys.path
|
| 10 |
+
sys.path.append(other_repo_path)
|
| 11 |
+
|
| 12 |
+
from load_robot_logger_device_data import load_data
|
| 13 |
+
|
| 14 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book/momentum/robot_logger_device_2025_03_13_11_43_35.mat")
|
| 15 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book_lateral/momentum/robot_logger_device_2025_03_13_14_59_27.mat")
|
| 16 |
+
data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_carpet/momentum/robot_logger_device_2025_03_13_15_08_35.mat")
|
| 17 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_metal/momentum_zoom/robot_logger_device_2025_03_13_14_30_56.mat")
|
| 18 |
+
|
| 19 |
+
index_shifting = 5
|
| 20 |
+
|
| 21 |
+
com_des = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["data"]
|
| 22 |
+
com_meas = data_ergocubsn000["balancing"]["com"]["position"]["measured"]["data"]
|
| 23 |
+
com_time = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["timestamps"]
|
| 24 |
+
|
| 25 |
+
com_des = com_des[:len(com_des)-index_shifting]
|
| 26 |
+
com_meas = com_meas[index_shifting:]
|
| 27 |
+
|
| 28 |
+
trq_des = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["data"]
|
| 29 |
+
trq_des_time = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["timestamps"]
|
| 30 |
+
trq_meas = data_ergocubsn000["joints_state"]["torques"]["data"]
|
| 31 |
+
trq_meas_time = data_ergocubsn000["joints_state"]["torques"]["timestamps"]
|
| 32 |
+
|
| 33 |
+
trq_des = trq_des[:len(trq_des)-index_shifting]
|
| 34 |
+
trq_des_time = trq_des_time[:len(trq_des_time)-index_shifting]
|
| 35 |
+
trq_meas = trq_meas[index_shifting:]
|
| 36 |
+
trq_meas_time = trq_meas_time[index_shifting:]
|
| 37 |
+
|
| 38 |
+
# Find first timestamp of trq_des_time in trq_meas_time and align signals
|
| 39 |
+
index_align_start = np.where(trq_meas_time == trq_des_time[0])[0][0]
|
| 40 |
+
trq_meas = trq_meas[index_align_start:]
|
| 41 |
+
trq_meas_time = trq_meas_time[index_align_start:]
|
| 42 |
+
|
| 43 |
+
# Find last timestamp of trq_des_time in trq_meas_time and align signals
|
| 44 |
+
index_align_end = np.where(trq_meas_time == trq_des_time[-1])[0][0]
|
| 45 |
+
trq_meas = trq_meas[:index_align_end]
|
| 46 |
+
trq_meas_time = trq_meas_time[:index_align_end]
|
| 47 |
+
|
| 48 |
+
com_time = com_time - com_time[0]
|
| 49 |
+
com_time = com_time[:len(com_time)-index_shifting]
|
| 50 |
+
|
| 51 |
+
trq_des_time = trq_des_time - trq_des_time[0]
|
| 52 |
+
trq_meas_time = trq_meas_time - trq_meas_time[0]
|
| 53 |
+
|
| 54 |
+
# Convert com in mm
|
| 55 |
+
com_des = com_des * 1000
|
| 56 |
+
com_meas = com_meas * 1000
|
| 57 |
+
|
| 58 |
+
colors = ["#E63946", "#457B9D"] # Pinkish-red for desired, blue for measured
|
| 59 |
+
|
| 60 |
+
# Plot from 0 to 100 seconds, discarding the first 50 seconds
|
| 61 |
+
time_20_sec = 3
|
| 62 |
+
end_time = 20.0
|
| 63 |
+
first_index_plot = np.where((com_time - time_20_sec) > 1)[0][0]
|
| 64 |
+
end_index_time = np.where((com_time - time_20_sec - end_time) > 1)[0][0]
|
| 65 |
+
|
| 66 |
+
com_time = trq_meas_time[first_index_plot:end_index_time] - trq_meas_time[first_index_plot]
|
| 67 |
+
com_des = com_des[first_index_plot:end_index_time]
|
| 68 |
+
com_meas = com_meas[first_index_plot:end_index_time]
|
| 69 |
+
|
| 70 |
+
# Fix size of figure
|
| 71 |
+
delta_axis = 30
|
| 72 |
+
plt.figure(figsize=(11,6))
|
| 73 |
+
plt.subplot(3,1,1)
|
| 74 |
+
plt.plot(com_time, com_des[:,0], label="Desired", color=colors[0], linewidth=2)
|
| 75 |
+
plt.plot(com_time, com_meas[:,0], label="Measured", color=colors[1], linewidth=2)
|
| 76 |
+
plt.legend()
|
| 77 |
+
plt.ylabel("CoM X (mm)", fontsize=14)
|
| 78 |
+
plt.ylim(np.mean(com_meas[:,0]) - delta_axis, np.mean(com_meas[:,0]) + delta_axis)
|
| 79 |
+
plt.subplot(3,1,2)
|
| 80 |
+
plt.plot(com_time, com_des[:,1], label="Desired", color=colors[0], linewidth=2)
|
| 81 |
+
plt.plot(com_time, com_meas[:,1], label="Measured", color=colors[1], linewidth=2)
|
| 82 |
+
plt.legend()
|
| 83 |
+
plt.ylabel("CoM Y (mm)", fontsize=14)
|
| 84 |
+
plt.subplot(3,1,3)
|
| 85 |
+
plt.plot(com_time, com_des[:,2], label="Desired", color=colors[0], linewidth=2)
|
| 86 |
+
plt.plot(com_time, com_meas[:,2], label="Measured", color=colors[1], linewidth=2)
|
| 87 |
+
plt.legend()
|
| 88 |
+
plt.ylabel("CoM Z (mm)", fontsize=14)
|
| 89 |
+
plt.ylim(np.mean(com_des[:,2]) - delta_axis, np.mean(com_des[:,2]) + delta_axis)
|
| 90 |
+
xlabel = "Time (s)"
|
| 91 |
+
plt.xlabel(xlabel, fontsize=14)
|
| 92 |
+
plt.xticks(fontsize=16)
|
| 93 |
+
plt.yticks(fontsize=16)
|
| 94 |
+
plt.tight_layout()
|
| 95 |
+
|
| 96 |
+
# Save figure in pdf in folder figures_for_paper and create it if it does not exist
|
| 97 |
+
if not os.path.exists("../figures_for_paper"):
|
| 98 |
+
os.makedirs("../figures_for_paper")
|
| 99 |
+
plt.savefig("../figures_for_paper/com_tracking_on_object_carpet_momentum.pdf")
|
| 100 |
+
plt.close()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# Align trajectories
|
| 106 |
+
# Find time index where time is about 20 seconds
|
| 107 |
+
start_plot_index_des = np.where((trq_des_time - time_20_sec) > 1)[0][0]
|
| 108 |
+
start_plot_index_meas = np.where((trq_meas_time - time_20_sec) > 1)[0][0]
|
| 109 |
+
end_plot_index_des = np.where((trq_des_time - time_20_sec - end_time) > 1)[0][0]
|
| 110 |
+
end_plot_index_meas = np.where((trq_meas_time - time_20_sec - end_time) > 1)[0][0]
|
| 111 |
+
|
| 112 |
+
trq_des_time = trq_des_time[start_plot_index_des:end_plot_index_des] - trq_des_time[start_plot_index_des]
|
| 113 |
+
trq_des = trq_des[start_plot_index_des:end_plot_index_des]
|
| 114 |
+
trq_meas_time = trq_meas_time[start_plot_index_meas:end_plot_index_meas] - trq_meas_time[start_plot_index_meas]
|
| 115 |
+
trq_meas = trq_meas[start_plot_index_meas:end_plot_index_meas]
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# Measured joints
|
| 119 |
+
measured_joint_list = data_ergocubsn000["joints_state"]["torques"]["elements_names"]
|
| 120 |
+
|
| 121 |
+
# Plot torque tracking for each joint in the list of controlled joints
|
| 122 |
+
controlled_joints = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["elements_names"]
|
| 123 |
+
|
| 124 |
+
# Find indeces of joints contained in controlled_joints and reorder and leave only those joints in measured_joint_list
|
| 125 |
+
indeces_to_remove = []
|
| 126 |
+
for joint in measured_joint_list:
|
| 127 |
+
if joint not in controlled_joints:
|
| 128 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 129 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 130 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 131 |
+
print(trq_meas.shape)
|
| 132 |
+
print(measured_joint_list)
|
| 133 |
+
print(controlled_joints)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
################### PLOT ALL JOINTS #####################
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
fig, axes = plt.subplots(6, 3, figsize=(23,12), sharex=True) # Share x-axis
|
| 140 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 141 |
+
for i, ax in enumerate(axes.ravel()):
|
| 142 |
+
|
| 143 |
+
if i >= len(controlled_joints):
|
| 144 |
+
# Delete the last subplot
|
| 145 |
+
fig
|
| 146 |
+
ax.remove()
|
| 147 |
+
# add legend here
|
| 148 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 149 |
+
break
|
| 150 |
+
print("Plotting joint and axis", i)
|
| 151 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 152 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 153 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 154 |
+
if i % 3 == 0:
|
| 155 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 156 |
+
|
| 157 |
+
if i >= len(controlled_joints)-4:
|
| 158 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 159 |
+
|
| 160 |
+
ax.set_title(controlled_joints[i], fontsize=24)
|
| 161 |
+
|
| 162 |
+
plt.tight_layout()
|
| 163 |
+
plt.subplots_adjust(wspace=0.1)
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
if not os.path.exists("../figures_for_paper"):
|
| 167 |
+
os.makedirs("../figures_for_paper")
|
| 168 |
+
plt.savefig("../figures_for_paper/trq_tracking_on_object_momentum_carpet.pdf")
|
| 169 |
+
plt.close()
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
controlled_joints_half = controlled_joints[:8]
|
| 173 |
+
|
| 174 |
+
fig, axes = plt.subplots(3, 3, figsize=(23,8), sharex=True) # Share x-axis
|
| 175 |
+
# fig.suptitle("", fontsize=24, fontweight='bold')
|
| 176 |
+
for i, ax in enumerate(axes.ravel()):
|
| 177 |
+
|
| 178 |
+
if i >= len(controlled_joints_half):
|
| 179 |
+
# Delete the last subplot
|
| 180 |
+
fig
|
| 181 |
+
ax.remove()
|
| 182 |
+
# add legend here
|
| 183 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 184 |
+
break
|
| 185 |
+
print("Plotting joint and axis", i)
|
| 186 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 187 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 188 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 189 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 190 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 191 |
+
|
| 192 |
+
if i >= 6:
|
| 193 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 194 |
+
|
| 195 |
+
ax.set_title(controlled_joints_half[i], fontsize=24)
|
| 196 |
+
|
| 197 |
+
# axes[-1, -1].legend(loc='lower right', bbox_to_anchor=(1.1, -0.35), fontsize=24)
|
| 198 |
+
plt.tight_layout()
|
| 199 |
+
plt.subplots_adjust(wspace=0.1)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
if not os.path.exists("../figures_for_paper"):
|
| 203 |
+
os.makedirs("../figures_for_paper")
|
| 204 |
+
plt.savefig("../figures_for_paper/trq_tracking_on_object_momentum_carpet_half_joints_oriz.pdf")
|
| 205 |
+
plt.close()
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_momentum_3.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Path to the other repository
|
| 7 |
+
other_repo_path = "../../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 8 |
+
|
| 9 |
+
# Add the path to sys.path
|
| 10 |
+
sys.path.append(other_repo_path)
|
| 11 |
+
|
| 12 |
+
from load_robot_logger_device_data import load_data
|
| 13 |
+
|
| 14 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book/momentum/robot_logger_device_2025_03_13_11_43_35.mat")
|
| 15 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book_lateral/momentum/robot_logger_device_2025_03_13_14_59_27.mat")
|
| 16 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_carpet/momentum/robot_logger_device_2025_03_13_15_08_35.mat")
|
| 17 |
+
data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_metal/momentum_zoom/robot_logger_device_2025_03_13_14_30_56.mat")
|
| 18 |
+
|
| 19 |
+
index_shifting = 5
|
| 20 |
+
|
| 21 |
+
com_des = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["data"]
|
| 22 |
+
com_meas = data_ergocubsn000["balancing"]["com"]["position"]["measured"]["data"]
|
| 23 |
+
com_time = data_ergocubsn000["balancing"]["com"]["position"]["desired"]["timestamps"]
|
| 24 |
+
|
| 25 |
+
com_des = com_des[:len(com_des)-index_shifting]
|
| 26 |
+
com_meas = com_meas[index_shifting:]
|
| 27 |
+
|
| 28 |
+
trq_des = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["data"]
|
| 29 |
+
trq_des_time = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["timestamps"]
|
| 30 |
+
trq_meas = data_ergocubsn000["joints_state"]["torques"]["data"]
|
| 31 |
+
trq_meas_time = data_ergocubsn000["joints_state"]["torques"]["timestamps"]
|
| 32 |
+
|
| 33 |
+
trq_des = trq_des[:len(trq_des)-index_shifting]
|
| 34 |
+
trq_des_time = trq_des_time[:len(trq_des_time)-index_shifting]
|
| 35 |
+
trq_meas = trq_meas[index_shifting:]
|
| 36 |
+
trq_meas_time = trq_meas_time[index_shifting:]
|
| 37 |
+
|
| 38 |
+
# Find first timestamp of trq_des_time in trq_meas_time and align signals
|
| 39 |
+
index_align_start = np.where(trq_meas_time == trq_des_time[0])[0][0]
|
| 40 |
+
trq_meas = trq_meas[index_align_start:]
|
| 41 |
+
trq_meas_time = trq_meas_time[index_align_start:]
|
| 42 |
+
|
| 43 |
+
# Find last timestamp of trq_des_time in trq_meas_time and align signals
|
| 44 |
+
index_align_end = np.where(trq_meas_time == trq_des_time[-1])[0][0]
|
| 45 |
+
trq_meas = trq_meas[:index_align_end]
|
| 46 |
+
trq_meas_time = trq_meas_time[:index_align_end]
|
| 47 |
+
|
| 48 |
+
com_time = com_time - com_time[0]
|
| 49 |
+
com_time = com_time[:len(com_time)-index_shifting]
|
| 50 |
+
|
| 51 |
+
trq_des_time = trq_des_time - trq_des_time[0]
|
| 52 |
+
trq_meas_time = trq_meas_time - trq_meas_time[0]
|
| 53 |
+
|
| 54 |
+
# Convert com in mm
|
| 55 |
+
com_des = com_des * 1000
|
| 56 |
+
com_meas = com_meas * 1000
|
| 57 |
+
|
| 58 |
+
colors = ["#E63946", "#457B9D"] # Pinkish-red for desired, blue for measured
|
| 59 |
+
|
| 60 |
+
# Plot from 0 to 100 seconds, discarding the first 50 seconds
|
| 61 |
+
time_20_sec = 3
|
| 62 |
+
end_time = 20.0
|
| 63 |
+
first_index_plot = np.where((com_time - time_20_sec) > 1)[0][0]
|
| 64 |
+
end_index_time = np.where((com_time - time_20_sec - end_time) > 1)[0][0]
|
| 65 |
+
|
| 66 |
+
com_time = trq_meas_time[first_index_plot:end_index_time] - trq_meas_time[first_index_plot]
|
| 67 |
+
com_des = com_des[first_index_plot:end_index_time]
|
| 68 |
+
com_meas = com_meas[first_index_plot:end_index_time]
|
| 69 |
+
|
| 70 |
+
# Fix size of figure
|
| 71 |
+
delta_axis = 30
|
| 72 |
+
plt.figure(figsize=(11,6))
|
| 73 |
+
plt.subplot(3,1,1)
|
| 74 |
+
plt.plot(com_time, com_des[:,0], label="Desired", color=colors[0], linewidth=2)
|
| 75 |
+
plt.plot(com_time, com_meas[:,0], label="Measured", color=colors[1], linewidth=2)
|
| 76 |
+
plt.legend()
|
| 77 |
+
plt.ylabel("CoM X (mm)", fontsize=14)
|
| 78 |
+
plt.ylim(np.mean(com_meas[:,0]) - delta_axis, np.mean(com_meas[:,0]) + delta_axis)
|
| 79 |
+
plt.subplot(3,1,2)
|
| 80 |
+
plt.plot(com_time, com_des[:,1], label="Desired", color=colors[0], linewidth=2)
|
| 81 |
+
plt.plot(com_time, com_meas[:,1], label="Measured", color=colors[1], linewidth=2)
|
| 82 |
+
plt.legend()
|
| 83 |
+
plt.ylabel("CoM Y (mm)", fontsize=14)
|
| 84 |
+
plt.subplot(3,1,3)
|
| 85 |
+
plt.plot(com_time, com_des[:,2], label="Desired", color=colors[0], linewidth=2)
|
| 86 |
+
plt.plot(com_time, com_meas[:,2], label="Measured", color=colors[1], linewidth=2)
|
| 87 |
+
plt.legend()
|
| 88 |
+
plt.ylabel("CoM Z (mm)", fontsize=14)
|
| 89 |
+
plt.ylim(np.mean(com_des[:,2]) - delta_axis, np.mean(com_des[:,2]) + delta_axis)
|
| 90 |
+
xlabel = "Time (s)"
|
| 91 |
+
plt.xlabel(xlabel, fontsize=14)
|
| 92 |
+
plt.xticks(fontsize=16)
|
| 93 |
+
plt.yticks(fontsize=16)
|
| 94 |
+
plt.tight_layout()
|
| 95 |
+
|
| 96 |
+
# Save figure in pdf in folder figures_for_paper and create it if it does not exist
|
| 97 |
+
if not os.path.exists("../figures_for_paper"):
|
| 98 |
+
os.makedirs("../figures_for_paper")
|
| 99 |
+
plt.savefig("../figures_for_paper/com_tracking_on_object_momentum_metal.pdf")
|
| 100 |
+
plt.close()
|
| 101 |
+
|
| 102 |
+
# Align trajectories
|
| 103 |
+
# Find time index where time is about 20 seconds
|
| 104 |
+
start_plot_index_des = np.where((trq_des_time - time_20_sec) > 1)[0][0]
|
| 105 |
+
start_plot_index_meas = np.where((trq_meas_time - time_20_sec) > 1)[0][0]
|
| 106 |
+
end_plot_index_des = np.where((trq_des_time - time_20_sec - end_time) > 1)[0][0]
|
| 107 |
+
end_plot_index_meas = np.where((trq_meas_time - time_20_sec - end_time) > 1)[0][0]
|
| 108 |
+
|
| 109 |
+
trq_des_time = trq_des_time[start_plot_index_des:end_plot_index_des] - trq_des_time[start_plot_index_des]
|
| 110 |
+
trq_des = trq_des[start_plot_index_des:end_plot_index_des]
|
| 111 |
+
trq_meas_time = trq_meas_time[start_plot_index_meas:end_plot_index_meas] - trq_meas_time[start_plot_index_meas]
|
| 112 |
+
trq_meas = trq_meas[start_plot_index_meas:end_plot_index_meas]
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
# Measured joints
|
| 116 |
+
measured_joint_list = data_ergocubsn000["joints_state"]["torques"]["elements_names"]
|
| 117 |
+
|
| 118 |
+
# Plot torque tracking for each joint in the list of controlled joints
|
| 119 |
+
controlled_joints = data_ergocubsn000["balancing"]["joint_state"]["torque"]["desired"]["elements_names"]
|
| 120 |
+
|
| 121 |
+
# Find indeces of joints contained in controlled_joints and reorder and leave only those joints in measured_joint_list
|
| 122 |
+
indeces_to_remove = []
|
| 123 |
+
for joint in measured_joint_list:
|
| 124 |
+
if joint not in controlled_joints:
|
| 125 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 126 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 127 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 128 |
+
print(trq_meas.shape)
|
| 129 |
+
print(measured_joint_list)
|
| 130 |
+
print(controlled_joints)
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
################### PLOT ALL JOINTS #####################
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
fig, axes = plt.subplots(6, 3, figsize=(23,12), sharex=True) # Share x-axis
|
| 137 |
+
fig.suptitle("UKF-PINN", fontsize=24, fontweight='bold')
|
| 138 |
+
for i, ax in enumerate(axes.ravel()):
|
| 139 |
+
|
| 140 |
+
if i >= len(controlled_joints):
|
| 141 |
+
# Delete the last subplot
|
| 142 |
+
fig
|
| 143 |
+
ax.remove()
|
| 144 |
+
# add legend here
|
| 145 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 146 |
+
break
|
| 147 |
+
print("Plotting joint and axis", i)
|
| 148 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 149 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 150 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 151 |
+
if i % 3 == 0:
|
| 152 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 153 |
+
|
| 154 |
+
if i >= len(controlled_joints)-4:
|
| 155 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 156 |
+
|
| 157 |
+
ax.set_title(controlled_joints[i], fontsize=24)
|
| 158 |
+
|
| 159 |
+
plt.tight_layout()
|
| 160 |
+
plt.subplots_adjust(wspace=0.1)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
if not os.path.exists("../figures_for_paper"):
|
| 164 |
+
os.makedirs("../figures_for_paper")
|
| 165 |
+
plt.savefig("../figures_for_paper/trq_tracking_on_object_momentum_metal.pdf")
|
| 166 |
+
plt.close()
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
controlled_joints_half = controlled_joints[:8]
|
| 170 |
+
|
| 171 |
+
fig, axes = plt.subplots(3, 3, figsize=(23,8), sharex=True) # Share x-axis
|
| 172 |
+
# fig.suptitle("", fontsize=24, fontweight='bold')
|
| 173 |
+
for i, ax in enumerate(axes.ravel()):
|
| 174 |
+
|
| 175 |
+
if i >= len(controlled_joints_half):
|
| 176 |
+
# Delete the last subplot
|
| 177 |
+
fig
|
| 178 |
+
ax.remove()
|
| 179 |
+
# add legend here
|
| 180 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 181 |
+
break
|
| 182 |
+
print("Plotting joint and axis", i)
|
| 183 |
+
ax.plot(trq_des_time, trq_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 184 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 185 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 186 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 187 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 188 |
+
|
| 189 |
+
if i >= 6:
|
| 190 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 191 |
+
|
| 192 |
+
ax.set_title(controlled_joints_half[i], fontsize=24)
|
| 193 |
+
|
| 194 |
+
# axes[-1, -1].legend(loc='lower right', bbox_to_anchor=(1.1, -0.35), fontsize=24)
|
| 195 |
+
plt.tight_layout()
|
| 196 |
+
plt.subplots_adjust(wspace=0.1)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
if not os.path.exists("../figures_for_paper"):
|
| 200 |
+
os.makedirs("../figures_for_paper")
|
| 201 |
+
plt.savefig("../figures_for_paper/trq_tracking_on_object_momentum_metal_half_joints_oriz.pdf")
|
| 202 |
+
plt.close()
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/plot_resubmission_object_position.py
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
|
| 6 |
+
# Path to the other repository
|
| 7 |
+
other_repo_path = "../../../element_sensorless-torque-control/code/python/utilities/general_scripts"
|
| 8 |
+
|
| 9 |
+
# Add the path to sys.path
|
| 10 |
+
sys.path.append(other_repo_path)
|
| 11 |
+
|
| 12 |
+
from load_robot_logger_device_data import load_data
|
| 13 |
+
|
| 14 |
+
data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_book_lateral/position/robot_logger_device_2025_03_13_15_02_57.mat")
|
| 15 |
+
# data_ergocubsn000 = load_data("../../PaperRALDatasetUsedForResultsAndVideos/balancing_on_metal/position/robot_logger_device_2025_03_13_14_36_32.mat")
|
| 16 |
+
|
| 17 |
+
index_shifting = 5
|
| 18 |
+
|
| 19 |
+
com_des = data_ergocubsn000["balancingposition"]["com"]["planned"]["position"]["data"]
|
| 20 |
+
com_meas = data_ergocubsn000["balancingposition"]["com"]["measured"]["with_joint_measured"]["data"]
|
| 21 |
+
com_time = data_ergocubsn000["balancingposition"]["com"]["planned"]["position"]["timestamps"]
|
| 22 |
+
|
| 23 |
+
com_des = com_des[:len(com_des)-index_shifting]
|
| 24 |
+
com_meas = com_meas[index_shifting:]
|
| 25 |
+
|
| 26 |
+
pos_des = data_ergocubsn000["balancingposition"]["joints"]["desired"]["position"]["data"]
|
| 27 |
+
pos_des_time = data_ergocubsn000["balancingposition"]["joints"]["desired"]["position"]["timestamps"]
|
| 28 |
+
pos_meas = data_ergocubsn000["joints_state"]["positions"]["data"]
|
| 29 |
+
pos_meas_time = data_ergocubsn000["joints_state"]["positions"]["timestamps"]
|
| 30 |
+
trq_meas = data_ergocubsn000["joints_state"]["torques"]["data"]
|
| 31 |
+
trq_meas_time = data_ergocubsn000["joints_state"]["torques"]["timestamps"]
|
| 32 |
+
|
| 33 |
+
pos_des = pos_des[:len(pos_des)-index_shifting]
|
| 34 |
+
pos_des_time = pos_des_time[:len(pos_des_time)-index_shifting]
|
| 35 |
+
pos_meas = pos_meas[index_shifting:]
|
| 36 |
+
pos_meas_time = pos_meas_time[index_shifting:]
|
| 37 |
+
|
| 38 |
+
trq_meas = trq_meas[index_shifting:]
|
| 39 |
+
trq_meas_time = trq_meas_time[index_shifting:]
|
| 40 |
+
|
| 41 |
+
# Find first timestamp of pos_des_time in pos_meas_time and align signals
|
| 42 |
+
index_align_start = np.where(pos_meas_time == pos_des_time[0])[0][0]
|
| 43 |
+
pos_meas = pos_meas[index_align_start:]
|
| 44 |
+
pos_meas_time = pos_meas_time[index_align_start:]
|
| 45 |
+
|
| 46 |
+
trq_meas = trq_meas[index_align_start:]
|
| 47 |
+
trq_meas_time = trq_meas_time[index_align_start:]
|
| 48 |
+
|
| 49 |
+
# Find last timestamp of pos_des_time in pos_meas_time and align signals
|
| 50 |
+
index_align_end = np.where(pos_meas_time == pos_des_time[-1])[0][0]
|
| 51 |
+
pos_meas = pos_meas[:index_align_end]
|
| 52 |
+
pos_meas_time = pos_meas_time[:index_align_end]
|
| 53 |
+
|
| 54 |
+
trq_meas = trq_meas[:index_align_end]
|
| 55 |
+
trq_meas_time = trq_meas_time[:index_align_end]
|
| 56 |
+
|
| 57 |
+
com_time = com_time - com_time[0]
|
| 58 |
+
com_time = com_time[:len(com_time)-index_shifting]
|
| 59 |
+
|
| 60 |
+
pos_des_time = pos_des_time - pos_des_time[0]
|
| 61 |
+
pos_meas_time = pos_meas_time - pos_meas_time[0]
|
| 62 |
+
|
| 63 |
+
trq_meas_time = trq_meas_time - trq_meas_time[0]
|
| 64 |
+
|
| 65 |
+
# Convert com in mm
|
| 66 |
+
com_des = com_des * 1000
|
| 67 |
+
com_meas = com_meas * 1000
|
| 68 |
+
|
| 69 |
+
colors = ["#E63946", "#457B9D"] # Pinkish-red for desired, blue for measured
|
| 70 |
+
|
| 71 |
+
# Plot from 0 to 100 seconds, discarding the first 50 seconds
|
| 72 |
+
time_20_sec = 25
|
| 73 |
+
end_time = 30
|
| 74 |
+
first_index_plot = np.where((com_time - time_20_sec) > 1)[0][0]
|
| 75 |
+
end_index_time = np.where((com_time - time_20_sec - end_time) > 1)[0][0]
|
| 76 |
+
|
| 77 |
+
com_time = pos_meas_time[first_index_plot:end_index_time] - pos_meas_time[first_index_plot]
|
| 78 |
+
com_des = com_des[first_index_plot:end_index_time]
|
| 79 |
+
com_meas = com_meas[first_index_plot:end_index_time]
|
| 80 |
+
|
| 81 |
+
# Fix size of figure
|
| 82 |
+
delta_axis = 30
|
| 83 |
+
plt.figure(figsize=(11,6))
|
| 84 |
+
plt.subplot(3,1,1)
|
| 85 |
+
plt.plot(com_time, com_des[:,0], label="Desired", color=colors[0], linewidth=2)
|
| 86 |
+
plt.plot(com_time, com_meas[:,0], label="Measured", color=colors[1], linewidth=2)
|
| 87 |
+
plt.legend()
|
| 88 |
+
plt.ylabel("CoM X (mm)", fontsize=14)
|
| 89 |
+
plt.ylim(np.mean(com_meas[:,0]) - delta_axis, np.mean(com_meas[:,0]) + delta_axis)
|
| 90 |
+
plt.subplot(3,1,2)
|
| 91 |
+
plt.plot(com_time, com_des[:,1], label="Desired", color=colors[0], linewidth=2)
|
| 92 |
+
plt.plot(com_time, com_meas[:,1], label="Measured", color=colors[1], linewidth=2)
|
| 93 |
+
plt.legend()
|
| 94 |
+
plt.ylabel("CoM Y (mm)", fontsize=14)
|
| 95 |
+
plt.subplot(3,1,3)
|
| 96 |
+
plt.plot(com_time, com_des[:,2], label="Desired", color=colors[0], linewidth=2)
|
| 97 |
+
plt.plot(com_time, com_meas[:,2], label="Measured", color=colors[1], linewidth=2)
|
| 98 |
+
plt.legend()
|
| 99 |
+
plt.ylabel("CoM Z (mm)", fontsize=14)
|
| 100 |
+
plt.ylim(np.mean(com_des[:,2]) - delta_axis, np.mean(com_des[:,2]) + delta_axis)
|
| 101 |
+
xlabel = "Time (s)"
|
| 102 |
+
plt.xlabel(xlabel, fontsize=14)
|
| 103 |
+
plt.xticks(fontsize=16)
|
| 104 |
+
plt.yticks(fontsize=16)
|
| 105 |
+
plt.tight_layout()
|
| 106 |
+
|
| 107 |
+
# Save figure in pdf in folder figures_for_paper and create it if it does not exist
|
| 108 |
+
if not os.path.exists("../figures_for_paper"):
|
| 109 |
+
os.makedirs("../figures_for_paper")
|
| 110 |
+
plt.savefig("../figures_for_paper/com_tracking_on_object_position.pdf")
|
| 111 |
+
plt.close()
|
| 112 |
+
|
| 113 |
+
# Plot torque tracking for each joint in the list of controlled joints
|
| 114 |
+
controlled_joints = data_ergocubsn000["balancingposition"]["joints"]["desired"]["position"]["elements_names"]
|
| 115 |
+
|
| 116 |
+
# Find index of joint names r_shoulder_yaw, r_elbow, l_shoulder_yaw, l_elbow and remove from data pos_des_time and pos_meas_time
|
| 117 |
+
index_r_shoulder_pitch = controlled_joints.index("r_shoulder_pitch")
|
| 118 |
+
index_r_shoulder_roll = controlled_joints.index("r_shoulder_roll")
|
| 119 |
+
index_l_shoulder_pitch = controlled_joints.index("l_shoulder_pitch")
|
| 120 |
+
index_l_shoulder_roll = controlled_joints.index("l_shoulder_roll")
|
| 121 |
+
# Remove the joints from the dataset
|
| 122 |
+
pos_des = np.delete(pos_des, [index_r_shoulder_pitch, index_r_shoulder_roll, index_l_shoulder_pitch, index_l_shoulder_roll], axis=1)
|
| 123 |
+
controlled_joints = np.delete(controlled_joints, [index_r_shoulder_pitch, index_r_shoulder_roll, index_l_shoulder_pitch, index_l_shoulder_roll])
|
| 124 |
+
print(controlled_joints)
|
| 125 |
+
|
| 126 |
+
# Measured joints
|
| 127 |
+
measured_joint_list = data_ergocubsn000["joints_state"]["torques"]["elements_names"]
|
| 128 |
+
# Find indeces of joints contained in controlled_joints and remove from measured_joint_list and from pos_meas all the others
|
| 129 |
+
indeces_to_remove = []
|
| 130 |
+
for joint in measured_joint_list:
|
| 131 |
+
if joint not in controlled_joints:
|
| 132 |
+
indeces_to_remove.append(measured_joint_list.index(joint))
|
| 133 |
+
pos_meas = np.delete(pos_meas, indeces_to_remove, axis=1)
|
| 134 |
+
trq_meas = np.delete(trq_meas, indeces_to_remove, axis=1)
|
| 135 |
+
measured_joint_list = np.delete(measured_joint_list, indeces_to_remove)
|
| 136 |
+
print(pos_meas.shape)
|
| 137 |
+
print(measured_joint_list)
|
| 138 |
+
|
| 139 |
+
# Crete number of subplots based on number of controlled joints
|
| 140 |
+
n_subplots = len(controlled_joints)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
# Find time index where time is about 20 seconds
|
| 144 |
+
start_plot_index_des = np.where((pos_des_time - time_20_sec) > 1)[0][0]
|
| 145 |
+
start_plot_index_meas = np.where((pos_meas_time - time_20_sec) > 1)[0][0]
|
| 146 |
+
end_plot_index_des = np.where((pos_des_time - time_20_sec - end_time) > 1)[0][0]
|
| 147 |
+
end_plot_index_meas = np.where((pos_meas_time - time_20_sec - end_time) > 1)[0][0]
|
| 148 |
+
|
| 149 |
+
pos_des_time = pos_des_time[start_plot_index_des:end_plot_index_des] - pos_des_time[start_plot_index_des]
|
| 150 |
+
pos_des = pos_des[start_plot_index_des:end_plot_index_des]
|
| 151 |
+
pos_meas_time = pos_meas_time[start_plot_index_meas:end_plot_index_meas] - pos_meas_time[start_plot_index_meas]
|
| 152 |
+
pos_meas = pos_meas[start_plot_index_meas:end_plot_index_meas]
|
| 153 |
+
|
| 154 |
+
trq_meas_time = trq_meas_time[start_plot_index_meas:end_plot_index_meas] - trq_meas_time[start_plot_index_meas]
|
| 155 |
+
trq_meas = trq_meas[start_plot_index_meas:end_plot_index_meas]
|
| 156 |
+
|
| 157 |
+
plt.figure(figsize=(18,10))
|
| 158 |
+
for i, joint in enumerate(controlled_joints):
|
| 159 |
+
plt.subplot(5,3,i+1)
|
| 160 |
+
plt.plot(pos_des_time, pos_des[:,i], label="Desired", color=colors[0], linewidth=2)
|
| 161 |
+
plt.plot(pos_meas_time, pos_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 162 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 163 |
+
plt.ylabel(f"Position (rad)", fontsize=14)
|
| 164 |
+
plt.title(joint, fontsize=14)
|
| 165 |
+
if i >= 11:
|
| 166 |
+
xlabel = "Time (s)"
|
| 167 |
+
plt.xlabel(xlabel, fontsize=14)
|
| 168 |
+
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), fontsize=14)
|
| 169 |
+
plt.xticks(fontsize=16)
|
| 170 |
+
plt.yticks(fontsize=16)
|
| 171 |
+
plt.tight_layout()
|
| 172 |
+
plt.tight_layout()
|
| 173 |
+
plt.subplots_adjust(wspace=0.1)
|
| 174 |
+
# plt.show()
|
| 175 |
+
|
| 176 |
+
if not os.path.exists("../figures_for_paper"):
|
| 177 |
+
os.makedirs("../figures_for_paper")
|
| 178 |
+
plt.savefig("../figures_for_paper/pos_tracking_on_object_position.pdf")
|
| 179 |
+
plt.close()
|
| 180 |
+
|
| 181 |
+
# Plot measured torques for each joint in the list of controlled joints
|
| 182 |
+
plt.figure(figsize=(18,10))
|
| 183 |
+
for i, joint in enumerate(controlled_joints):
|
| 184 |
+
plt.subplot(5,3,i+1)
|
| 185 |
+
plt.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 186 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 187 |
+
plt.ylabel(f"Torque (Nm)", fontsize=14)
|
| 188 |
+
plt.title(joint, fontsize=14)
|
| 189 |
+
if i >= 11:
|
| 190 |
+
xlabel = "Time (s)"
|
| 191 |
+
plt.xlabel(xlabel, fontsize=14)
|
| 192 |
+
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5), fontsize=14)
|
| 193 |
+
plt.xticks(fontsize=16)
|
| 194 |
+
plt.yticks(fontsize=16)
|
| 195 |
+
plt.tight_layout()
|
| 196 |
+
plt.tight_layout()
|
| 197 |
+
plt.subplots_adjust(wspace=0.1)
|
| 198 |
+
# plt.show()
|
| 199 |
+
|
| 200 |
+
if not os.path.exists("../figures_for_paper"):
|
| 201 |
+
os.makedirs("../figures_for_paper")
|
| 202 |
+
plt.savefig("../figures_for_paper/trq_on_object_position.pdf")
|
| 203 |
+
plt.close()
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
controlled_joints_half = controlled_joints[:8]
|
| 208 |
+
|
| 209 |
+
fig, axes = plt.subplots(3, 3, figsize=(23,8), sharex=True) # Share x-axis
|
| 210 |
+
for i, ax in enumerate(axes.ravel()):
|
| 211 |
+
|
| 212 |
+
if i >= len(controlled_joints_half):
|
| 213 |
+
# Delete the last subplot
|
| 214 |
+
fig
|
| 215 |
+
ax.remove()
|
| 216 |
+
# add legend here
|
| 217 |
+
axes[-1, -2].legend(loc='lower right', bbox_to_anchor=(1.5, 0), fontsize=24)
|
| 218 |
+
break
|
| 219 |
+
print("Plotting joint and axis", i)
|
| 220 |
+
ax.plot(trq_meas_time, trq_meas[:,i], label="Measured", color=colors[1], linewidth=2)
|
| 221 |
+
ax.tick_params(axis='both', labelsize=18)
|
| 222 |
+
if i == 0 or i == 3 or i == 6 or i == 9 or i == 12:
|
| 223 |
+
ax.set_ylabel(f"$\\tau$ (Nm)", fontsize=24)
|
| 224 |
+
|
| 225 |
+
if i >= 6:
|
| 226 |
+
ax.set_xlabel("Time (s)", fontsize=24)
|
| 227 |
+
|
| 228 |
+
ax.set_title(controlled_joints_half[i], fontsize=24)
|
| 229 |
+
|
| 230 |
+
plt.tight_layout()
|
| 231 |
+
plt.subplots_adjust(wspace=0.1)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
if not os.path.exists("../figures_for_paper"):
|
| 235 |
+
os.makedirs("../figures_for_paper")
|
| 236 |
+
plt.savefig("../figures_for_paper/trq_on_object_position_half_joints_oriz.pdf")
|
| 237 |
+
plt.close()
|
FirstSubmission/PaperRAL_ScriptAndVideo/script/run_all.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This script runs all the scripts in the project
|
| 2 |
+
#
|
| 3 |
+
# The script is useful to run all the scripts in the project
|
| 4 |
+
# and check if all the scripts are working properly
|
| 5 |
+
#
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
# List of scripts to run
|
| 12 |
+
scripts = [
|
| 13 |
+
"plot_resubmission_ground_ergocubsn000.py",
|
| 14 |
+
"plot_resubmission_ground_ergocubsn001.py",
|
| 15 |
+
"plot_resubmission_ground_RNEA.py",
|
| 16 |
+
"plot_resubmission_object_momentum_0.py",
|
| 17 |
+
"plot_resubmission_object_position.py"
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
# Run all the scripts
|
| 21 |
+
for script in scripts:
|
| 22 |
+
os.system("python " + script)
|
| 23 |
+
print("Script " + script + " executed successfully")
|
FirstSubmission/PaperRAL_ScriptAndVideo/ukfpinn_sn000_sn001_camera_high_res.MP4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6c8d801ef55b016f03fb26678c0dd797ba0cc3edea25a012cb6d5bb60686bfe1
|
| 3 |
+
size 966459031
|
FirstSubmission/PaperRAL_ScriptAndVideo/ukfpinn_sn000_sn001_camera_low_res.MP4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b5abff4062c6a22f9679adce3e21d77abe48739f62f09bf166fa5bb3365cbbb4
|
| 3 |
+
size 2056167433
|