AGVC SDK API  0.7.0
rtde.h
浏览该文件的文档.
1/** @file rtde.h
2 * @brief 用于RPC模块的交互,如订阅、发布等功能
3 */
4#ifndef AGVC_SDK_RTDE_H
5#define AGVC_SDK_RTDE_H
6
7#define AGVC_ABI
8
9#include <string>
10#include <vector>
11#include <functional>
12#include <memory>
13#include <map>
14#include <unordered_map>
15
16#include "type.h"
17
18namespace agvc_interface {
19
20class RtdeClient;
21
22/// 向输出数据中增加
24{
25public:
28
30 OutputBuilder &push(double val);
31 OutputBuilder &push(const std::vector<double> &val);
32 OutputBuilder &push(const std::tuple<int, bool> &val);
33 OutputBuilder &push(int16_t &val);
34 OutputBuilder &push(const std::vector<int16_t> &val);
35 OutputBuilder &push(const std::vector<int> &val);
36 OutputBuilder &push(const std::string &val);
37 OutputBuilder &push(char val);
39
40
41private:
42 friend RtdeClient;
43 class Impl;
44 Impl *impl;
45};
46
47/// 解析输入
49{
50public:
53
54 bool popBool();
55 int popInt32();
56 int64_t popInt64();
57 int16_t popInt16();
58 double popDouble();
59 char popChar();
60 std::string popString();
61 std::vector<int> popVectorInt();
62 std::vector<int16_t> popVectorInt16();
63 std::vector<double> popVectorDouble();
64 std::vector<std::vector<double>> popVectorVectorDouble();
69 std::vector<agvc_interface::Point2d> popVectorPoint2d();
70 std::vector<agvc_interface::Header> popVectorHeader();
71
72private:
73 friend RtdeClient;
74 class Impl;
75 Impl *impl;
76};
77
78/// RTDE客户端
80{
81public:
87
88 /**
89 * RTDE客户端初始化
90 *
91 * @param mode 设置通讯方式, 0 tcp通讯 1 uds通讯
92 */
93 RtdeClient(int mode = 0);
95
96 /**
97 * 设置日志处理器
98 *
99 * 此函数可设置自定义的日志处理函数来处理日志消息。 \n
100 * Aubo SDK 有一套默认的日志系统,按照默认的格式输出到默认的文件。
101 * 如果用户不希望采用默认的格式或者不希望输出到默认的文件,那就可以通过这个接口重新自定义格式,或者输出路径。
102 * 这个函数可以将用户自定义的日志系统与 Aubo SDK 默认的日志系统合并。
103 *
104 * @note setLogHandler函数要放在即将触发的日志之前,
105 * 否则会按照默认的形式输出日志。
106 *
107 * @param handler 日志处理函数 \n
108 * 此日志处理函数的下定义如下: \n
109 * void handler(int level, const char* filename, int line, const
110 * std::string& message) \n
111 * level 表示日志等级 \n
112 * &nbsp; 0: LOGLEVEL_FATAL 严重的错误 \n
113 * &nbsp; 1: LOGLEVEL_ERROR 错误 \n
114 * &nbsp; 2: LOGLEVEL_WARNING 警告 \n
115 * &nbsp; 3: LOGLEVEL_INFO 通知 \n
116 * &nbsp; 4: LOGLEVEL_DEBUG 调试 \n
117 * &nbsp; 5: LOGLEVEL_BACKTRACE 跟踪 \n
118 * filename 表示文件名 \n
119 * line 表示代码行号 \n
120 * message 表示日志信息 \n
121 * @return 无
122 */
124 std::function<void(int /*level*/, const char * /*filename*/, int /*line*/, const std::string & /*message*/)>
125 handler);
126
127 /**
128 * 连接到服务器
129 *
130 * @param ip IP地址
131 * @param port 端口号,RTDE 端口号为30110
132 * @retval 0 连接成功
133 * @retval 1 在执行函数前,已连接
134 * @retval -1 连接失败
135 */
136 int connect(const std::string &ip = "", int port = 0);
137
138 /**
139 * socket 是否已连接
140 *
141 * @retval true 已连接socket
142 * @retval false 未连接socket
143 */
144 bool hasConnected() const;
145
146 /**
147 * socket 是否已连接
148 *
149 * @param callback
150 * @retval true 已连接socket
151 * @retval false 未连接socket
152 */
153 bool hasConnected1(std::function<void(bool)> callback);
154
155 /**
156 * 登录
157 *
158 * @param usrname 用户名
159 * @param passwd 密码
160 * @retval 0 成功
161 * @retval -1 失败
162 */
163 int login(const std::string &usrname, const std::string &passwd);
164
165 /**
166 * 是否已经登录
167 *
168 * @retval true 已登录
169 * @retval false 未登录
170 */
172
173 /**
174 * 登出
175 *
176 * @return 0
177 */
178 int logout();
179
180 /**
181 * 断开连接
182 *
183 * @retval 0 成功
184 * @retval -1 失败
185 */
187
188 /**
189 * 获取协议版本号
190 *
191 * @return 协议版本号
192 */
194
195 /**
196 * 获取输入列表
197 *
198 * @return 输入列表
199 */
200 std::map<std::string, int> getInputMaps();
201
202 /**
203 * 获取输出列表
204 *
205 * @return 输出列表
206 */
207 std::map<std::string, int> getOutputMaps();
208
209 /**
210 * 设置话题
211 *
212 * @param to_server 数据流向。
213 * true 表示客户端给服务器发送消息,false 表示服务器给客户端发送消息
214 * @param names 服务器推送的信息列表
215 * @param freq 服务器推送信息的频率
216 * @param expected_chanel 通道。
217 * 取值范围:0~99,
218 * 发布不同的话题走不同的通道
219 * @retval expected_chanel参数的值 成功
220 * @retval -1 失败
221 */
222 int setTopic(bool to_server, const std::vector<std::string> &names, double freq, int expected_chanel);
223
224 /**
225 * 取消订阅
226 *
227 * @param to_server 数据流向
228 * true 表示客户端给服务器发送消息,false 表示服务器给客户端发送消息
229 * @param chanel 通道
230 * @retval 0 成功
231 * @retval 1 失败
232 */
233 int removeTopic(bool to_server, int chanel);
234
235 /**
236 * 获取已注册的输入菜单
237 *
238 * @return 已注册的输入菜单
239 */
240 std::unordered_map<int, agvc_interface::RtdeRecipe> getRegisteredInputRecipe();
241
242 /**
243 * 获取已注册的输出菜单
244 *
245 * @return 已注册的输出菜单
246 */
247 std::unordered_map<int, agvc_interface::RtdeRecipe> getRegisteredOutputRecipe();
248
249 /**
250 * 订阅 subscribe from output
251 *
252 * @param chanel 通道
253 * @param callback 回调函数,用于处理订阅的输入信息。\n
254 * 回调函数的定义如下:
255 * void callback(InputParser &parser)
256 * @return 0
257 */
258 int subscribe(int chanel, std::function<void(InputParser &)> callback);
259
260 /**
261 * 发布 publish to input
262 *
263 * @param chanel 通道
264 * @param callback 回调函数,用于构建发布的输出信息。\n
265 * 回调函数的定义如下:
266 * void callback(OutputBuilder &builder)
267 * @retval 0 成功
268 * @retval -1 失败
269 */
270 int publish(int chanel, std::function<void(OutputBuilder &)> callback);
271
272 /**
273 * 设置事件处理
274 *
275 * @param cb
276 * @return
277 */
278 int setEventHandler(std::function<void(int /*event*/)> cb);
279
280private:
281 class Impl;
282 Impl *impl;
283};
284using RtdeClientPtr = std::shared_ptr<RtdeClient>;
285
286} // namespace agvc_interface
287
288#define RtdeClient_DECLARES \
289 _FUNC(RtdeClient, 1, setLogHandler, handler) \
290 _FUNC(RtdeClient, 2, connect, ip, port) \
291 _FUNC(RtdeClient, 0, disconnect) \
292 _FUNC(RtdeClient, 0, hasConnected) \
293 _FUNC(RtdeClient, 1, hasConnected1, callback) \
294 _FUNC(RtdeClient, 2, login, usrname, passwd) \
295 _FUNC(RtdeClient, 0, logout) \
296 _FUNC(RtdeClient, 0, hasLogined) \
297 _FUNC(RtdeClient, 0, getProtocolVersion) \
298 _FUNC(RtdeClient, 0, getInputMaps) \
299 _FUNC(RtdeClient, 0, getOutputMaps) \
300 _FUNC(RtdeClient, 4, setTopic, to_server, names, freq, expected_chanel) \
301 _FUNC(RtdeClient, 2, removeTopic, to_server, chanel) \
302 _FUNC(RtdeClient, 0, getRegisteredInputRecipe) \
303 _FUNC(RtdeClient, 0, getRegisteredOutputRecipe) \
304 _FUNC(RtdeClient, 2, subscribe, chanel, callback) \
305 _FUNC(RtdeClient, 2, publish, chanel, callback) \
306 _FUNC(RtdeClient, 1, setEventHandler, cb)
307
308#endif
agvc_interface::Pose2d popPose2d()
std::vector< std::vector< double > > popVectorVectorDouble()
agvc_interface::AgvDetails popAgvDetails()
std::vector< int16_t > popVectorInt16()
std::vector< double > popVectorDouble()
std::vector< int > popVectorInt()
agvc_interface::RunningInfo popRunningInfo()
agvc_interface::NavInfo popNavInfo()
std::vector< agvc_interface::Point2d > popVectorPoint2d()
std::vector< agvc_interface::Header > popVectorHeader()
向输出数据中增加
定义 rtde.h:24
OutputBuilder & push(double val)
OutputBuilder & push(int16_t &val)
OutputBuilder & push(const std::vector< double > &val)
OutputBuilder & push(int val)
OutputBuilder & push(const std::string &val)
OutputBuilder & push(char val)
OutputBuilder & push(const std::vector< int > &val)
OutputBuilder & push(const std::vector< int16_t > &val)
OutputBuilder & push(const agvc_interface::RtdeRecipe &val)
OutputBuilder & push(const std::tuple< int, bool > &val)
std::unordered_map< int, agvc_interface::RtdeRecipe > getRegisteredOutputRecipe()
获取已注册的输出菜单
int removeTopic(bool to_server, int chanel)
取消订阅
bool hasConnected() const
socket 是否已连接
int setTopic(bool to_server, const std::vector< std::string > &names, double freq, int expected_chanel)
设置话题
int connect(const std::string &ip="", int port=0)
连接到服务器
bool hasLogined()
是否已经登录
std::unordered_map< int, agvc_interface::RtdeRecipe > getRegisteredInputRecipe()
获取已注册的输入菜单
std::map< std::string, int > getInputMaps()
获取输入列表
int login(const std::string &usrname, const std::string &passwd)
登录
int subscribe(int chanel, std::function< void(InputParser &)> callback)
订阅 subscribe from output
bool hasConnected1(std::function< void(bool)> callback)
socket 是否已连接
int setEventHandler(std::function< void(int)> cb)
设置事件处理
int disconnect()
断开连接
RtdeClient(int mode=0)
RTDE客户端初始化
int getProtocolVersion()
获取协议版本号
std::map< std::string, int > getOutputMaps()
获取输出列表
void setLogHandler(std::function< void(int, const char *, int, const std::string &)> handler)
设置日志处理器
int publish(int chanel, std::function< void(OutputBuilder &)> callback)
发布 publish to input
std::shared_ptr< RtdeClient > RtdeClientPtr
定义 rtde.h:284
#define AGVC_ABI
定义 rpc.h:7
导航状态信息 / 自动充电状态信息
定义 type.h:761