-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResetEntity.cpp
166 lines (113 loc) · 4.55 KB
/
ResetEntity.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
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
#include "ResetEntity.h"
#include "ControlPosition.h"
bool resetEntityPosition(SimObj *entity, Vector3d desiredPosition){
Vector3d currentPos;
entity->getPosition(currentPos);
Vector3d differenceInPos;
differenceInPos.x(desiredPosition.x() - currentPos.x());
differenceInPos.y(desiredPosition.y() - currentPos.y());
differenceInPos.z(desiredPosition.z() - currentPos.z());
double* ptr1 = NULL;
// cout << "The desiredPosition = " << desiredPosition.x() << " , " << desiredPosition.z() << endl ;
ptr1 = controlPosition(desiredPosition, currentPos, 4.0,0.2, 1.2);
// cout << "The velocity should be applied on tool for position reset is " << ptr1[0] << " , " << ptr1[1] << endl;
double xVel = ptr1[0];
double yVel = ptr1[1];
// cout << "xVel = " << xVel << endl;
// cout << "yVel = " << yVel << endl;
entity->setLinearVelocity( xVel , 0, yVel );
// Vector3d currentLinearVelocity;
// entity->getLinearVelocity(currentLinearVelocity);
// cout << "currentLinearVelocity = " << currentLinearVelocity.x() << " , " << currentLinearVelocity.z() << endl;
// LOG_MSG((" current entity pos is : %f %f %f ", currentPos.x(), currentPos.y(), currentPos.z() ));
if ( abs(differenceInPos.x()) < 0.1 && abs(differenceInPos.z()) < 0.1)
{
// LOG_MSG((" Tool reset at : %f %f %f ", currentPos.x(), currentPos.y(), currentPos.z() ));
// LOG_MSG (("The difference in position is: %f, %f, %f ", differenceInPos.x(), differenceInPos.y(), differenceInPos.z() )) ;
differenceInPos.set(0,0,0);
// cout << "The entity is reset" << endl;
return true;
}
}
void maintainOrientationOfTool(SimObj * entity, Rotation initialToolRot)
{
double torque;
Vector3d angularVel;
entity->getAngularVelocity(angularVel);
if ( abs(angularVel.y()) > 0.1 )
{
// LOG_MSG((" Current angular Velocity is : %f %f %f ", angularVel.x(), angularVel.y(), angularVel.z() ));
double* ptr1 = NULL;
ptr1 = controlAngularVelocity(angularVel, 10.0, 0, 8.0);
torque = ptr1[0] * 10000;
// torque = ptr1[0] * 12000 ;
// cout << "The torque applied for controlling angular velocity is " << torque << " N. m" << endl;
entity->addTorque( 0 , torque, 0);
}
Rotation currentToolRot;
entity->getRotation(currentToolRot);
double *ptrTool = NULL;
ptrTool = controlRotationThroughout(initialToolRot, currentToolRot, 20.0, 0.0, 20.0);
torque = ptrTool[1] * 10000 ;
// cout << "The torque applied for controlling the rotation = " << torque << endl;
entity->addTorque(0, torque,0);
}
bool resetEntityOrientation(SimObj *entity, Rotation goalRotation){
double *ptrTool = NULL;
double torque;
ptrTool = controlRotation(entity, goalRotation, 20.0, 0.4, 20.0);
// cout << "The difference in entity orientation about y axis is " << ptrTool[3] << endl;
// cout << ptrTool[1] << endl;
torque = ptrTool[1] * 10000 ;
// cout << " torque = " << torque << endl;
entity->addTorque(0, torque, 0);
if ( abs(ptrTool[3]) < 0.05)
{
return true;
}
}
bool resetRandomTargetOrientation(SimObj *entity){
double *ptrTool = NULL;
double torque;
Rotation currentRot;
entity->getRotation(currentRot);
ptrTool = reachZeroPose(entity, currentRot, 4.0, 0.1, 1.2);
// cout << "The difference in entity orientation about y axis is " << ptrTool[3] << endl;
// cout << ptrTool[1] << endl;
torque = ptrTool[1] * 100 ;
// cout << " torque = " << torque << endl;
entity->addTorque(0, torque, 0);
if ( abs(ptrTool[3]) < 0.05)
{
cout << " The entity is set to a new pose" << endl;
return true;
// exit(0);
}
}
float randomFloat(float min, float max) {
static bool init = false;
if (!init) {
srand(time(NULL));
init = true;
}
return (max - min) * ((((float) rand()) / (float) RAND_MAX)) + min ;
}
bool newEntityPose(SimObj *entity, Rotation initToolRotation, double randomStep)
{
double *ptrTool = NULL;
double torque;
// entity->addTorque(0, 10000, 0);
// ptrTool = controlRotation(entity, initToolRotation, 1.0, 0.4, 1.2);
ptrTool = reachRotation(entity, initToolRotation, randomStep, 20, 0, 20);
// cout << "The difference in entity orientation about y axis is " << ptrTool[3] << endl;
// cout << ptrTool[1] << endl;
torque = ptrTool[1] * 1000 ;
// cout << " torque = " << torque << endl;
entity->addTorque(0, torque, 0);
if ( abs(ptrTool[3]) < 0.1)
{
cout << " The entity is set to a new pose" << endl;
return true;
// exit(0);
}
}