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

24 lines
670 B
Python

from pythonosc import dispatcher
from pythonosc import osc_server
def joint_handler(address, *args):
print(f"{address} -> {args[0]}")
def main():
ip = "0.0.0.0" # Listen on all network interfaces
port = 8000 # Must match the sender's port in `joint_state_osc.py`
# Create dispatcher and register callback
disp = dispatcher.Dispatcher()
disp.map("/joint_states/shoulder_lift_joint/*", joint_handler)
server = osc_server.ThreadingOSCUDPServer((ip, port), disp) # Start OSC server
try:
server.serve_forever() # Keep server running
except KeyboardInterrupt:
print("")
if __name__ == "__main__":
main()