Skip to content

Commit 9e686cd

Browse files
committed
add g1 arm action api
1 parent 50fd418 commit 9e686cd

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <unitree/common/json/jsonize.hpp>
4+
#include <variant>
5+
6+
namespace unitree {
7+
namespace robot {
8+
namespace g1 {
9+
/*service name*/
10+
const std::string ARM_ACTION_SERVICE_NAME = "arm";
11+
12+
/*api version*/
13+
const std::string ARM_ACTION_API_VERSION = "1.0.0.14";
14+
15+
/*api id*/
16+
const int32_t ROBOT_API_ID_ARM_ACTION_EXECUTE_ACTION = 7106;
17+
18+
class JsonizeArmActionCommand : public common::Jsonize {
19+
public:
20+
JsonizeArmActionCommand() {}
21+
~JsonizeArmActionCommand() {}
22+
23+
void fromJson(common::JsonMap &json) {
24+
common::FromJson(json["data"], action_id);
25+
}
26+
27+
void toJson(common::JsonMap &json) const {
28+
common::ToJson(action_id, json["data"]);
29+
}
30+
31+
int32_t action_id;
32+
};
33+
34+
} // namespace g1
35+
} // namespace robot
36+
} // namespace unitree
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#pragma once
2+
3+
#include <unitree/robot/client/client.hpp>
4+
#include <unitree/robot/go2/public/jsonize_type.hpp>
5+
#include "g1_arm_action_api.hpp"
6+
7+
namespace unitree {
8+
namespace robot {
9+
namespace g1 {
10+
11+
/**
12+
* @brief Arm action client
13+
*
14+
* The arm action server provides some upper body actions.
15+
* The controller is based on the `rt/arm_sdk` interface.
16+
*/
17+
class G1ArmActionClient : public Client {
18+
public:
19+
G1ArmActionClient() : Client(ARM_ACTION_SERVICE_NAME, false) {}
20+
~G1ArmActionClient() {}
21+
22+
/*Init*/
23+
void Init() {
24+
SetApiVersion(ARM_ACTION_API_VERSION);
25+
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_ARM_ACTION_EXECUTE_ACTION);
26+
}
27+
28+
/*API Call*/
29+
int32_t ExecuteAction(int32_t action_id) {
30+
std::string parameter, data;
31+
JsonizeArmActionCommand json;
32+
33+
json.action_id = action_id;
34+
parameter = common::ToJsonString(json);
35+
36+
return Call(ROBOT_API_ID_ARM_ACTION_EXECUTE_ACTION, parameter, data);
37+
}
38+
39+
/*Action List*/
40+
std::map<std::string, int32_t> action_map = {
41+
{"release arm", 99},
42+
{"two-hand kiss", 11},
43+
{"left kiss", 12},
44+
{"right kiss", 12},
45+
{"hands up", 15},
46+
{"clap", 17},
47+
{"high five", 18},
48+
{"hug", 19},
49+
{"heart", 20},
50+
{"right heart", 21},
51+
{"reject", 22},
52+
{"right hand up", 23},
53+
{"x-ray", 24},
54+
{"face wave", 25},
55+
{"high wave", 26},
56+
{"shake hand", 27},
57+
};
58+
};
59+
60+
61+
} // namespace g1
62+
} // namespace robot
63+
} // namespace unitree
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <unitree/common/decl.hpp>
4+
5+
namespace unitree {
6+
namespace robot {
7+
namespace g1 {
8+
9+
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_ARMSDK, 7400, "armsdk is occupied.")
10+
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_HOLDING, 7401, "The arm is holding. Only release is allowed.")
11+
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_INVALID_ACTION_ID, 7402, "Invalid action id.")
12+
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_INVALID_FSM_ID, 7404, "Invalid fsm id.")
13+
14+
} // namespace g1
15+
} // namespace robot
16+
} // namespace unitree

0 commit comments

Comments
 (0)