forked from Arturvpf/ProjetoExtra-ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
copiar.c
195 lines (146 loc) · 9.19 KB
/
copiar.c
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#define PI 3.14
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern "C" {
#include "extApi.h"
}
void funcao(float digito){
float numj3[] = {-PI / 35,PI / 45, PI / 20, PI / 20, PI / 150,PI / 45, PI / 30, -PI / 55,0,PI / 200}
float numj2[] = {-PI / 4,-PI / 4, -PI / 4, -PI / 4, -PI / 4.5,-PI / 4,-PI / 4, -PI / 4.5,-PI / 4,-PI / 4}
float numj1[] = {-PI / 11, -PI / 15, -PI / 11, -PI / 10, -PI / 15, -PI / 11, -PI / 9.5,-PI / 15,-PI / 11,-PI / 9.5}
float backj2[] = {-PI / 3.75, -PI / 3.8, -PI / 3.6, -PI / 3.55, -PI / 3.8, -PI / 3.70,-PI / 3.6,-PI / 3.9,-PI / 3.75,-PI / 3.65}
float t1[] = {1000, 1000, 2000, 3000, 4000, 2000, 3000, 2000, 2000, 2000}
float t2[] = {1000, 3000, 2000, 1000, 5000, 1000, 5000, 2000, 2000, 3000}
float t3[] = {1000, 3000, 2000, 2000, 2000, 1000, 3000, 2000, 1000, 2000}
float t4[] = {1000, 3000, 2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000}
strcpy(handlerName, "/base_link_respondable[0]/joint_3");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)numj3[digito], (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(t1[digito]);
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)numj2[digito], (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(t2[digito]);
strcpy(handlerName, "/base_link_respondable[0]/joint_1");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)numj1[digito], (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(t3[digito]);
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)backj2[digito], (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(t4[digito]);
}
int main(int argc, char* argv[]){
int handler = 0;
int clientID = simxStart((simxChar*) "127.0.0.1", 19999, true, true, 2000, 5);
extApi_sleepMs(500);
if (clientID == -1) {
printf("Erro conectando ao Coppelia!\n");
return 0;
} else {
printf("Conectado ao Coppelia!\n");
}
//Definir ponto central para movimentação do robô (em cima do número 5)
simxChar handlerName[150] = "/base_link_respondable[0]/joint_3";
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)0, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(1000);
simxSetJointTargetPosition(clientID, handler, (simxFloat)PI/45, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(2000);
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat) -PI/4, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(12000);
strcpy(handlerName, "/base_link_respondable[0]/joint_1");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI/11, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(3000);
int digito;
char numero[6];
int cont;
int tam;
FILE* arq;
arq = fopen("votos.txt", "r");
if (arq == NULL) {
printf("Falha ao acessar o arquivo");
exit (1);
}
else if (arq != NULL) {
printf("Sucesso ao acessar o arquivo");
while (!feof(arq)) {
fscanf(arq, " %[^\n]\n", numero);
tam = strlen(numero);
for (cont = 0; cont < tam; cont++) {
digito = numero[cont] - 48;
funcao(digito);
}
//VOLTANDO PARA O PONTO DEFINIDO
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI / 4, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(4000);
strcpy(handlerName, "/base_link_respondable[0]/joint_1");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI / 11, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(2000);
strcpy(handlerName, "/base_link_respondable[0]/joint_3");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)PI/45, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(2000);
if (cont == tam-1) {
//CONFIRMANDO VOTO
strcpy(handlerName, "/base_link_respondable[0]/joint_3");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI / 70, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(6000);
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI / 8, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(6000);
strcpy(handlerName, "/base_link_respondable[0]/joint_1");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI / 8, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(6000);
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI / 3.55, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(7000);
//VOLTANDO PARA O PONTO DEFINIDO
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI / 4, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(4000);
strcpy(handlerName, "/base_link_respondable[0]/joint_1");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)-PI / 11, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(2000);
strcpy(handlerName, "/base_link_respondable[0]/joint_3");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)PI / 45, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(2000);
}
}
}
fclose(arq);
//VOLTANDO PARA A POSIÇÃO INICIAL
strcpy(handlerName, "/base_link_respondable[0]/joint_3");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)0, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(3000);
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)0, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(15000);
strcpy(handlerName, "/base_link_respondable[0]/joint_1");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)0, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(3000);
strcpy(handlerName, "/base_link_respondable[0]/joint_2");
simxGetObjectHandle(clientID, handlerName, &handler, (simxInt)simx_opmode_oneshot_wait);
simxSetJointTargetPosition(clientID, handler, (simxFloat)0, (simxInt)simx_opmode_oneshot_wait);
extApi_sleepMs(2000);
}
simxFinish(clientID);
return(0);
}