plot-log-files-4-wheels.py
Go to the documentation of this file.
1 #!/bin/env python3
2 
3 # Usage:
4 # plot-log-files.py session1-mvsim_r1_logger_pose.log
5 
6 # Requirements:
7 # pip install pandas matplotlib
8 
9 import pandas as pd
10 import matplotlib.pyplot as plt
11 import sys
12 import os
13 
14 
15 def main(file_path):
16  # Read the main file
17  try:
18  main_data = pd.read_csv(file_path, skipinitialspace=True)
19  print(f"Main data loaded from {file_path}")
20  except Exception as e:
21  print(f"Error reading {file_path}: {e}")
22  return
23 
24  # Define the wheel files based on the main file name
25  base_name = file_path.replace("pose.log", "")
26  wheel_files = [f"{base_name}wheel{i}.log" for i in range(1, 5)]
27 
28  # Load wheel data
29  wheel_data = {}
30  for i, wheel_file in enumerate(wheel_files, start=1):
31  try:
32  wheel_data[i] = pd.read_csv(wheel_file, skipinitialspace=True)
33  print(f"Wheel {i} data loaded from {wheel_file}")
34  except Exception as e:
35  print(f"Error reading {wheel_file}: {e}")
36  return
37 
38  # Create plots for the wheel files (non-blocking)
39  plot_wheel_data(wheel_data)
40 
41  # Create plots for the main file (blocking)
42  plot_main_data(main_data)
43 
44 
45 def plot_main_data(data):
46  """Create plots for the main file data."""
47  plt.figure(figsize=(12, 8))
48 
49  # print(data.columns)
50  ts = data['Timestamp'].to_numpy()
51 
52  # Plot 1: qx, qy, qz over time
53  plt.subplot(3, 1, 1)
54  plt.plot(ts, data['qx'].to_numpy(), label='qx')
55  plt.plot(ts, data['qy'].to_numpy(), label='qy')
56  plt.plot(ts, data['qz'].to_numpy(), label='qz')
57  plt.xlabel('Timestamp')
58  plt.ylabel('Position')
59  plt.title('Position (qx, qy, qz) vs Time')
60  plt.grid()
61  plt.legend()
62 
63  # Plot 2: Orientation angles (qpitch, qroll, qyaw) over time
64  plt.subplot(3, 1, 2)
65  plt.plot(ts,
66  data['qpitch'].to_numpy(), label='qpitch')
67  plt.plot(ts,
68  data['qroll'].to_numpy(), label='qroll')
69  plt.plot(ts,
70  data['qyaw'].to_numpy(), label='qyaw')
71  plt.xlabel('Timestamp')
72  plt.ylabel('Orientation')
73  plt.title('Orientation Angles vs Time')
74  plt.grid()
75  plt.legend()
76 
77  # Plot 3: dqz over time
78  plt.subplot(3, 1, 3)
79  plt.plot(ts, data['dqx'].to_numpy(), label='dqx', color='red')
80  plt.plot(ts, data['dqy'].to_numpy(), label='dqy', color='green')
81  plt.plot(ts, data['dqz'].to_numpy(), label='dqz', color='blue')
82  plt.xlabel('Timestamp')
83  plt.ylabel('Velocity')
84  plt.title('Velocity components')
85  plt.grid()
86  plt.legend()
87 
88  plt.tight_layout()
89  plt.show()
90 
91 
92 def plot_wheel_data(wheel_data):
93  """Create plots for the wheel data."""
94  plt.figure(figsize=(12, 12))
95 
96  # Create one plot per variable group across all wheels
97  variables = ['friction_x', 'friction_y',
98  'velocity_x', 'velocity_y',
99  'torque', 'weight']
100  wheel_names = ['LR', 'RR', 'LF', 'RF']
101 
102  for i, var in enumerate(variables, start=1):
103  plt.subplot(3, 2, i)
104  for wheel, data in wheel_data.items():
105  ts = data['Timestamp'].to_numpy()
106  plt.plot(ts,
107  data[var].to_numpy(), label=f'{wheel_names[wheel-1]} wheel')
108  plt.xlabel('Timestamp')
109  plt.ylabel(var)
110  plt.title(f'{var.capitalize()} vs Time')
111  plt.grid()
112  plt.legend()
113 
114  plt.tight_layout()
115  plt.show(block=False)
116 
117 
118 if __name__ == "__main__":
119  # Check if the path to the main file is provided
120  if len(sys.argv) != 2:
121  print("Usage: python3 script.py </path/to/session1-mvsim_r1_logger_pose.log>")
122  sys.exit(1)
123 
124  file_path = sys.argv[1]
125  main(file_path)
plot-log-files-4-wheels.plot_main_data
def plot_main_data(data)
Definition: plot-log-files-4-wheels.py:45
plot-log-files-4-wheels.main
def main(file_path)
Definition: plot-log-files-4-wheels.py:15
rapidxml::print
OutIt print(OutIt out, const xml_node< Ch > &node, int flags=0)
Definition: rapidxml_print.hpp:405
plot-log-files-4-wheels.plot_wheel_data
def plot_wheel_data(wheel_data)
Definition: plot-log-files-4-wheels.py:92


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:08