ndi.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #define BOOST_TEST_DYN_LINK
  2. #define BOOST_TEST_MAIN // in only one cpp file
  3. #include "tracker/ndi/ndi_interface.h"
  4. #include "utility/variable_helper.hpp"
  5. #include "core/basic_obj_types.hpp"
  6. #include <boost/asio/co_spawn.hpp>
  7. #include <boost/asio/detached.hpp>
  8. #include <boost/asio/this_coro.hpp>
  9. #include <boost/asio/use_awaitable.hpp>
  10. #include <boost/test/unit_test.hpp>
  11. #include <chrono>
  12. #include <iostream>
  13. #include <vector>
  14. using boost::asio::awaitable;
  15. using boost::asio::co_spawn;
  16. using boost::asio::detached;
  17. using boost::asio::use_awaitable;
  18. using namespace sophiar;
  19. using namespace std::chrono_literals;
  20. awaitable<void> coro_ndi_test() {
  21. auto interface = std::make_unique<ndi_interface>();
  22. auto init_config = nlohmann::json::parse(
  23. R"({"address_type":"ethernet","ip":"169.254.132.51","tcp_port":8765,"com_port":"COM3","tool_list":[{"rom_path":"D:\\Program\\Robot\\Tools\\roms\\Probe_Small_4Ball.rom","outputs":{"transform":"tracker_probe_transform","marker_uncertainty":"tracker_probe_transform_uncertainty"}},{"rom_path":"D:\\Program\\Robot\\Tools\\roms\\Head_3Ball_2.rom","outputs":{"transform":"tracker_model_ref_transform","marker_uncertainty":"tracker_model_ref_transform_uncertainty"}}]})");
  24. auto start_config = nlohmann::json::parse(
  25. R"({"allow_unreliable":true,"prefer_stream_tracking":true})");
  26. BOOST_TEST(co_await interface->init(init_config));
  27. BOOST_TEST(co_await interface->start(start_config));
  28. auto trans_obj = global_obj_auto_sync_delegate<transform_obj>(
  29. global_sophiar_manager,
  30. "tracker_probe_transform");
  31. int cnt = 0;
  32. FILE_LINE_TRACE
  33. for (;;) {
  34. co_await trans_obj.coro_wait_update();
  35. // if (!trans_obj.empty()) {
  36. // std::cout << trans_obj->value.matrix() << std::endl;
  37. // } else {
  38. // std::cout << "empty" << std::endl;
  39. // }
  40. if (++cnt == 250) break;
  41. }
  42. FILE_LINE_TRACE
  43. co_await interface->reset();
  44. start_config = nlohmann::json::parse(
  45. R"({"allow_unreliable":true,"prefer_stream_tracking":false})");
  46. BOOST_TEST(co_await interface->init(init_config));
  47. BOOST_TEST(co_await interface->start(start_config));
  48. cnt = 0;
  49. FILE_LINE_TRACE
  50. for (;;) {
  51. co_await trans_obj.coro_wait_update();
  52. if (++cnt == 60) break;
  53. }
  54. FILE_LINE_TRACE
  55. co_await interface->reset();
  56. co_return;
  57. }
  58. BOOST_AUTO_TEST_CASE(test_ndi) {
  59. co_spawn(global_context, coro_ndi_test(), detached);
  60. global_context.run();
  61. }