-
Notifications
You must be signed in to change notification settings - Fork 29
/
0001-event_register.cc
76 lines (63 loc) · 2.34 KB
/
0001-event_register.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Software License Agreement (MIT License)
*
* Copyright (c) 2022, UFACTORY, Inc.
*
* All rights reserved.
*
* @author Vinman <[email protected]> <[email protected]>
*/
#include "xarm/wrapper/xarm_api.h"
void report_location_callback(const fp32* pose, const fp32* angles) {
print_nvect("pose = ", (fp32*)pose, 6);
print_nvect("angles = ", (fp32*)angles, 7);
}
void connect_changed_callback(bool connected, bool reported) {
printf("connected: %d, reported: %d\n", connected, reported);
}
void state_changed_callback(int state) {
printf("state: %d\n", state);
}
void mode_changed_callback(int mode) {
printf("mode: %d\n", mode);
}
void mtable_mtbrake_changed_callback(int mtable, int mtbrake) {
printf("mtable: %d, mtbrake: %d\n", mtable, mtbrake);
}
void error_warn_changed_callback(int err, int warn) {
printf("err: %d, warn: %d\n", err, warn);
}
void cmdnum_changed_callback(int cmdnum) {
printf("cmdnum: %d\n", cmdnum);
}
int main(int argc, char **argv) {
if (argc < 2) {
printf("Please enter IP address\n");
return 0;
}
std::string port(argv[1]);
XArmAPI *arm = new XArmAPI(port, false, true, true, true, true, false, true, true, 0);
printf("register events\n");
arm->register_report_location_callback(report_location_callback);
arm->register_connect_changed_callback(connect_changed_callback);
arm->register_state_changed_callback(state_changed_callback);
arm->register_mode_changed_callback(mode_changed_callback);
arm->register_mtable_mtbrake_changed_callback(mtable_mtbrake_changed_callback);
arm->register_error_warn_changed_callback(error_warn_changed_callback);
arm->register_cmdnum_changed_callback(cmdnum_changed_callback);
arm->connect();
arm->motion_enable(true);
arm->set_mode(0);
arm->set_state(0);
sleep_milliseconds(100000);
printf("release events\n");
arm->release_report_location_callback(report_location_callback);
arm->release_connect_changed_callback(connect_changed_callback);
arm->release_state_changed_callback(state_changed_callback);
arm->release_mode_changed_callback(mode_changed_callback);
arm->release_mtable_mtbrake_changed_callback(mtable_mtbrake_changed_callback);
arm->release_error_warn_changed_callback(error_warn_changed_callback);
arm->release_cmdnum_changed_callback(cmdnum_changed_callback);
// sleep_milliseconds(30000);
return 0;
}