From 48d4337ed040cdd7179853645ada56f4a2bac454 Mon Sep 17 00:00:00 2001 From: raiot Date: Fri, 8 Nov 2024 14:26:27 +0800 Subject: [PATCH] feat: normalize plot to angle --- utils/plot_servo.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils/plot_servo.py b/utils/plot_servo.py index 72bfc0f..67a183d 100644 --- a/utils/plot_servo.py +++ b/utils/plot_servo.py @@ -15,6 +15,10 @@ def plot_servo_data(csv_file): print(f"Error reading CSV file: {e}") sys.exit(1) + # Preprocess data: subtract 500 and multiply by 0.5 + for servo in ['Servo 1', 'Servo 2', 'Servo 3']: + df[servo] = (df[servo] - 500) * 0.25 + # Set plot style sns.set_style("whitegrid") plt.figure(figsize=(12, 6)) @@ -25,9 +29,9 @@ def plot_servo_data(csv_file): sns.lineplot(data=df, x='Step', y='Servo 3', label='Servo 3') # Set title and labels - plt.title('Servo Angles vs Time') + plt.title('Servo Angles vs Time (Normalized)') plt.xlabel('Time (seconds)') - plt.ylabel('Angle') + plt.ylabel('Angle (degrees)') # Add legend plt.legend(title='Servo ID') @@ -36,7 +40,7 @@ def plot_servo_data(csv_file): plt.tight_layout() # Generate output filename based on input - output_file = csv_file.rsplit('.', 1)[0] + '_plot.png' + output_file = csv_file.rsplit('.', 1)[0] + '_normalized_plot.png' # Save plot plt.savefig(output_file, dpi=300, bbox_inches='tight')