init
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <unitree/common/json/jsonize.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace g1 {
|
||||
/*service name*/
|
||||
const std::string ARM_ACTION_SERVICE_NAME = "arm";
|
||||
|
||||
/*api version*/
|
||||
const std::string ARM_ACTION_API_VERSION = "1.0.0.14";
|
||||
|
||||
/*api id*/
|
||||
const int32_t ROBOT_API_ID_ARM_ACTION_EXECUTE_ACTION = 7106;
|
||||
const int32_t ROBOT_API_ID_ARM_ACTION_GET_ACTION_LIST = 7107;
|
||||
|
||||
class JsonizeArmActionCommand : public common::Jsonize {
|
||||
public:
|
||||
JsonizeArmActionCommand() {}
|
||||
~JsonizeArmActionCommand() {}
|
||||
|
||||
void fromJson(common::JsonMap &json) {
|
||||
common::FromJson(json["data"], action_id);
|
||||
}
|
||||
|
||||
void toJson(common::JsonMap &json) const {
|
||||
common::ToJson(action_id, json["data"]);
|
||||
}
|
||||
|
||||
int32_t action_id;
|
||||
};
|
||||
|
||||
} // namespace g1
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include <unitree/robot/client/client.hpp>
|
||||
#include <unitree/robot/go2/public/jsonize_type.hpp>
|
||||
#include "g1_arm_action_api.hpp"
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace g1 {
|
||||
|
||||
/**
|
||||
* @brief Arm action client
|
||||
*
|
||||
* The arm action server provides some upper body actions.
|
||||
* The controller is based on the `rt/arm_sdk` interface.
|
||||
*/
|
||||
class G1ArmActionClient : public Client {
|
||||
public:
|
||||
G1ArmActionClient() : Client(ARM_ACTION_SERVICE_NAME, false) {}
|
||||
~G1ArmActionClient() {}
|
||||
|
||||
/*Init*/
|
||||
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);
|
||||
}
|
||||
|
||||
/*API Call*/
|
||||
int32_t ExecuteAction(int32_t action_id) {
|
||||
std::string parameter, data;
|
||||
JsonizeArmActionCommand json;
|
||||
|
||||
json.action_id = action_id;
|
||||
parameter = common::ToJsonString(json);
|
||||
|
||||
return Call(ROBOT_API_ID_ARM_ACTION_EXECUTE_ACTION, parameter, data);
|
||||
}
|
||||
|
||||
int32_t GetActionList(std::string &data) {
|
||||
std::string parameter;
|
||||
return Call(ROBOT_API_ID_ARM_ACTION_GET_ACTION_LIST, parameter, data);
|
||||
}
|
||||
|
||||
/*Action List*/
|
||||
std::map<std::string, int32_t> action_map = {
|
||||
{"release arm", 99},
|
||||
{"two-hand kiss", 11},
|
||||
{"left kiss", 12},
|
||||
{"right 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 g1
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <unitree/common/decl.hpp>
|
||||
|
||||
namespace unitree {
|
||||
namespace robot {
|
||||
namespace g1 {
|
||||
|
||||
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_ARMSDK, 7400, "The topic rt/armsdk is occupied.")
|
||||
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_HOLDING, 7401, "The arm is holding. Expecting release action(99) or the same last action id.")
|
||||
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_INVALID_ACTION_ID, 7402, "Invalid action id.")
|
||||
// The actions are only supported in fsm id {500, 501, 801};
|
||||
// You can subscribe the topic rt/sportmodestate to check the fsm id.
|
||||
// And in the state 801, the actions are only supported in the fsm mode {0, 3}.
|
||||
// See https://support.unitree.com/home/en/G1_developer/sport_services_interface#Expert%20interface
|
||||
UT_DECL_ERR(UT_ROBOT_ARM_ACTION_ERR_INVALID_FSM_ID, 7404, "Invalid fsm id.")
|
||||
|
||||
} // namespace g1
|
||||
} // namespace robot
|
||||
} // namespace unitree
|
Reference in New Issue
Block a user