fracture_robot_interface.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #define BOOST_TEST_DYN_LINK
  2. #include "core/basic_obj_types.hpp"
  3. #include "core/global_defs.h"
  4. #include "core/sophiar_pool.h"
  5. #include "utility/debug_utility.hpp"
  6. #include "utility/variable_helper.hpp"
  7. #include <boost/asio/co_spawn.hpp>
  8. #include <boost/asio/detached.hpp>
  9. #include <boost/test/unit_test.hpp>
  10. #include <spdlog/spdlog.h>
  11. #include <fstream>
  12. #include <numbers>
  13. using namespace sophiar;
  14. using namespace std::chrono_literals;
  15. using boost::asio::co_spawn;
  16. using boost::asio::awaitable;
  17. using boost::asio::detached;
  18. awaitable<void> test_fracture_robot_direct_control() {
  19. auto move_index = REQUIRE_VARIABLE(bool_obj, "robot_is_moving");
  20. auto target_index = REQUIRE_VARIABLE(array6_obj, "motor_velocity");
  21. co_await coro_wait_for_not_empty<bool_obj>(move_index);
  22. BOOST_TEST(QUERY_VARIABLE(bool_obj, move_index)->value == false);
  23. for (int i = 0; i < 100; ++i) {
  24. auto motor_speed = array6_obj::new_instance();
  25. motor_speed->value.fill(5);
  26. UPDATE_VARIABLE(array6_obj, target_index, motor_speed);
  27. co_await coro_sleep(20ms);
  28. }
  29. co_return;
  30. }
  31. BOOST_AUTO_TEST_CASE(test_fracture_robot_interface) {
  32. spdlog::set_level(spdlog::level::trace);
  33. std::ifstream config_file("data/fracture_robot_interface_config.json");
  34. BOOST_TEST(config_file.is_open());
  35. auto config = nlohmann::json::parse(config_file);
  36. BOOST_TEST(initialize(config));
  37. co_spawn(*global_context, test_fracture_robot_direct_control(), detached);
  38. global_context->run();
  39. }