FIX&ENH: rotary driver works!
ADD: three pins for current strength values FIX: ADC1->ADC2 ENH: prepare for UART FIX&ADD: add USART print, add extra_script to print floats to COM port #2 ADD: some func #2 Rebuild project structure ADD: .clang-format file ENG: use flag ADD: USART1 FIX: .ioc FIX: .ioc ADD: debug script to angle value ADD: gitlab-ci ADD: gitlab CI ADD: gitlab-ci FIX: gitlab-ci ADD&FIX: all sensors work! (or not?)
This commit is contained in:
parent
d1b0ed0858
commit
8157b41ea9
23 changed files with 673 additions and 339 deletions
48
vizualize.py
Normal file
48
vizualize.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import serial
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.animation as animation
|
||||
import numpy as np
|
||||
|
||||
# Open the serial port. Replace 'COM3' with your serial port name.
|
||||
serial_port = '/dev/ttyUSB0'
|
||||
baud_rate = 115200 # Adjust as per your device configuration
|
||||
ser = serial.Serial(serial_port, baud_rate, timeout=1)
|
||||
|
||||
# Setup the matplotlib figure and axes for polar plot.
|
||||
fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})
|
||||
line, = ax.plot([], [], 'b-', lw=2) # Line object to update the angle
|
||||
ax.set_ylim(0, 1) # Set the radius range (fixed in this case)
|
||||
|
||||
# Adjust the orientation so that 0 is up and the angle proceeds clockwise.
|
||||
ax.set_theta_zero_location('N')
|
||||
ax.set_theta_direction(-1)
|
||||
|
||||
# Initialization function to clear the data.
|
||||
def init():
|
||||
line.set_data([], [])
|
||||
return (line,)
|
||||
|
||||
# Update function that reads from the serial port
|
||||
# and updates the plot with the new angle.
|
||||
def update(frame):
|
||||
line.set_data([], [])
|
||||
raw_data = ser.readline().strip()
|
||||
angle = 0
|
||||
if raw_data:
|
||||
try:
|
||||
angle = float(raw_data)
|
||||
except:
|
||||
angle = 0
|
||||
angle_rad = np.deg2rad(angle) # Convert to radians
|
||||
# Update the plot with the new angle.
|
||||
line.set_data([angle_rad, angle_rad], [0, 1])
|
||||
return (line,)
|
||||
|
||||
# Create the animation object with a suitable update interval (ms).
|
||||
ani = animation.FuncAnimation(fig, update, init_func=init, blit=True, interval=1)
|
||||
|
||||
# Start the plot animation
|
||||
plt.show()
|
||||
|
||||
# Closing the serial port after the plot is closed.
|
||||
ser.close()
|
Loading…
Add table
Add a link
Reference in a new issue