-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstageOne.cpp
More file actions
269 lines (242 loc) · 6.51 KB
/
stageOne.cpp
File metadata and controls
269 lines (242 loc) · 6.51 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/**
* stageOne.cpp
* This program completes the first stage of the research moving the arm and then focusing on it.
*
* Date: 11/12/2011
* Author: John Dyer
*
*/
#include <yarp/os/all.h>
#include <yarp/dev/all.h>
#include <yarp/sig/all.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <iomanip>
#include <GazeControl.h>
#include <iCub/iKin/iKinFwd.h>
#include <iCub/iKin/iKinIpOpt.h>
#include <iCub/iKin/iKinHlp.h>
#include <iCub/iKin/iKinSlv.h>
#include <gsl/gsl_math.h>
#include "stageOne.h"
#include "utilities.h"
#include "armController.cpp"
#include "eyeController.cpp"
using namespace std;
using namespace yarp::os;
using namespace yarp::dev;
using namespace yarp::sig;
using namespace yarp::math;
using namespace iCub::ctrl;
using namespace iCub::iKin;
double currentDepth;
double currentAngle;
int dataArraySize = 100;
Vector eyeAngles,gazePoint,endEffector,q0,currentPos;
bool* mStop=0;
int main(int argc, char* argv[])
{
cout<<"main";
srand(time(NULL));
Network yarp;
armController armCon;
YARP_REGISTER_DEVICES(icubmod);
cout<<"Start";
initDataStruct();
cout<<"Data";
initGazeControl();
cout<<"Gaze";
rightArmChainDriver = armCon.getRightPoly();
rightArmChainDriver->view(encs);
iCubArm* rightiCubArm = new iCubArm("right");
rightArmChain = rightiCubArm->asChain();
if(!rightiCubArm->isValid())
cout<< "error with iKin" << endl;
cout<<"updatingChain";
updateChain();
cout<<"updatedChain";
int l =0;
while (l<10)
{
// int i = 0;
// while (i<2)
// {
armCon.babble(1);
//checkMotionStop(&mStop);
updateChain();
// endEffector = rightiCubArm->EndEffPose(0);
// lookAtPoint();
//
// getValues();
// armCon.getCurrentPosition(currentPos,1);
// i++;
// Time::delay(1);
// }
endEffector = rightiCubArm->EndEffPose(0);
lookAtPoint();
getValues();
// bool success;
// do
// {
// success = armCon.getCurrentPosition(currentPos,1);
// }while(!success);
// int i =0;
// cout<< "Current position angles are: ";
// while(i<4)
// {
// cout << " " << currentPos[i];
// i++;
// }
// cout <<endl<<endl;
addValuesToStruct(eyeAngles,currentPos);
l++;
}
displayStruct();
return 0;
}
bool updateChain()
{
Vector fb, encodervalues;
encodervalues.resize(16);
encs -> getEncoders(encodervalues.data());
// cout << encodervalues.toString() <<endl;
// int i=0;
// while(i<5)
// {
// cout << encodervalues.toString() <<endl;
// i++;
// }
//cout << "Angles values from encoders: " << encodervalues.toString() <<endl;
fb = Vector(16, encodervalues.data());
fb = (M_PI*fb)/180; //Conversion to radians
//cout << "Angles in radian: " << fb.toString() << endl;
rightArmChain->setAng(fb); //kinematic
}
bool initGazeControl()
{
cout<<"init Gaze";
Property option;
option.put("device","gazecontrollerclient");
option.put("remote","/iKinGazeCtrl");
option.put("local","/gaze_client");
clientGazeCtrl.open(option);
if (clientGazeCtrl.isValid())
clientGazeCtrl.view(iGaze);
iGaze->blockNeckPitch();
iGaze->blockNeckRoll();
iGaze->blockNeckYaw();
return 0;
}
bool initDataStruct()
{
rightArm.panValue = new double[dataArraySize];
rightArm.tiltValue = new double[dataArraySize];
rightArm.versionValue = new double[dataArraySize];
rightArm.rollMotorAngleValue = new double[dataArraySize];
rightArm.pitchMotorAngleValue = new double[dataArraySize];
rightArm.yawMotorAngleValue = new double[dataArraySize];
rightArm.elbowMotorAngleValue = new double[dataArraySize];
rightArm.current = 0;
return 0;
}
bool incDataStruct()
{
int tmpInt;
string tmpString;
double* tmpArrayPan[dataArraySize];
double* tmpArrayTilt[dataArraySize];
double* tmpArrayVersion[dataArraySize];
double* tmpArrayRollMotor[dataArraySize];
double* tmpArrayPitchMotor[dataArraySize];
double* tmpArrayYawMotor[dataArraySize];
double* tmpArrayElbowMotor[dataArraySize];
memcpy(tmpArrayPan, rightArm.panValue, dataArraySize);
memcpy(tmpArrayTilt, rightArm.tiltValue, dataArraySize);
memcpy(tmpArrayVersion, rightArm.versionValue, dataArraySize);
memcpy(tmpArrayRollMotor, rightArm.rollMotorAngleValue, dataArraySize);
memcpy(tmpArrayPitchMotor, rightArm.pitchMotorAngleValue, dataArraySize);
memcpy(tmpArrayYawMotor, rightArm.yawMotorAngleValue, dataArraySize);
memcpy(tmpArrayElbowMotor, rightArm.elbowMotorAngleValue, dataArraySize);
// dataArraySize = dataArraySize * 2;
// tmpString.panValue = new double[dataArraySize];
// tmpString.tiltValue = new double[dataArraySize];
// tmpString.versionValue = new double[dataArraySize];
// tmpString.motorAngleValue = new double[dataArraySize];
// memcpy(tmpString.panValue, tmpArrayPan, halfNumber(dataArraySize) );
// memcpy(tmpString.tiltValue, tmpArrayTilt, halfNumber(dataArraySize) );
// memcpy(tmpString.versionValue, tmpArrayVersion, halfNumber(dataArraySize) );
// memcpy(tmpString.motorAngleValue, tmpArrayMotor, halfNumber(dataArraySize) );
return 0;
}
double halfNumber(double num)
{
double tmpNum = num / 2;
return tmpNum;
}
bool getValues()
{
iGaze->getFixationPoint(gazePoint);
//cout << "Gaze Point: " << gazePoint.toString() <<endl;
iGaze->getAngles(eyeAngles);
//cout << "Eye Angles: " << eyeAngles.toString() <<endl <<endl;
currentPos.resize(16);
encs -> getEncoders(currentPos.data());
}
bool lookAtPoint()
{
q0 = endEffector.subVector(0,2);
iGaze->lookAtFixationPoint(q0);
return 0;
}
bool addValuesToStruct(Vector eye,Vector motor)
{
int k = rightArm.current;
rightArm.panValue[k] = eye[0];
rightArm.tiltValue[k] = eye[1];
rightArm.versionValue[k] = eye[2];
rightArm.rollMotorAngleValue[k] = motor[0];
rightArm.pitchMotorAngleValue[k] = motor[1];
rightArm.yawMotorAngleValue[k] = motor[2];
rightArm.elbowMotorAngleValue[k] = motor[3];
k++;
rightArm.current = k;
}
bool checkMotionStop(bool stop)
{
bool* tmpbool = &stop;
iGaze->checkMotionDone(tmpbool);
while(!stop)
{
iGaze->checkMotionDone(tmpbool);
Time::delay(0.2);
}
return tmpbool;
}
bool displayStruct()
{
int k = rightArm.current;
double tmpValues[7];
k--;
while(k>=0)
{
tmpValues[0] = rightArm.panValue[k];
tmpValues[1] = rightArm.tiltValue[k];
tmpValues[2] = rightArm.versionValue[k];
tmpValues[3] = rightArm.rollMotorAngleValue[k];
tmpValues[4] = rightArm.pitchMotorAngleValue[k];
tmpValues[5] = rightArm.yawMotorAngleValue[k];
tmpValues[6] = rightArm.elbowMotorAngleValue[k];
cout<<"For data " << k << ", values of: ";
for(int i =0;i<7;i++)
{
printf("%3.2f ",tmpValues[i]);
}
cout <<endl;
k--;
}
return 0;
}