Skip to content

Commit 331352d

Browse files
committed
feat: update loco client interface for G1
1 parent 66cc928 commit 331352d

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

example/g1/high_level/g1_loco_client_example.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ int main(int argc, char const *argv[]) {
255255
std::cout << "wave hand with turn" << std::endl;
256256
}
257257

258+
if (arg_pair.first == "set_speed_mode") {
259+
client.SetSpeedMode(std::stoi(arg_pair.second));
260+
std::cout << "set speed mode" << std::endl;
261+
}
262+
258263
std::cout << "Done!" << std::endl;
259264
}
260265

include/unitree/robot/g1/loco/g1_loco_api.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace unitree {
88
namespace robot {
99
namespace g1 {
1010
/*service name*/
11-
const std::string LOCO_SERVICE_NAME = "loco";
11+
const std::string LOCO_SERVICE_NAME = "sport";
1212

1313
/*api version*/
1414
const std::string LOCO_API_VERSION = "1.0.0.0";
@@ -27,6 +27,7 @@ const int32_t ROBOT_API_ID_LOCO_SET_SWING_HEIGHT = 7103;
2727
const int32_t ROBOT_API_ID_LOCO_SET_STAND_HEIGHT = 7104;
2828
const int32_t ROBOT_API_ID_LOCO_SET_VELOCITY = 7105;
2929
const int32_t ROBOT_API_ID_LOCO_SET_ARM_TASK = 7106;
30+
const int32_t ROBOT_API_ID_LOCO_SET_SPEED_MODE = 7107;
3031

3132
using LocoCmd =
3233
std::map<std::string, std::variant<int, float, std::vector<float>>>;

include/unitree/robot/g1/loco/g1_loco_client.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class LocoClient : public Client {
3030
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_LOCO_SET_STAND_HEIGHT);
3131
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_LOCO_SET_VELOCITY);
3232
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_LOCO_SET_ARM_TASK);
33+
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_LOCO_SET_SPEED_MODE);
3334
};
3435

3536
/*Low Level API Call*/
@@ -231,7 +232,17 @@ class LocoClient : public Client {
231232
}
232233
}
233234

234-
private:
235+
int32_t SetSpeedMode(int speed_mode) {
236+
std::string parameter, data;
237+
238+
go2::JsonizeDataInt json;
239+
json.data = speed_mode;
240+
parameter = common::ToJsonString(json);
241+
242+
return Call(ROBOT_API_ID_LOCO_SET_SPEED_MODE, parameter, data);
243+
}
244+
245+
private:
235246
bool continous_move_ = false;
236247
bool first_shake_hand_stage_ = true;
237248
};

0 commit comments

Comments
 (0)