From c51f80753d707ac4f3c7160a9ed554f4e194ff3d Mon Sep 17 00:00:00 2001 From: xiaoliangstd <2303335747@qq.com> Date: Mon, 28 Oct 2024 13:02:40 +0800 Subject: [PATCH] update b2w examples --- example/b2w/b2w_sport_client.cpp | 39 +++++++++++++++++++------------ example/b2w/b2w_stand_example.cpp | 2 +- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/example/b2w/b2w_sport_client.cpp b/example/b2w/b2w_sport_client.cpp index b25f114..7e306ae 100644 --- a/example/b2w/b2w_sport_client.cpp +++ b/example/b2w/b2w_sport_client.cpp @@ -6,10 +6,6 @@ #include #include #include -#include -#include - -#define TOPIC_HIGHSTATE "rt/lf/sportmodestate" using namespace std; @@ -23,12 +19,13 @@ const vector option_list = {{"damp", 0}, {"stand_up", 1}, {"stand_down", 2}, - {"move", 3}, - {"stop_move", 4}, - {"switch_gait", 5}, - {"switch_gait", 6}, - {"get_state", 6}, - {"recovery", 7}, + {"move forward", 3}, + {"move lateral", 4}, + {"move rotate", 5}, + {"stop_move", 6}, + {"switch_gait", 7}, + {"switch_gait", 8}, + {"recovery", 9}, }; int ConvertToInt(const std::string &str) @@ -94,7 +91,7 @@ int main(int argc, char **argv) test_option.id = 1; unitree::robot::b2::SportClient sport_client; - sport_client.SetTimeout(10.0f); + sport_client.SetTimeout(25.0f); sport_client.Init(); UserInterface user_interface; @@ -124,23 +121,35 @@ int main(int argc, char **argv) } else if (test_option.id == 3) { - res = sport_client.Move(0.2, 0, 0);// the robot will move for 0.5 seconds before stopping. + res = sport_client.Move(0.3, 0, 0);// the robot will move for 0.5 seconds before stopping. // If the Move command is called in a loop, the robot will continue moving. // If no Move request is received within 0.5 seconds, the robot will automatically stop. } else if (test_option.id == 4) { - res = sport_client.StopMove(); + res = sport_client.Move(0, 0.3, 0);// the robot will move for 0.5 seconds before stopping. + // If the Move command is called in a loop, the robot will continue moving. + // If no Move request is received within 0.5 seconds, the robot will automatically stop. } else if (test_option.id == 5) { - res = sport_client.SwitchGait(0); + res = sport_client.Move(0, 0, 0.5);// the robot will move for 0.5 seconds before stopping. + // If the Move command is called in a loop, the robot will continue moving. + // If no Move request is received within 0.5 seconds, the robot will automatically stop. } else if (test_option.id == 6) { - res = sport_client.SwitchGait(1); + res = sport_client.StopMove(); } else if (test_option.id == 7) + { + res = sport_client.SwitchGait(0); + } + else if (test_option.id == 8) + { + res = sport_client.SwitchGait(1); + } + else if (test_option.id == 9) { res = sport_client.RecoveryStand(); } diff --git a/example/b2w/b2w_stand_example.cpp b/example/b2w/b2w_stand_example.cpp index 8e0f257..381b037 100644 --- a/example/b2w/b2w_stand_example.cpp +++ b/example/b2w/b2w_stand_example.cpp @@ -353,7 +353,7 @@ int main(int argc, const char** argv) exit(-1); } - std::cout << "WARNING: Make sure the robot is hung up or lying on the ground." << std::endl + std::cout << "WARNING: Make sure the robot is lying on the ground." << std::endl << "Press Enter to continue..." << std::endl; std::cin.ignore();