cmvr-es/third_party/AuboSdk/linux/include/aubo_sdk/rtde.h

303 lines
7.6 KiB
C
Raw Normal View History

2025-11-17 13:48:22 +08:00
/** @file rtde.h
* @brief RPC模块的交互
*/
#ifndef AUBO_SDK_RTDE_H
#define AUBO_SDK_RTDE_H
#include <string>
#include <vector>
#include <functional>
#include <memory>
#include <map>
#include <unordered_map>
#include <aubo/type_def.h>
#include <aubo/global_config.h>
namespace arcs {
namespace aubo_sdk {
class RtdeClient;
/// 向输出数据中增加
class ARCS_ABI OutputBuilder
{
public:
OutputBuilder();
~OutputBuilder();
OutputBuilder &push(int val);
OutputBuilder &push(double val);
OutputBuilder &push(const std::vector<double> &val);
OutputBuilder &push(const std::tuple<int, bool> &val);
OutputBuilder &push(int16_t &val);
OutputBuilder &push(const std::vector<int16_t> &val);
OutputBuilder &push(const std::vector<int> &val);
OutputBuilder &push(const std::string &val);
OutputBuilder &push(char val);
OutputBuilder &push(const common_interface::RtdeRecipe &val);
private:
friend RtdeClient;
class Impl;
Impl *impl;
};
/// 解析输入
class ARCS_ABI InputParser
{
public:
InputParser();
~InputParser();
bool popBool();
int popInt32();
int64_t popInt64();
int16_t popInt16();
double popDouble();
char popChar();
std::vector<int> popVectorInt();
std::vector<int16_t> popVectorInt16();
std::vector<double> popVectorDouble();
std::vector<std::vector<double>> popVectorVectorDouble();
std::vector<common_interface::JointStateType> popVectorJointStateType();
common_interface::RobotModeType popRobotModeType();
common_interface::OperationalModeType popOperationalModeType();
common_interface::SafetyModeType popSafetyModeType();
common_interface::RuntimeState popRuntimeState();
common_interface::RobotMsgVector popRobotMsgVector();
common_interface::Payload popPayload();
private:
friend RtdeClient;
class Impl;
Impl *impl;
};
/// RTDE客户端
class ARCS_ABI RtdeClient
{
public:
enum Event
{
Connected,
Disconnected,
};
/**
* RTDE客户端初始化
*
* @param mode 0 tcp通讯 1 uds通讯
*/
RtdeClient(int mode = 0);
~RtdeClient();
/**
*
*
* \n
* Aubo SDK
*
* Aubo SDK
*
* @note setLogHandler函数要放在即将触发的日志之前
*
*
* @param handler \n
* : \n
* void handler(int level, const char* filename, int line, const
* std::string& message) \n
* level \n
* &nbsp; 0: LOGLEVEL_FATAL \n
* &nbsp; 1: LOGLEVEL_ERROR \n
* &nbsp; 2: LOGLEVEL_WARNING \n
* &nbsp; 3: LOGLEVEL_INFO \n
* &nbsp; 4: LOGLEVEL_DEBUG \n
* &nbsp; 5: LOGLEVEL_BACKTRACE \n
* filename \n
* line \n
* message \n
* @return
*/
void setLogHandler(
std::function<void(int /*level*/, const char * /*filename*/,
int /*line*/, const std::string & /*message*/)>
handler);
/**
*
*
* @param ip IP地址
* @param port RTDE 30010
* @retval 0
* @retval 1
* @retval -1
*/
int connect(const std::string &ip = "", int port = 0);
/**
* socket
*
* @retval true socket
* @retval false socket
*/
bool hasConnected() const;
/**
* socket
*
* @param callback
* @retval true socket
* @retval false socket
*/
bool hasConnected1(std::function<void(bool)> callback);
/**
*
*
* @param usrname
* @param passwd
* @retval 0
* @retval -1
*/
int login(const std::string &usrname, const std::string &passwd);
/**
*
*
* @retval true
* @retval false
*/
bool hasLogined();
/**
*
*
* @return 0
*/
int logout();
/**
*
*
* @retval 0
* @retval -1
*/
int disconnect();
/**
*
*
* @return
*/
int getProtocolVersion();
/**
*
*
* @return
*/
std::map<std::string, int> getInputMaps();
/**
*
*
* @return
*/
std::map<std::string, int> getOutputMaps();
/**
*
*
* @param to_server
* true false
* @param names
* @param freq
* @param expected_chanel
* 0~99
*
* @retval expected_chanel参数的值
* @retval -1
*/
int setTopic(bool to_server, const std::vector<std::string> &names,
double freq, int expected_chanel);
/**
*
*
* @param to_server
* true false
* @param chanel
* @retval 0
* @retval 1
*/
int removeTopic(bool to_server, int chanel);
/**
*
*
* @return
*/
std::unordered_map<int, common_interface::RtdeRecipe>
getRegisteredInputRecipe();
/**
*
*
* @return
*/
std::unordered_map<int, common_interface::RtdeRecipe>
getRegisteredOutputRecipe();
/**
* subscribe from output
*
* @param chanel
* @param callback \n
*
* void callback(InputParser &parser)
* @return 0
*/
int subscribe(int chanel, std::function<void(InputParser &)> callback);
/**
* publish to input
*
* @param chanel
* @param callback \n
*
* void callback(OutputBuilder &builder)
* @retval 0
* @retval -1
*/
int publish(int chanel, std::function<void(OutputBuilder &)> callback);
/**
*
*
* @param cb
* @return
*/
int setEventHandler(std::function<void(int /*event*/)> cb);
private:
class Impl;
Impl *impl;
};
using RtdeClientPtr = std::shared_ptr<RtdeClient>;
} // namespace aubo_sdk
} // namespace arcs
#ifdef __cplusplus
extern "C" {
#endif
ARCS_ABI arcs::aubo_sdk::RtdeClient *createRtdeClient(int mode = 0);
ARCS_ABI void destroyRtdeClient(arcs::aubo_sdk::RtdeClient *cli);
#ifdef __cplusplus
}
#endif
#endif