-
Notifications
You must be signed in to change notification settings - Fork 40
/
XARMDriver.cpp
123 lines (103 loc) · 3.12 KB
/
XARMDriver.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "XARMDriver.h"
using namespace ofxRobotArm;
XARMDriver::XARMDriver(){
}
XARMDriver::XARMDriver(RobotType type){
if(type == XARM7){
numJoints = 7;
}
vector<double> foo;
foo.assign(numJoints, 0.0001);
initPose.assign(numJoints, 0.0001);
poseRaw.setup(foo);
toolPoseRaw.setup(foo);
poseProcessed.setup(foo);
poseRaw.getBack().assign(numJoints, 0.0001);
poseProcessed.getBack().assign(numJoints, 0.0001);
toolPoseRaw.getBack().assign(numJoints, 0.0001);
numDeccelSteps = 120;
}
XARMDriver::~XARMDriver(){
}
void XARMDriver::setAllowReconnect(bool bDoReconnect) {
}
void XARMDriver::setup() {
}
void XARMDriver::setup(string ipAddress, int port, double minPayload , double maxPayload ) {
}
void XARMDriver::setup(string ipAddress, double minPayload , double maxPayload ) {
robot = new XArmAPI(ipAddress);
robot->connect();
robot->set_mode(0);
robot->set_state(0);
robot->motion_enable(true);
}
void XARMDriver::setup(int port, double minPayload , double maxPayload ) {
}
void XARMDriver::start() {
}
bool XARMDriver::isConnected() {
return false;
}
void XARMDriver::disconnect() {
}
void XARMDriver::stopThread() {
}
void XARMDriver::toggleTeachMode() {
}
void XARMDriver::setTeachMode(bool enabled) {
}
vector<double> XARMDriver::getInitPose(){
vector<double> ret;
lock();
ret = initPose;
unlock();
return ret;
}
void XARMDriver::threadedFunction() {
while(isThreadRunning()){
int ret;
unsigned char version[40];
ret = robot->get_version(version);
// printf("ret=%d, version: %s\n", ret, version);
int state;
ret = robot->get_state(&state);
// printf("ret=%d, state: %d, mode: %d\n", ret, state, robot->mode);
int cmdnum;
ret = robot->get_cmdnum(&cmdnum);
// printf("ret=%d, cmdnum: %d\n", ret, cmdnum);
int err_warn[2];
ret = robot->get_err_warn_code(err_warn);
// printf("ret=%d, err: %d, warn: %d\n", ret, err_warn[0], err_warn[1]);
fp32 pose[6];
ret = robot->get_position(pose);
// printf("ret=%d, ", ret);
// print_nvect("pose: ", pose, 6);
fp32 angles[7];
ret = robot->get_servo_angle(angles);
// printf("ret=%d, ", ret);
// print_nvect("angles: ", angles, 7);
if(bMove && currentPose.size() > 0){
timeNow = ofGetElapsedTimef();
if( bMove || timeNow-lastTimeSentMove >= 1.0/60.0){
currentPose = getAchievablePosition(currentPose);
fp32 pose[currentPose.size()];
int i = 0;
for(auto angle : currentPose){
pose[i] = angle;
i++;
}
ret = robot->set_servo_angle(pose, false);
printf("set_servo_angle, ret=%d\n", ret);
if(!bMove){
deccelCount--;
if( deccelCount < 0){
deccelCount = 0;
}
}
lastTimeSentMove = timeNow;
}
bMove = false;
}
}
}