unitree_sdk2_python/example/helloworld/subscriber.py

21 lines
528 B
Python
Raw Normal View History

2024-04-26 21:26:50 +08:00
import time
from unitree_sdk2py.core.channel import ChannelSubscriber, ChannelFactortyInitialize
from user_data import *
if __name__ == "__main__":
ChannelFactortyInitialize()
# Create a subscriber to subscribe the data defined in UserData class
sub = ChannelSubscriber("topic", UserData)
sub.Init()
while True:
msg = sub.Read()
if msg is not None:
print("Subscribe success. msg:", msg)
else:
print("No data subscribed.")
break
sub.Close()