added time stamp to robot states

This commit is contained in:
Ruixiang Du
2021-07-15 15:25:49 +08:00
parent e96b078c05
commit f74ee40fc3
32 changed files with 248 additions and 328 deletions

View File

@@ -4,3 +4,5 @@ add_subdirectory(tracer_demo)
add_subdirectory(ranger_demo)
add_subdirectory(bunker_demo)
add_subdirectory(hunter_demo)
add_subdirectory(utils_demo)

View File

@@ -1,3 +1,2 @@
# tests
add_executable(demo_bunker_robot bunker_robot_demo.cpp)
target_link_libraries(demo_bunker_robot ugv_sdk)

View File

@@ -1,3 +1,2 @@
# tests
add_executable(demo_hunter_robot hunter_robot_demo.cpp)
target_link_libraries(demo_hunter_robot ugv_sdk)

View File

@@ -1,92 +0,0 @@
/*
* demo_hunter_can.cpp
*
* Created on: Jun 12, 2019 05:03
* Description:
*
* Copyright (c) 2019 Ruixiang Du (rdu)
*/
#include "ugv_sdk/hunter_base.hpp"
using namespace westonrobot;
int main(int argc, char **argv)
{
std::string device_name;
int32_t baud_rate = 0;
if (argc == 2)
{
device_name = {argv[1]};
std::cout << "Specified CAN: " << device_name << std::endl;
}
else
{
std::cout << "Usage: app_hunter_demo <interface>" << std::endl
<< "Example 1: ./app_hunter_demo can0" << std::endl;
return -1;
}
HunterBase hunter;
hunter.Connect(device_name);
int count = 0;
while (true)
{
// motion control
if (count < 5)
{
std::cout << "Motor: 0.2, 0.0" << std::endl;
hunter.SetMotionCommand(0.2, 0.0);
}
else if (count < 10)
{
std::cout << "Motor: 0.8, 0.3" << std::endl;
hunter.SetMotionCommand(0.8, 0.3);
}
else if (count < 15)
{
std::cout << "Motor: 1.5, 0.5" << std::endl;
hunter.SetMotionCommand(1.5, 0.5);
}
else if (count < 20)
{
std::cout << "Motor: 1.0, 0.3" << std::endl;
hunter.SetMotionCommand(1.0, 0.3);
}
else if (count < 25)
{
std::cout << "Motor: 0.0, 0.0" << std::endl;
hunter.SetMotionCommand(0.0, 0.0);
}
else if (count < 30)
{
std::cout << "Motor: -0.5, -0.3" << std::endl;
hunter.SetMotionCommand(-0.5, -0.3);
}
else if (count < 35)
{
std::cout << "Motor: -1.0, -0.5" << std::endl;
hunter.SetMotionCommand(-1.0, -0.5);
}
else if (count < 40)
{
std::cout << "Motor: 0.0, 0.0," << std::endl;
hunter.SetMotionCommand(0.0, 0.0);
}
auto state = hunter.GetHunterState();
std::cout << "-------------------------------" << std::endl;
std::cout << "count: " << count << std::endl;
std::cout << "control mode: " << static_cast<int>(state.control_mode) << " , base state: " << static_cast<int>(state.base_state) << std::endl;
std::cout << "battery voltage: " << state.battery_voltage << std::endl;
std::cout << "velocity (linear, angular): " << state.linear_velocity << ", " << state.steering_angle << std::endl;
std::cout << "-------------------------------" << std::endl;
sleep(1);
++count;
}
return 0;
}

View File

@@ -1,2 +1,2 @@
add_executable(demo_ranger_robot ranger_demo.cpp)
add_executable(demo_ranger_robot ranger_robot_demo.cpp)
target_link_libraries(demo_ranger_robot ugv_sdk)

View File

@@ -1,6 +1,2 @@
# tests
add_executable(demo_scout_v2 scout_v2_demo.cpp)
target_link_libraries(demo_scout_v2 ugv_sdk)
add_executable(demo_scout_robot scout_robot_demo.cpp)
target_link_libraries(demo_scout_robot ugv_sdk)

View File

@@ -13,34 +13,38 @@
#include <iostream>
#include "ugv_sdk/mobile_robot/scout_robot.hpp"
#include "ugv_sdk/utilities/protocol_detector.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;
if (argc == 2) {
device_name = {argv[1]};
std::cout << "Selected interface " << device_name << std::endl;
} else {
std::cout << "Usage: app_scout_demo <protocol-version> <interface>"
<< std::endl
<< "Example 1: ./app_scout_demo v1 can0" << std::endl;
<< "Example 1: ./app_scout_demo can0" << std::endl;
return -1;
}
std::unique_ptr<ScoutRobot> scout;
if (protocol_version == "v1") {
ProtocolDectctor detector;
detector.Connect("can0");
auto proto = detector.DetectProtocolVersion(5);
if (proto == ProtocolVersion::AGX_V1) {
std::cout << "Detected protocol: AGX_V1" << std::endl;
scout = std::unique_ptr<ScoutRobot>(
new ScoutRobot(ProtocolVersion::AGX_V1, true));
} else if (protocol_version == "v2") {
} else if (proto == ProtocolVersion::AGX_V2) {
std::cout << "Detected protocol: AGX_V2" << std::endl;
scout = std::unique_ptr<ScoutRobot>(
new ScoutRobot(ProtocolVersion::AGX_V2, true));
} else {
std::cout << "Error: invalid protocol version string" << std::endl;
std::cout << "Detected protocol: UNKONWN" << std::endl;
return -1;
}
@@ -51,9 +55,6 @@ int main(int argc, char **argv) {
if (scout->GetParserProtocolVersion() == ProtocolVersion::AGX_V2) {
scout->EnableCommandedMode();
std::cout << "Protocol version 2" << std::endl;
} else {
std::cout << "Protocol version 1" << std::endl;
}
// light control
@@ -66,11 +67,9 @@ int main(int argc, char **argv) {
std::cout << "Light: breath" << std::endl;
scout->SetLightCommand(BREATH, 0, BREATH, 0);
sleep(3);
std::cout << "Light: custom 30-80" << std::endl;
scout->SetLightCommand(CUSTOM, 30, CUSTOM, 80);
std::cout << "Light: custom 30-40" << std::endl;
scout->SetLightCommand(CUSTOM, 30, CUSTOM, 40);
sleep(3);
// std::cout << "Light: diabled cmd control" << std::endl;
// scout->DisableLightControl();
scout->SetLightCommand(CONST_OFF, 0, CONST_OFF, 0);
int count = 0;
@@ -88,11 +87,17 @@ int main(int argc, char **argv) {
<< " , vehicle state: "
<< static_cast<int>(state.system_state.vehicle_state)
<< " , error code: " << std::hex << state.system_state.error_code
<< std::dec
<< ", 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;
std::cout << "core state age (ms): "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
AgxMsgRefClock::now() - state.time_stamp)
.count()
<< std::endl;
auto actuator = scout->GetActuatorState();
if (scout->GetParserProtocolVersion() == ProtocolVersion::AGX_V1) {
@@ -104,7 +109,25 @@ int main(int argc, char **argv) {
actuator.actuator_state[i].driver_temp,
actuator.actuator_state[i].motor_temp);
}
std::cout << "actuator state age (ms): "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
AgxMsgRefClock::now() - actuator.time_stamp)
.count()
<< std::endl;
} else {
for (int i = 0; i < 4; ++i) {
printf("motor %d: current %f, rpm %d, driver temp %f, motor temp %f\n",
actuator.actuator_hs_state[i].motor_id,
actuator.actuator_hs_state[i].current,
actuator.actuator_hs_state[i].rpm,
actuator.actuator_ls_state[i].driver_temp,
actuator.actuator_ls_state[i].motor_temp);
}
std::cout << "actuator state age (ms): "
<< std::chrono::duration_cast<std::chrono::milliseconds>(
AgxMsgRefClock::now() - actuator.time_stamp)
.count()
<< std::endl;
}
std::cout << "-------------------------------" << std::endl;

View File

@@ -1,75 +0,0 @@
/*
* demo_scout_can.cpp
*
* Created on: Jun 12, 2019 05:03
* Description:
*
* Copyright (c) 2019 Ruixiang Du (rdu)
*/
#include "ugv_sdk/details/robot_base/scout_base.hpp"
using namespace westonrobot;
int main(int argc, char **argv) {
std::string device_name;
if (argc == 2) {
device_name = {argv[1]};
std::cout << "Specified CAN: " << device_name << std::endl;
} else {
std::cout << "Usage: app_scout_demo <interface>" << std::endl
<< "Example 1: ./app_scout_demo can0" << std::endl;
return -1;
}
ScoutBaseV2 scout;
scout.Connect(device_name);
scout.EnableCommandedMode();
// // light control
std::cout << "Light: const off" << std::endl;
scout.SetLightCommand(CONST_OFF, 0, CONST_OFF, 0);
sleep(3);
std::cout << "Light: const on" << std::endl;
scout.SetLightCommand(CONST_ON, 0, CONST_ON, 0);
sleep(3);
std::cout << "Light: breath" << std::endl;
scout.SetLightCommand(BREATH, 0, BREATH, 0);
sleep(3);
std::cout << "Light: custom 90-80" << std::endl;
scout.SetLightCommand(CUSTOM, 90, CUSTOM, 80);
sleep(3);
std::cout << "Light: diabled cmd control" << std::endl;
scout.DisableLightControl();
int count = 0;
while (true) {
// motion control
if (count < 500) {
std::cout << "Motor: 0.2, 0" << std::endl;
scout.SetMotionCommand(0.2, 0.0);
}
auto state = scout.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)
<< std::endl;
std::cout << "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;
std::cout << "-------------------------------" << std::endl;
usleep(20000);
++count;
}
return 0;
}

View File

@@ -1,99 +0,0 @@
/*
* demo_tracer_can.cpp
*
* Created on: Jun 12, 2019 05:03
* Description:
*
* Copyright (c) 2019 Ruixiang Du (rdu)
*/
#include "ugv_sdk/protocol_v2/tracer_base.hpp"
using namespace westonrobot;
int main(int argc, char **argv) {
std::string device_name;
if (argc == 2) {
device_name = {argv[1]};
std::cout << "Specified CAN: " << device_name << std::endl;
} else {
std::cout << "Usage: app_tracer_demo <interface>" << std::endl
<< "Example 1: ./app_tracer_demo can0" << std::endl;
return -1;
}
TracerBaseV2 tracer;
tracer.Connect(device_name);
tracer.EnableCommandedMode();
// tracer.DisableTimeout();
// light control
std::cout << "Light: const off" << std::endl;
tracer.SetLightCommand({CONST_OFF, 0});
// usleep(50000);
sleep(3);
std::cout << "Light: const on" << std::endl;
tracer.SetLightCommand({CONST_ON, 0});
// usleep(50000);
sleep(3);
std::cout << "Light: breath" << std::endl;
tracer.SetLightCommand({BREATH, 0});
// usleep(50000);
sleep(8);
std::cout << "Light: custom 90-80" << std::endl;
tracer.SetLightCommand({CUSTOM, 90});
// usleep(50000);
sleep(3);
std::cout << "Light: diabled cmd control" << std::endl;
tracer.SetLightCommand(TracerLightCmd());
int count = 0;
while (true) {
// motion control
if (count < 5) {
std::cout << "Motor: 0.2, 0.0" << std::endl;
tracer.SetMotionCommand(0.2, 0.0);
} else if (count < 10) {
std::cout << "Motor: 0.8, 0.3" << std::endl;
tracer.SetMotionCommand(0.8, 0.3);
} else if (count < 15) {
std::cout << "Motor: 1.5, 0.5" << std::endl;
tracer.SetMotionCommand(1.5, 0.5);
} else if (count < 20) {
std::cout << "Motor: 1.0, 0.3" << std::endl;
tracer.SetMotionCommand(1.0, 0.3);
} else if (count < 25) {
std::cout << "Motor: 0.0, 0.0" << std::endl;
tracer.SetMotionCommand(0.0, 0.0);
} else if (count < 30) {
std::cout << "Motor: -0.5, -0.3" << std::endl;
tracer.SetMotionCommand(-0.5, -0.3);
} else if (count < 35) {
std::cout << "Motor: -1.0, -0.5" << std::endl;
tracer.SetMotionCommand(-1.0, -0.5);
} else if (count < 40) {
std::cout << "Motor: 0.0, 0.0," << std::endl;
tracer.SetMotionCommand(0.0, 0.0);
}
// tracer.SetMotionCommand(0.8, 0.8);
auto state = tracer.GetTracerState();
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)
<< std::endl;
std::cout << "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;
std::cout << "-------------------------------" << std::endl;
// usleep(20000);
sleep(1);
++count;
}
return 0;
}

View File

@@ -0,0 +1,2 @@
add_executable(demo_protocol_detector demo_protocol_detector.cpp)
target_link_libraries(demo_protocol_detector ugv_sdk)

View File

@@ -0,0 +1,32 @@
/*
* demo_protocol_detect.cpp
*
* Created on: Jul 15, 2021 14:10
* Description:
*
* Copyright (c) 2021 Weston Robot Pte. Ltd.
*/
#include <memory>
#include <iostream>
#include "ugv_sdk/utilities/protocol_detector.hpp"
using namespace westonrobot;
int main(int argc, char **argv) {
ProtocolDectctor detector;
detector.Connect("can0");
auto proto = detector.DetectProtocolVersion(5);
if (proto == ProtocolVersion::AGX_V1) {
std::cout << "Detected protocol: AGX_V1" << std::endl;
} else if (proto == ProtocolVersion::AGX_V2) {
std::cout << "Detected protocol: AGX_V2" << std::endl;
} else {
std::cout << "Detected protocol: UNKONWN" << std::endl;
}
return 0;
}