OSC_ROS2/ros_osc/joint_info/pythonosc/bundles/different_lib.py
Alexander Schaefer 98759f2bab AS: osc4py3
2025-03-14 09:37:10 +01:00

38 lines
1.0 KiB
Python

# Import needed modules from osc4py3
import osc4py3.as_eventloop
from osc4py3 import oscmethod as osm
def handlerfunction(*args):
for arg in args:
print(arg)
pass
"""
def handlerfunction2(address, s, x, y):
# Will receive message address, and message data flattened in s, x, y
print(f's: {s}')
print(f'x: {x}')
print(f'y: {y}')
pass
"""
# Start the system.
osc_startup()
# Make server channels to receive packets.
osc_udp_server("0.0.0.0", 5005, "aservername")
osc_udp_server("0.0.0.0", 5005, "anotherserver")
# Associate Python functions with message address patterns, using default
# argument scheme OSCARG_DATAUNPACK.
osc_method("SYNC", handlerfunction)
# Too, but request the message address pattern before in argscheme
#osc_method("SYNC", handlerfunction2, argscheme=osm.OSCARG_ADDRESS + osm.OSCARG_DATAUNPACK)
# Periodically call osc4py3 processing method in your event loop.
finished = False
while not finished:
# …
osc_process()
# …
# Properly close the system.
osc_terminate()