thecountoftuscany / PyTeapot-Quaternion-Euler-cube-rotation

Visualization of IMU orientation from quaternion or Euler angles with a rotating cube
GNU General Public License v3.0
145 stars 42 forks source link

[TODO] Read data from file for visualisation #9

Open sandeepnmenon opened 2 years ago

sandeepnmenon commented 2 years ago

Raising issue as per TODO.

Would like to submit PR for the same

sandeepnmenon commented 2 years ago

Raised PR #10 Please review.

thecountoftuscany commented 2 years ago

Hi sorry quite busy right now. Might review over the weekend.

AsternA commented 2 years ago

if your file is csv then just read the file using pandas, construct the message yourself and send it over UDP.

That's what I am doing right now and it does the trick

example:

df_csv = pd.read_csv(PATH_CSV)
time = df_csv['loggingTime(txt)']

quat_w = df_csv['motionQuaternionW(R)']
quat_x = df_csv['motionQuaternionX(R)']
quat_y = df_csv['motionQuaternionY(R)']
quat_z = df_csv['motionQuaternionZ(R)']

yaw = df_csv['motionYaw(rad)']
pitch = df_csv['motionPitch(rad)']
roll = df_csv['motionRoll(rad)']

UDP_IP = "0.0.0.0"
UDP_PORT = 5005
START_indx = 9350
END_indx = 10000
MESSAGE = 'w' + str(quat_w[1]) + 'wa' + str(quat_x[1]) + 'ab' + str(quat_y[1]) + 'bc' + str(quat_z[1]) + 'c'

print("UDP target IP:", UDP_IP)
print("UDP target port:", UDP_PORT)
print("message:", MESSAGE)
print(f"Time {time[1]}")

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
i = START_indx
# while True:
while i < END_indx:
    MESSAGE = 'w' + str(quat_w[i]) + 'wa' + str(quat_x[i]) + 'ab' + str(quat_y[i]) + 'bc' + str(quat_z[i]) + 'c'
    sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, UDP_PORT))
    print(f"Time: {time[i]}, i: {i}")
    i += 1
    input()

note: I use "input()" so the code runs when I want it so I can go over line by line