#include <chrono>
#include <cstdio>
#include <iostream>
#include <thread>
{
try
{
#ifdef NODELETS_TEST_VERBOSE
printf("[publisher] Started\n");
#endif
for (int i = 0; i < 5; i++)
{
std::this_thread::sleep_for(100ms);
dir->getTopic(
"/robot/odom")->publish(
p_tx);
}
#ifdef NODELETS_TEST_VERBOSE
printf("[publisher] Finish\n");
#endif
}
catch (const std::exception& e)
{
cerr << e.what() << endl;
}
catch (...)
{
printf("[thread_publisher] Runtime error!\n");
}
}
{
#ifdef NODELETS_TEST_VERBOSE
std::cout <<
"sub2: rx TPose3D" << p.
asString() << std::endl;
#endif
}
{
#ifdef NODELETS_TEST_VERBOSE
std::cout <<
"onNewMsg2: idx=" << idx <<
" rx TPose3D" << p.
asString()
<< std::endl;
#endif
}
{
try
{
#ifdef NODELETS_TEST_VERBOSE
printf("[subscriber] Connecting\n");
#endif
#ifdef NODELETS_TEST_VERBOSE
printf("[subscriber] Connected. Waiting for a message...\n");
#endif
dir->getTopic(
"/robot/odom")
#ifdef NODELETS_TEST_VERBOSE
std::cout << "sub1: rx TPose3D" << p_rx.asString()
<< std::endl;
#endif
});
auto sub2 =
dir->getTopic(
"/robot/odom")
std::function<void(const mrpt::math::TPose3D&)>(&
onNewMsg));
auto sub3 =
dir->getTopic(
"/robot/odom")
using namespace std::placeholders;
auto sub4 =
dir->getTopic(
"/robot/odom")
[](
auto&& arg1) {
return onNewMsg2(123, arg1); });
std::this_thread::sleep_for(1000ms);
#ifdef NODELETS_TEST_VERBOSE
printf("[subscriber] Finish\n");
#endif
}
catch (const std::exception& e)
{
cerr << e.what() << endl;
}
catch (...)
{
cerr << "[thread_subscriber] Runtime error!" << endl;
}
}
{
using namespace std::chrono_literals;
std::this_thread::sleep_for(1000ms);
}