ARCS SDK API  0.24.0
runtime_machine.h
浏览该文件的文档.
1 /** @file runtime_machine.h
2  * @brief 脚本解释器运行时接口,
3  * 可以实现脚本解释器的暂停、脚本解释器的设置/取消断点
4  */
5 #ifndef AUBO_SDK_RUNTIME_MACHINE_INTERFACE_H
6 #define AUBO_SDK_RUNTIME_MACHINE_INTERFACE_H
7 
8 #include <memory>
9 #include <aubo/global_config.h>
10 #include <aubo/type_def.h>
11 
12 namespace arcs {
13 namespace common_interface {
14 
15 /**
16  * The RuntimeMachine class
17  */
18 class ARCS_ABI_EXPORT RuntimeMachine
19 {
20 public:
22  virtual ~RuntimeMachine();
23 
24  /**
25  * 返回 task_id
26  */
27  int newTask(bool daemon = false);
28 
29  /**
30  * 删除 task,会终止正在执行的运动
31  */
32  int deleteTask(int tid);
33 
34  /**
35  * 等待 task 自然结束
36  *
37  * @param tid
38  * @return
39  */
40  int detachTask(int tid);
41 
42  /**
43  * 判断任务是否存活
44  *
45  * @param tid
46  * @return
47  */
48  bool isTaskAlive(int tid);
49 
50  /**
51  * 切换当前线程,切换之后接下来的指令将被插入切换后的线程中
52  *
53  * @param tid
54  * @return
55  */
56  int switchTask(int tid);
57 
58  /**
59  * 标记记下来的指令的行号和注释
60  *
61  * @param lineno
62  * @param comment
63  * @return
64  */
65  int setLabel(int lineno, const std::string &comment);
66 
67  /**
68  * 向aubo_control日志中添加注释
69  * 使用 setLabel 替换
70  *
71  * @param tid 指令的线程ID
72  * @param lineno 行号
73  * @param comment 注释
74  * @return
75  *
76  * @par Python函数原型
77  * setPlanContext(self: pyaubo_sdk.RuntimeMachine, arg0: int, arg1: int,
78  * arg2: str) -> int
79  *
80  * @par Lua函数原型
81  * setPlanContext(tid: number, lineno: number, comment: string) -> number
82  *
83  */
84  ARCS_DEPRECATED int setPlanContext(int tid, int lineno,
85  const std::string &comment);
86 
87  /**
88  * 空操作
89  *
90  * @return
91  */
92  int nop();
93 
94  /**
95  * 获取耗时的接口执行状态, 如 setPersistentParameters
96  *
97  * @return 指令名字, 执行状态
98  * 执行状态: EXECUTING/FINISHED
99  *
100  * @par Python函数原型
101  * getExecutionStatus(self: pyaubo_sdk.RuntimeMachine) -> Tuple[str, str]
102  *
103  * @par Lua函数原型
104  * getExecutionStatus() -> string
105  *
106  */
107  std::tuple<std::string, std::string> getExecutionStatus();
108 
109  /**
110  * 跳转到指定行号
111  *
112  * @param lineno
113  * @return
114  *
115  * @par Python函数原型
116  * gotoLine(self: pyaubo_sdk.RuntimeMachine, arg0: int) -> int
117  *
118  * @par Lua函数原型
119  * gotoLine(lineno: number) -> number
120  *
121  */
122  int gotoLine(int lineno);
123 
124  /**
125  * 获取当前运行上下文
126  *
127  * @param tid 任务编号
128  * 如果指定(不是-1),返回对应任务的运行上下文;如果不指定(是-1),返回正在运行的线程的运行上下文
129  *
130  * @return
131  *
132  * @par Python函数原型
133  * getPlanContext(self: pyaubo_sdk.RuntimeMachine) -> Tuple[int, int, str]
134  *
135  * @par Lua函数原型
136  * getPlanContext() -> number
137  *
138  */
139  std::tuple<int, int, std::string> getPlanContext(int tid = -1);
140 
141  /**
142  * 获取提前运行规划器的上下文信息
143  *
144  * @param tid 任务编号
145  * 如果指定(不是-1),返回对应任务运行规划器的上下文信息;如果不指定(是-1),返回正在运行的线程运行规划器的上下文信息
146  *
147  * @return
148  */
149  std::tuple<int, int, std::string> getAdvancePlanContext(int tid = -1);
150 
151  /**
152  * 获取AdvanceRun的程序指针
153  *
154  * @return
155  */
156  int getAdvancePtr(int tid = -1);
157 
158  /**
159  * 获取机器人运动的程序指针
160  *
161  * @param tid 任务编号
162  * 如果指定(不是-1),返回对应任务的程序指针;如果不指定(是-1),返回正在运行线程的程序指针
163  *
164  * @return
165  */
166  int getMainPtr(int tid = -1);
167 
168  /**
169  * 获取最近解释过的指令指针
170  *
171  * @param tid
172  * @return
173  */
174  int getInterpPtr(int tid);
175 
176  /**
177  * 加载本地工程文件
178  * Lua 脚本,只需要给出文件名字,不需要后缀,需要从 ${ARCS_WS}/program
179  * 目录中查找
180  *
181  * @param program
182  * @return
183  *
184  * @par JSON-RPC请求示例
185  * {"jsonrpc":"2.0","method":"RuntimeMachine.loadProgram","params":["demo"],"id":1}
186  *
187  * @par JSON-RPC响应示例
188  * {"id":1,"jsonrpc":"2.0","result":0}
189  *
190  */
191  int loadProgram(const std::string &program);
192 
193  /**
194  * 运行已经加载的工程文件
195  *
196  * @return
197  *
198  * @par JSON-RPC请求示例
199  * {"jsonrpc":"2.0","method":"RuntimeMachine.runProgram","params":[],"id":1}
200  *
201  * @par JSON-RPC响应示例
202  * {"id":1,"jsonrpc":"2.0","result":0}
203  *
204  */
205  int runProgram();
206 
207  /**
208  * 开始运行时
209  *
210  * @return
211  *
212  * @par Python函数原型
213  * start(self: pyaubo_sdk.RuntimeMachine) -> int
214  *
215  * @par Lua函数原型
216  * start() -> number
217  *
218  * @par JSON-RPC请求示例
219  * {"jsonrpc":"2.0","method":"RuntimeMachine.start","params":[],"id":1}
220  *
221  * @par JSON-RPC响应示例
222  * {"id":1,"jsonrpc":"2.0","result":0}
223  *
224  */
225  int start();
226 
227  /**
228  * 停止运行时即脚本运行,无法停止运行时状态为 Stopped 时的机器人运动
229  *
230  * 如果考虑停止机器人所有运动,可以调用 RuntimeMachine::abort 接口
231  *
232  * @return
233  *
234  * @par Python函数原型
235  * stop(self: pyaubo_sdk.RuntimeMachine) -> int
236  *
237  * @par Lua函数原型
238  * stop() -> number
239  *
240  * @par JSON-RPC请求示例
241  * {"jsonrpc":"2.0","method":"RuntimeMachine.stop","params":[],"id":1}
242  *
243  * @par JSON-RPC响应示例
244  * {"id":1,"jsonrpc":"2.0","result":0}
245  *
246  */
247  int stop();
248 
249  /**
250  * 终止机器人运行.
251  *
252  * 如果只是考虑停止运行时,可以调用 RuntimeMachine::stop 接口
253  *
254  * 如果脚本运行时处于 Running 状态,则终止运行时;如果运行时处于 Stopped
255  * 且机器人正在移动,则停止机器人移动;如果此时力控开启了,则机器人停止力控
256  *
257  * @return
258  *
259  * @par Python函数原型
260  * abort(self: pyaubo_sdk.RuntimeMachine) -> int
261  *
262  * @par Lua函数原型
263  * abort() -> number
264  *
265  * @par JSON-RPC请求示例
266  * {"jsonrpc":"2.0","method":"RuntimeMachine.abort","params":[],"id":1}
267  *
268  * @par JSON-RPC响应示例
269  * {"id":1,"jsonrpc":"2.0","result":0}
270  *
271  */
272  int abort();
273 
274  /**
275  * 暂停解释器
276  *
277  * @return
278  *
279  * @par Python函数原型
280  * pause(self: pyaubo_sdk.RuntimeMachine) -> int
281  *
282  * @par Lua函数原型
283  * pause() -> number
284  *
285  * @par JSON-RPC请求示例
286  * {"jsonrpc":"2.0","method":"RuntimeMachine.pause","params":[],"id":1}
287  *
288  * @par JSON-RPC响应示例
289  * {"id":1,"jsonrpc":"2.0","result":0}
290  *
291  */
292  int pause();
293 
294  /**
295  * 单步运行
296  *
297  * @return
298  *
299  * @par Python函数原型
300  * step(self: pyaubo_sdk.RuntimeMachine) -> int
301  *
302  * @par Lua函数原型
303  * step() -> number
304  *
305  */
306  int step();
307 
308  /**
309  * 恢复解释器
310  *
311  * @return
312  *
313  * @par Python函数原型
314  * resume(self: pyaubo_sdk.RuntimeMachine) -> int
315  *
316  * @par Lua函数原型
317  * resume() -> number
318  *
319  * @par JSON-RPC请求示例
320  * {"jsonrpc":"2.0","method":"RuntimeMachine.resume","params":[],"id":1}
321  *
322  * @par JSON-RPC响应示例
323  * {"id":1,"jsonrpc":"2.0","result":0}
324  *
325  */
326  int resume();
327 
328  /**
329  * 恢复解释器之前等待恢复前之前的序列完成
330  *
331  * @param wait
332  * @return
333  */
334  int setResumeWait(bool wait);
335 
336  /**
337  * 获取规划器的状态
338  *
339  * @return
340  *
341  * @par Python函数原型
342  * getStatus(self: pyaubo_sdk.RuntimeMachine) ->
343  * arcs::common_interface::RuntimeState
344  *
345  * @par Lua函数原型
346  * getStatus() -> number
347  *
348  * @par JSON-RPC请求示例
349  * {"jsonrpc":"2.0","method":"RuntimeMachine.getStatus","params":[],"id":1}
350  *
351  * @par JSON-RPC响应示例
352  * {"id":1,"jsonrpc":"2.0","result":"Running"}
353  *
354  */
355  ARCS_DEPRECATED RuntimeState getStatus();
356  RuntimeState getRuntimeState();
357 
358  /**
359  * 设置断点
360  *
361  * @param lineno
362  * @return
363  *
364  * @par Python函数原型
365  * setBreakPoint(self: pyaubo_sdk.RuntimeMachine, arg0: int) -> int
366  *
367  * @par Lua函数原型
368  * setBreakPoint(lineno: number) -> number
369  *
370  */
371  int setBreakPoint(int lineno);
372 
373  /**
374  * 移除断点
375  *
376  * @param lineno
377  * @return
378  *
379  * @par Python函数原型
380  * removeBreakPoint(self: pyaubo_sdk.RuntimeMachine, arg0: int) -> int
381  *
382  * @par Lua函数原型
383  * removeBreakPoint(lineno: number) -> number
384  *
385  */
386  int removeBreakPoint(int lineno);
387 
388  /**
389  * 清除所有断点
390  *
391  * @return
392  *
393  * @par Python函数原型
394  * clearBreakPoints(self: pyaubo_sdk.RuntimeMachine) -> int
395  *
396  * @par Lua函数原型
397  * clearBreakPoints() -> number
398  *
399  */
400  int clearBreakPoints();
401 
402  /**
403  * 定时器开始
404  *
405  * @param name
406  * @return
407  *
408  * @par Python函数原型
409  * timerStart(self: pyaubo_sdk.RuntimeMachine, arg0: str) -> int
410  *
411  * @par Lua函数原型
412  * timerStart(name: string) -> nil
413  *
414  */
415  int timerStart(const std::string &name);
416 
417  /**
418  * 定时器结束
419  *
420  * @param name
421  * @return
422  *
423  * @par Python函数原型
424  * timerStop(self: pyaubo_sdk.RuntimeMachine, arg0: str) -> int
425  *
426  * @par Lua函数原型
427  * timerStop(name: string) -> nil
428  *
429  */
430  int timerStop(const std::string &name);
431 
432  /**
433  * 定时器重置
434  *
435  * @param name
436  * @return
437  *
438  * @par Python函数原型
439  * timerReset(self: pyaubo_sdk.RuntimeMachine, arg0: str) -> int
440  *
441  * @par Lua函数原型
442  * timerReset(name: string) -> nil
443  *
444  */
445  int timerReset(const std::string &name);
446 
447  /**
448  * 定时器删除
449  *
450  * @param name
451  * @return
452  *
453  * @par Python函数原型
454  * timerDelete(self: pyaubo_sdk.RuntimeMachine, arg0: str) -> int
455  *
456  * @par Lua函数原型
457  * timerDelete(name: string) -> nil
458  *
459  */
460  int timerDelete(const std::string &name);
461 
462  /**
463  * 获取定时器数值
464  *
465  * @param name
466  * @return
467  *
468  * @par Python函数原型
469  * getTimer(self: pyaubo_sdk.RuntimeMachine, arg0: str) -> float
470  *
471  * @par Lua函数原型
472  * getTimer(name: string) -> number
473  *
474  */
475  double getTimer(const std::string &name);
476 
477  /**
478  * 开始配置触发
479  *
480  * @param distance
481  * @param delay
482  * @return
483  */
484  int triggBegin(double distance, double delay);
485 
486  /**
487  * 终止配置触发
488  *
489  * @return
490  */
491  int triggEnd();
492 
493  /**
494  * 返回自动分配的中断号
495  *
496  * @param distance
497  * @param delay
498  * @param intnum
499  * @return
500  */
501  int triggInterrupt(double distance, double delay);
502 
503  /**
504  * 获取所有的中断号列表
505  *
506  * @return
507  */
508  std::vector<int> getTriggInterrupts();
509 
510 protected:
511  void *d_;
512 };
513 
514 using RuntimeMachinePtr = std::shared_ptr<RuntimeMachine>;
515 
516 // clang-format off
517 #define RuntimeMachine_DECLARES \
518  _FUNC(RuntimeMachine, 1, newTask, daemon) \
519  _FUNC(RuntimeMachine, 1, deleteTask, tid) \
520  _FUNC(RuntimeMachine, 1, detachTask, tid) \
521  _FUNC(RuntimeMachine, 1, isTaskAlive, tid) \
522  _INST(RuntimeMachine, 0, nop) \
523  _FUNC(RuntimeMachine, 1, switchTask, tid) \
524  _FUNC(RuntimeMachine, 2, setLabel, tid, lineno) \
525  _FUNC(RuntimeMachine, 3, setPlanContext, tid, lineno, comment) \
526  _FUNC(RuntimeMachine, 1, gotoLine, lineno) \
527  _FUNC(RuntimeMachine, 1, getAdvancePlanContext, tid) \
528  _FUNC(RuntimeMachine, 1, getAdvancePtr, tid) \
529  _FUNC(RuntimeMachine, 1, getMainPtr, tid) \
530  _FUNC(RuntimeMachine, 1, getInterpPtr, tid) \
531  _FUNC(RuntimeMachine, 1, getPlanContext, tid) \
532  _FUNC(RuntimeMachine, 0, getExecutionStatus) \
533  _FUNC(RuntimeMachine, 1, loadProgram, program) \
534  _FUNC(RuntimeMachine, 0, runProgram) \
535  _FUNC(RuntimeMachine, 0, start) \
536  _FUNC(RuntimeMachine, 0, stop) \
537  _FUNC(RuntimeMachine, 0, abort) \
538  _FUNC(RuntimeMachine, 0, pause) \
539  _FUNC(RuntimeMachine, 0, step) \
540  _FUNC(RuntimeMachine, 1, setResumeWait, wait) \
541  _FUNC(RuntimeMachine, 0, resume) \
542  _FUNC(RuntimeMachine, 0, getStatus) \
543  _FUNC(RuntimeMachine, 0, getRuntimeState) \
544  _FUNC(RuntimeMachine, 1, setBreakPoint, lineno) \
545  _FUNC(RuntimeMachine, 1, removeBreakPoint, lineno) \
546  _FUNC(RuntimeMachine, 0, clearBreakPoints) \
547  _INST(RuntimeMachine, 1, timerStart, name) \
548  _INST(RuntimeMachine, 1, timerStop, name) \
549  _INST(RuntimeMachine, 1, timerReset, name) \
550  _INST(RuntimeMachine, 1, timerDelete, name) \
551  _FUNC(RuntimeMachine, 1, getTimer, name) \
552  _FUNC(RuntimeMachine, 2, triggBegin, distance, delay) \
553  _FUNC(RuntimeMachine, 0, triggEnd) \
554  _FUNC(RuntimeMachine, 2, triggInterrupt, distance, delay) \
555  _FUNC(RuntimeMachine, 0, getTriggInterrupts)
556 
557 // clang-format on
558 } // namespace common_interface
559 } // namespace arcs
560 #endif // AUBO_SDK_RUNTIME_MACHINE_H
数据类型的定义
std::shared_ptr< RuntimeMachine > RuntimeMachinePtr
Definition: aubo_api.h:17