mirror of
https://github.com/westonrobot/ugv_sdk
synced 2023-04-08 06:32:14 +08:00
demo_scout_robot runs
This commit is contained in:
@@ -77,7 +77,7 @@ add_library(${PROJECT_NAME}
|
||||
src/async_port/async_can.cpp
|
||||
########################
|
||||
## public interface to access robot
|
||||
src/mobile_base/scout_robot.cpp
|
||||
src/mobile_robot/scout_robot.cpp
|
||||
########################
|
||||
## protocol v2 support
|
||||
# parser
|
||||
|
||||
@@ -7,72 +7,90 @@
|
||||
* Copyright (c) 2021 Weston Robot Pte. Ltd.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
#include "ugv_sdk/mobile_base/scout_robot.hpp"
|
||||
#include "ugv_sdk/mobile_robot/scout_robot.hpp"
|
||||
|
||||
using namespace westonrobot;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::string protocol_version;
|
||||
std::string device_name;
|
||||
|
||||
if (argc == 2) {
|
||||
device_name = {argv[1]};
|
||||
std::cout << "Specified CAN: " << device_name << std::endl;
|
||||
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_scout_demo <interface>" << std::endl
|
||||
<< "Example 1: ./app_scout_demo can0" << std::endl;
|
||||
std::cout << "Usage: app_scout_demo <protocol-version> <interface>"
|
||||
<< std::endl
|
||||
<< "Example 1: ./app_scout_demo v1 can0" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ScoutRobot scout(ProtocolType::AGX_V2);
|
||||
// scout.Connect(device_name);
|
||||
std::unique_ptr<ScoutRobot> scout;
|
||||
if (protocol_version == "v1") {
|
||||
scout = std::unique_ptr<ScoutRobot>(new ScoutRobot(ProtocolType::AGX_V1));
|
||||
} else if (protocol_version == "v2") {
|
||||
scout = std::unique_ptr<ScoutRobot>(new ScoutRobot(ProtocolType::AGX_V2));
|
||||
} else {
|
||||
std::cout << "Error: invalid protocol version string" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// scout.EnableCommandedMode();
|
||||
if (scout == nullptr)
|
||||
std::cout << "Failed to create robot object" << std::endl;
|
||||
|
||||
// // // 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();
|
||||
scout->Connect(device_name);
|
||||
scout->EnableCommandedMode();
|
||||
|
||||
// int count = 0;
|
||||
// while (true) {
|
||||
// // motion control
|
||||
// if (count < 100) {
|
||||
// std::cout << "Motor: 0.2, 0" << std::endl;
|
||||
// scout.SetMotionCommand(0.2, 0.0);
|
||||
// }
|
||||
// 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();
|
||||
|
||||
// // get robot state
|
||||
// auto state = scout.GetScoutState();
|
||||
// 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;
|
||||
int count = 0;
|
||||
while (true) {
|
||||
// motion control
|
||||
if (count < 100) {
|
||||
std::cout << "Motor: 0.2, 0" << std::endl;
|
||||
scout->SetMotionCommand(0.2, 0.0);
|
||||
}
|
||||
|
||||
// usleep(20000);
|
||||
// ++count;
|
||||
// }
|
||||
// get robot state
|
||||
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;
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
* Copyright (c) 2021 Weston Robot Pte. Ltd.
|
||||
*/
|
||||
|
||||
#include "ugv_sdk/mobile_base/scout_robot.hpp"
|
||||
#include "ugv_sdk/mobile_robot/scout_robot.hpp"
|
||||
#include "ugv_sdk/details/robot_base/scout_base.hpp"
|
||||
|
||||
namespace westonrobot {
|
||||
Reference in New Issue
Block a user