初始化项目,包含fast_lio_ws和unitree_sdk2
This commit is contained in:
45
unitree_sdk2/example/helloworld/subscriber.cpp
Normal file
45
unitree_sdk2/example/helloworld/subscriber.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <unitree/robot/channel/channel_subscriber.hpp>
|
||||
#include <unitree/common/time/time_tool.hpp>
|
||||
#include "HelloWorldData.hpp"
|
||||
|
||||
#define TOPIC "TopicHelloWorld"
|
||||
|
||||
using namespace unitree::robot;
|
||||
using namespace unitree::common;
|
||||
|
||||
void Handler(const void* msg)
|
||||
{
|
||||
const HelloWorldData::Msg* pm = (const HelloWorldData::Msg*)msg;
|
||||
|
||||
std::cout << "userID:" << pm->userID() << ", message:" << pm->message() << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ChannelFactory::Instance()->Init(0);
|
||||
ChannelSubscriber<HelloWorldData::Msg> subscriber(TOPIC);
|
||||
subscriber.InitChannel(Handler);
|
||||
|
||||
sleep(5);
|
||||
subscriber.CloseChannel();
|
||||
|
||||
std::cout << "reseted. sleep 3" << std::endl;
|
||||
|
||||
sleep(3);
|
||||
subscriber.InitChannel();
|
||||
|
||||
sleep(5);
|
||||
subscriber.CloseChannel();
|
||||
|
||||
std::cout << "reseted. sleep 3" << std::endl;
|
||||
|
||||
sleep(3);
|
||||
subscriber.InitChannel();
|
||||
|
||||
while (true)
|
||||
{
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user