feat: 初始化 Go2 导航相关代码与配置
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <unitree/common/json/jsonize.hpp>
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace h2 {
|
||||
|
||||
const std::string ARM_ACTION_SERVICE_NAME = "arm";
|
||||
const std::string ARM_ACTION_API_VERSION = "1.0.0.14";
|
||||
|
||||
const int32_t ROBOT_API_ID_ARM_ACTION_EXECUTE_ACTION = 7106;
|
||||
const int32_t ROBOT_API_ID_ARM_ACTION_GET_ACTION_LIST = 7107;
|
||||
const int32_t ROBOT_API_ID_ARM_ACTION_EXECUTE_CUSTOM_ACTION = 7108;
|
||||
const int32_t ROBOT_API_ID_ARM_ACTION_STOP_CUSTOM_ACTION = 7113;
|
||||
|
||||
class JsonizeArmActionCommand : public common::Jsonize {
|
||||
public:
|
||||
void fromJson(common::JsonMap& json) override {
|
||||
common::FromJson(json["action_id"], action_id);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const override {
|
||||
common::ToJson(action_id, json["action_id"]);
|
||||
}
|
||||
|
||||
int32_t action_id = 0;
|
||||
};
|
||||
|
||||
class JsonizeArmActionName : public common::Jsonize {
|
||||
public:
|
||||
void fromJson(common::JsonMap& json) override {
|
||||
common::FromJson(json["action_name"], action_name);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap& json) const override {
|
||||
common::ToJson(action_name, json["action_name"]);
|
||||
}
|
||||
|
||||
std::string action_name;
|
||||
};
|
||||
|
||||
} // namespace h2
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
||||
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <unitree/robot/client/client.hpp>
|
||||
|
||||
#include "h2_arm_action_api.hpp"
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace h2 {
|
||||
|
||||
/**
|
||||
* @brief Client for requesting preset H2 upper-body actions.
|
||||
*
|
||||
* The matching robot-side "arm" service generates the trajectory and sends it
|
||||
* through rt/arm_sdk. This client sends action requests over RPC and does not
|
||||
* generate joint trajectories itself.
|
||||
*/
|
||||
class H2ArmActionClient : public Client {
|
||||
public:
|
||||
H2ArmActionClient() : Client(ARM_ACTION_SERVICE_NAME, false) {}
|
||||
|
||||
void Init() {
|
||||
SetApiVersion(ARM_ACTION_API_VERSION);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_ARM_ACTION_EXECUTE_ACTION);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_ARM_ACTION_GET_ACTION_LIST);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_ARM_ACTION_EXECUTE_CUSTOM_ACTION);
|
||||
UT_ROBOT_CLIENT_REG_API_NO_PROI(ROBOT_API_ID_ARM_ACTION_STOP_CUSTOM_ACTION);
|
||||
}
|
||||
|
||||
int32_t ExecuteAction(int32_t action_id) {
|
||||
JsonizeArmActionCommand command;
|
||||
command.action_id = action_id;
|
||||
|
||||
std::string data;
|
||||
const std::string parameter = common::ToJsonString(command);
|
||||
return Call(ROBOT_API_ID_ARM_ACTION_EXECUTE_ACTION, parameter, data);
|
||||
}
|
||||
|
||||
int32_t ExecuteAction(const std::string& action_name) {
|
||||
JsonizeArmActionName command;
|
||||
command.action_name = action_name;
|
||||
|
||||
std::string data;
|
||||
const std::string parameter = common::ToJsonString(command);
|
||||
return Call(ROBOT_API_ID_ARM_ACTION_EXECUTE_CUSTOM_ACTION, parameter, data);
|
||||
}
|
||||
|
||||
int32_t StopCustomAction() {
|
||||
std::string parameter;
|
||||
std::string data;
|
||||
return Call(ROBOT_API_ID_ARM_ACTION_STOP_CUSTOM_ACTION, parameter, data);
|
||||
}
|
||||
|
||||
int32_t GetActionList(std::string& data) {
|
||||
std::string parameter;
|
||||
return Call(ROBOT_API_ID_ARM_ACTION_GET_ACTION_LIST, parameter, data);
|
||||
}
|
||||
|
||||
// This is a local list known by the client, not a list queried from the robot.
|
||||
inline static const std::map<std::string, int32_t> action_map = {
|
||||
{"release arm", 99}, {"two-hand kiss", 11},
|
||||
{"left kiss", 12}, {"hands up", 15},
|
||||
{"clap", 17}, {"high five", 18},
|
||||
{"hug", 19}, {"heart", 20},
|
||||
{"right heart", 21}, {"reject", 22},
|
||||
{"right hand up", 23}, {"x-ray", 24},
|
||||
{"face wave", 25}, {"high wave", 26},
|
||||
{"shake hand", 27},
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace h2
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <unitree/common/decl.hpp>
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace h2 {
|
||||
|
||||
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_ARMSDK, 7400,
|
||||
"The topic rt/arm_sdk is occupied.")
|
||||
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_HOLDING, 7401,
|
||||
"The arm is holding. Send action 99 or repeat the last action ID to release it.")
|
||||
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_INVALID_ACTION_ID, 7402,
|
||||
"Invalid arm action ID.")
|
||||
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_INVALID_FSM_ID, 7404,
|
||||
"The current FSM does not support arm actions.")
|
||||
|
||||
} // namespace h2
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
||||
Reference in New Issue
Block a user