/
main.cpp
executable file
·53 lines (47 loc) · 1.24 KB
/
main.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
//Example that uses the RobotComau library to move from a starting position towards
//a set of different points, and then back to the initial position (after a keypress).
//
//Developed by Davide Valeriani
//www.davidevaleriani.it
#include "libs/RobotComau.h"
#include "libs/pthread.h"
RobotComau r("192.168.1.101", 10000, 10001);
bool stop = false;
void * getPos (void * arg) {
Point6d p1;
ofstream fout("trace.txt");
while (!stop) {
p1 = r.GetCurrentPositionOR();
fout << p1;
}
fout.close();
return NULL;
}
void * motion (void * arg) {
r.SetSpeed("30");
r.MoveLinearTo("starting_point.txt");
r.MoveRelative(0, 0, -200);
r.MoveRelative(0, 100, 0);
r.MoveRelative(0, 0, 200);
r.MoveRelative(0, 100, 0);
r.MoveRelative(0, 0, -200);
r.MoveRelative(0, 100, 0);
r.MoveRelative(0, 0, 200);
r.MoveRelative(0, 100, 0);
r.MoveRelative(0, 0, -200);
r.MoveRelative(0, 100, 0);
r.MoveRelative(0, 0, 200);
stop = true;
system("PAUSE");
r.MoveLinearTo("starting_point.txt");
r.CloseConnection();
return NULL;
}
int main () {
pthread_t thread1;
pthread_t thread2;
pthread_create(&thread2, NULL, motion, NULL);
pthread_create(&thread1, NULL, getPos, NULL);
pthread_join(thread2, NULL);
pthread_join(thread1, NULL);
}