mirror of
https://github.com/westonrobot/ugv_sdk
synced 2023-04-08 06:32:14 +08:00
added hunter support
This commit is contained in:
@@ -3,12 +3,4 @@ add_subdirectory(scout_demo)
|
||||
add_subdirectory(tracer_demo)
|
||||
add_subdirectory(ranger_demo)
|
||||
add_subdirectory(bunker_demo)
|
||||
|
||||
# add_executable(app_hunter_demo hunter_demo/hunter_demo.cpp)
|
||||
# target_link_libraries(app_hunter_demo ugv_sdk)
|
||||
|
||||
# add_executable(app_tracer_demo tracer_demo/tracer_demo.cpp)
|
||||
# target_link_libraries(app_tracer_demo ugv_sdk)
|
||||
|
||||
# add_executable(app_ranger_demo ranger_demo/ranger_demo.cpp)
|
||||
# target_link_libraries(app_ranger_demo ugv_sdk)
|
||||
add_subdirectory(hunter_demo)
|
||||
|
||||
3
demo/hunter_demo/CMakeLists.txt
Executable file
3
demo/hunter_demo/CMakeLists.txt
Executable file
@@ -0,0 +1,3 @@
|
||||
# tests
|
||||
add_executable(demo_hunter_robot hunter_robot_demo.cpp)
|
||||
target_link_libraries(demo_hunter_robot ugv_sdk)
|
||||
99
demo/hunter_demo/hunter_robot_demo.cpp
Normal file
99
demo/hunter_demo/hunter_robot_demo.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* hunter_robot_demo.cpp
|
||||
*
|
||||
* Created on: Jul 08, 2021 11:12
|
||||
* Description:
|
||||
*
|
||||
* Copyright (c) 2021 Weston Robot Pte. Ltd.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
#include "ugv_sdk/mobile_robot/hunter_robot.hpp"
|
||||
|
||||
using namespace westonrobot;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::string protocol_version;
|
||||
std::string device_name;
|
||||
|
||||
if (argc == 3) {
|
||||
protocol_version = {argv[1]};
|
||||
device_name = {argv[2]};
|
||||
std::cout << "Use protocol " << protocol_version << " on interface "
|
||||
<< device_name << std::endl;
|
||||
} else {
|
||||
std::cout << "Usage: app_hunter_demo <protocol-version> <interface>"
|
||||
<< std::endl
|
||||
<< "Example 1: ./app_hunter_demo v1 can0" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::unique_ptr<HunterRobot> hunter;
|
||||
if (protocol_version == "v1") {
|
||||
hunter =
|
||||
std::unique_ptr<HunterRobot>(new HunterRobot(ProtocolVersion::AGX_V1));
|
||||
} else if (protocol_version == "v2") {
|
||||
hunter =
|
||||
std::unique_ptr<HunterRobot>(new HunterRobot(ProtocolVersion::AGX_V2));
|
||||
} else {
|
||||
std::cout << "Error: invalid protocol version string" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (hunter == nullptr)
|
||||
std::cout << "Failed to create robot object" << std::endl;
|
||||
|
||||
hunter->Connect(device_name);
|
||||
|
||||
if (hunter->GetProtocolVersion() == ProtocolVersion::AGX_V2) {
|
||||
hunter->EnableCommandedMode();
|
||||
std::cout << "Protocol version 2" << std::endl;
|
||||
} else {
|
||||
std::cout << "Protocol version 1" << std::endl;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
while (true) {
|
||||
// motion control
|
||||
std::cout << "Motor: 1.0, 0" << std::endl;
|
||||
hunter->SetMotionCommand(1.0, 0.0);
|
||||
|
||||
// get robot state
|
||||
auto state = hunter->GetRobotState();
|
||||
std::cout << "-------------------------------" << std::endl;
|
||||
std::cout << "count: " << count << std::endl;
|
||||
std::cout << "control mode: "
|
||||
<< static_cast<int>(state.system_state.control_mode)
|
||||
<< " , vehicle state: "
|
||||
<< static_cast<int>(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;
|
||||
|
||||
auto actuator = hunter->GetActuatorState();
|
||||
if (hunter->GetProtocolVersion() == ProtocolVersion::AGX_V1) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
printf("motor %d: current %f, rpm %d, driver temp %f, motor temp %f\n",
|
||||
actuator.actuator_state[i].motor_id,
|
||||
actuator.actuator_state[i].current,
|
||||
actuator.actuator_state[i].rpm,
|
||||
actuator.actuator_state[i].driver_temp,
|
||||
actuator.actuator_state[i].motor_temp);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
std::cout << "-------------------------------" << std::endl;
|
||||
|
||||
usleep(20000);
|
||||
++count;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user