From 0462c9e5c017c76c4bda1f9f276ebfb031fbdd68 Mon Sep 17 00:00:00 2001 From: "pinloon.lee" Date: Tue, 13 Jul 2021 22:25:32 +0800 Subject: [PATCH] add tracer demo --- demo/CMakeLists.txt | 2 +- demo/tracer_demo/CMakeLists.txt | 2 + demo/tracer_demo/tracer_robot_demo.cpp | 88 ++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 demo/tracer_demo/CMakeLists.txt create mode 100644 demo/tracer_demo/tracer_robot_demo.cpp diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt index 6756879..7c6a3f4 100755 --- a/demo/CMakeLists.txt +++ b/demo/CMakeLists.txt @@ -1,6 +1,6 @@ # demo add_subdirectory(scout_demo) - +add_subdirectory(tracer_demo) # add_executable(app_hunter_demo hunter_demo/hunter_demo.cpp) # target_link_libraries(app_hunter_demo ugv_sdk) diff --git a/demo/tracer_demo/CMakeLists.txt b/demo/tracer_demo/CMakeLists.txt new file mode 100644 index 0000000..d037a3e --- /dev/null +++ b/demo/tracer_demo/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(demo_tracer_robot tracer_robot_demo.cpp) +target_link_libraries(demo_tracer_robot ugv_sdk) \ No newline at end of file diff --git a/demo/tracer_demo/tracer_robot_demo.cpp b/demo/tracer_demo/tracer_robot_demo.cpp new file mode 100644 index 0000000..e044725 --- /dev/null +++ b/demo/tracer_demo/tracer_robot_demo.cpp @@ -0,0 +1,88 @@ +/* + * scout_robot_demo.cpp + * + * Created on: Jul 13, 2021 22:22 + * Description: + * + * Copyright (c) 2021 Weston Robot Pte. Ltd. + */ + +#include + +#include +#include + +#include "ugv_sdk/mobile_robot/tracer_robot.hpp" + +using namespace westonrobot; + +int main(int argc, char **argv) { + std::string device_name; + + if (argc == 2) { + device_name = {argv[1]}; + std::cout << "Using interface " + << device_name << std::endl; + } else { + std::cout << "Usage: app_tracer_demo " + << std::endl + << "Example 1: ./app_tracer_demo can0" << std::endl; + return -1; + } + + std::unique_ptr tracer; + tracer = std::unique_ptr(new TracerRobot()); + if (tracer == nullptr) + std::cout << "Failed to create robot object" << std::endl; + + tracer->Connect(device_name); + tracer->EnableCommandedMode(); + + // light control + std::cout << "Light: const off" << std::endl; + tracer->SetLightCommand(CONST_OFF, 0); + sleep(3); + std::cout << "Light: const on" << std::endl; + tracer->SetLightCommand(CONST_ON, 0); + sleep(3); + std::cout << "Light: breath" << std::endl; + tracer->SetLightCommand(BREATH, 0); + sleep(3); + std::cout << "Light: custom 30-80" << std::endl; + tracer->SetLightCommand(CUSTOM, 30); + sleep(3); + // std::cout << "Light: diabled cmd control" << std::endl; + // scout->DisableLightControl(); + tracer->SetLightCommand(CONST_OFF, 0); + + int count = 0; + while (true) { + // motion control + std::cout << "Motor: 1.0, 0" << std::endl; + tracer->SetMotionCommand(1.0, 0.0); + + // get robot state + auto state = tracer->GetRobotState(); + std::cout << "-------------------------------" << std::endl; + std::cout << "count: " << count << std::endl; + std::cout << "control mode: " + << static_cast(state.system_state.control_mode) + << " , vehicle state: " + << static_cast(state.system_state.vehicle_state) + << " , error code: " << std::hex << state.system_state.error_code + << ", battery voltage: " << state.system_state.battery_voltage + << std::endl; + std::cout << "velocity (linear, angular): " + << state.motion_state.linear_velocity << ", " + << state.motion_state.angular_velocity << std::endl; + + for (int i = 0; i < 2; ++i) { + } + std::cout << "-------------------------------" << std::endl; + + usleep(20000); + ++count; + } + + return 0; +} \ No newline at end of file