36 lines
1011 B
Python
36 lines
1011 B
Python
from osc4py3.as_eventloop import *
|
|
from osc4py3 import oscmethod as osm
|
|
import csv
|
|
import time
|
|
|
|
# CSV setup
|
|
csv_file = './pose_log.csv'
|
|
|
|
with open(csv_file, 'w', newline='') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow(["timestamp", "x", "y", "z", "roll", "pitch", "yaw"])
|
|
|
|
# OSC handler
|
|
def pose_handler(timestamp, x, y, z, roll, pitch, yaw):
|
|
print(f"[{timestamp:.6f}] Received: x={x}, y={y}, z={z}, roll={roll}, pitch={pitch}, yaw={yaw}")
|
|
with open(csv_file, 'a', newline='') as f:
|
|
writer = csv.writer(f)
|
|
writer.writerow([timestamp, x, y, z, roll, pitch, yaw])
|
|
|
|
# Setup
|
|
osc_startup()
|
|
osc_udp_server("0.0.0.0", 8000, "pose_server")
|
|
|
|
# Register OSC method (with timestamp argument)
|
|
osc_method("/tcp_coordinates", pose_handler, argscheme=osm.OSCARG_READTIME+ osm.OSCARG_DATAUNPACK)
|
|
|
|
print("Listening for OSC messages on port 8000...")
|
|
|
|
try:
|
|
while True:
|
|
osc_process()
|
|
time.sleep(0.01)
|
|
except KeyboardInterrupt:
|
|
print("Shutting down...")
|
|
osc_terminate()
|