2024-04-26 21:26:50 +08:00
|
|
|
import time
|
|
|
|
|
2024-05-14 10:18:12 +08:00
|
|
|
from unitree_sdk2py.core.channel import ChannelPublisher, ChannelFactoryInitialize
|
2024-04-26 21:26:50 +08:00
|
|
|
from helloworld import HelloWorld
|
|
|
|
|
2024-05-14 10:18:12 +08:00
|
|
|
ChannelFactoryInitialize()
|
2024-04-26 21:26:50 +08:00
|
|
|
|
|
|
|
pub = ChannelPublisher("topic", HelloWorld)
|
|
|
|
pub.Init()
|
|
|
|
|
|
|
|
for i in range(30):
|
|
|
|
msg = HelloWorld("Hello world. time:" + str(time.time()))
|
|
|
|
# msg.data = "Hello world. time:" + str(time.time())
|
|
|
|
|
|
|
|
if pub.Write(msg, 0.5):
|
|
|
|
print("publish success. msg:", msg)
|
|
|
|
else:
|
|
|
|
print("publish error.")
|
|
|
|
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
pub.Close()
|