Commit bc39e0f6 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

erp5_wendelin_drone: update to new timestamping format

parent 6331971f
......@@ -39,7 +39,16 @@ def rated_value(next_value, previous_value, rate):
def nparray_to_dataframe(nparray):
return pd.DataFrame(
data=nparray.getArray(),
columns=["timestamp (ms)","latitude ()","longitude ()","AMSL (m)","rel altitude (m)","yaw ()","ground speed (m/s)","climb rate (m/s)"],
columns=[
'timestamp (ms)',
'latitude ()',
'longitude ()',
'AMSL (m)',
'rel altitude (m)',
'yaw ()',
'ground speed (m/s)',
'climb rate (m/s)',
],
)
......@@ -95,70 +104,57 @@ if seen_sims is None:
simulated_flight_list = []
simulated_flights_value_dict_list = []
selected_simulation_data_dict_list = []
if len([x for x in sim_flight_names if x not in seen_sims]) == 0:
return
not_seen_list = [x for x in sim_flight_names if x not in seen_sims]
if len(not_seen_list) == 0:
return
distance_criterion_tuple = (
'latitude ()',
'longitude ()',
'AMSL (m)',
'ground speed (m/s)',
'climb rate (m/s)',
)
not_seen_list = [x for x in sim_flight_names if x not in seen_sims]
for name in not_seen_list[:]:
for name in not_seen_list:
if name[:14] == 'simulation_log':
splitted_filename = name[:-4].split('_')
distance_list_tuple = ([],[], [], [], [])
simulated_flight = nparray_to_dataframe(sim_array.get(name))
simulated_flight = simulated_flight.applymap(lambda value: np.format_float_scientific(float(value)) if isinstance(value, str) and 'e' in value else value)
simulated_flight_list.append(simulated_flight)
max_simulator_timestamp = simulated_flight["timestamp (ms)"].max()
min_simulator_timestamp = simulated_flight["timestamp (ms)"].min()
tmp_sim = {
'longitude': [],
'latitude': [],
'asml': [],
'ground_speed': [],
'climb_rate': []
}
tmp_real = {
'longitude': [],
'latitude': [],
'asml': [],
'ground_speed': [],
'climb_rate': []
}
timestamp_diff = simulated_flight['timestamp (ms)'].min() - real_flight['timestamp (ms)'].min()
max_simulator_timestamp = simulated_flight['timestamp (ms)'].max() - timestamp_diff
tmp_sim = {k: [] for k in distance_criterion_tuple}
tmp_real = {k: [] for k in distance_criterion_tuple}
for idx, row in real_flight.iterrows():
if max_simulator_timestamp < row["timestamp (ms)"]:
if max_simulator_timestamp < row['timestamp (ms)']:
break
if min_simulator_timestamp > row["timestamp (ms)"]:
try:
under_timestamp = simulated_flight[simulated_flight['timestamp (ms)'] - timestamp_diff < row['timestamp (ms)']].tail(1)
except IndexError:
continue
over_timestamp = simulated_flight[simulated_flight["timestamp (ms)"] >= row["timestamp (ms)"]].head(1)
under_timestamp = simulated_flight[simulated_flight["timestamp (ms)"] <= row["timestamp (ms)"]].tail(1)
rate = (float(over_timestamp["timestamp (ms)"]) - row["timestamp (ms)"])/(float(over_timestamp["timestamp (ms)"]) - float(under_timestamp["timestamp (ms)"]))
tmp_sim["latitude"].append(rated_value(float(over_timestamp["latitude ()"]), float(under_timestamp["latitude ()"]), rate))
tmp_sim["longitude"].append(rated_value(float(over_timestamp["longitude ()"]), float(under_timestamp["longitude ()"]), rate))
tmp_sim["asml"].append(rated_value(float(over_timestamp["AMSL (m)"]), float(under_timestamp["AMSL (m)"]), rate))
tmp_sim["ground_speed"].append(rated_value(float(over_timestamp["ground speed (m/s)"]), float(under_timestamp["ground speed (m/s)"]), rate))
tmp_sim["climb_rate"].append(rated_value(float(over_timestamp["climb rate (m/s)"]), float(under_timestamp["climb rate (m/s)"]), rate))
tmp_real["latitude"].append(row["latitude ()"])
tmp_real["longitude"].append(row["longitude ()"])
tmp_real["asml"].append(row["AMSL (m)"])
tmp_real["ground_speed"].append(row["ground speed (m/s)"])
tmp_real["climb_rate"].append(row["climb rate (m/s)"])
over_timestamp = simulated_flight[simulated_flight['timestamp (ms)'] - timestamp_diff >= row['timestamp (ms)']].head(1)
rate = (float(over_timestamp["timestamp (ms)"]) - timestamp_diff - row["timestamp (ms)"])/(float(over_timestamp["timestamp (ms)"]) - float(under_timestamp["timestamp (ms)"]))
for criterion in distance_criterion_tuple:
tmp_sim[criterion].append(rated_value(float(over_timestamp[criterion]), float(under_timestamp[criterion]), rate))
tmp_real[criterion].append(row[criterion])
for index, value in enumerate((
row["timestamp (ms)"] / 1000,
distance(
row["latitude ()"],
row["longitude ()"],
rated_value(float(over_timestamp["latitude ()"]), float(under_timestamp["latitude ()"]), rate),
rated_value(float(over_timestamp["longitude ()"]), float(under_timestamp["longitude ()"]), rate),
row['timestamp (ms)'] / 1000,
distance(row['latitude ()'],
row['longitude ()'],
tmp_sim['latitude ()'][-1],
tmp_sim['longitude ()'][-1],
),
rated_value(float(over_timestamp["AMSL (m)"]), float(under_timestamp["AMSL (m)"]), rate) - row["AMSL (m)"],
rated_value(float(over_timestamp["ground speed (m/s)"]), float(under_timestamp["ground speed (m/s)"]), rate) - row["ground speed (m/s)"],
rated_value(float(over_timestamp["climb rate (m/s)"]), float(under_timestamp["climb rate (m/s)"]), rate) - row["climb rate (m/s)"]
tmp_sim['AMSL (m)'][-1],
tmp_sim['ground speed (m/s)'][-1],
tmp_real['climb rate (m/s)'][-1]
)):
distance_list_tuple[index].append(value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment