-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTarget1YourService.java
More file actions
294 lines (244 loc) · 9.97 KB
/
Target1YourService.java
File metadata and controls
294 lines (244 loc) · 9.97 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
package jp.jaxa.iss.kibo.rpc.sampleapk;
import android.graphics.Bitmap;
import android.util.Log;
import org.opencv.core.Mat;
import java.util.Arrays;
import java.util.List;
import gov.nasa.arc.astrobee.Kinematics;
import gov.nasa.arc.astrobee.Result;
import gov.nasa.arc.astrobee.types.Point;
import gov.nasa.arc.astrobee.types.Quaternion;
import jp.jaxa.iss.kibo.rpc.api.KiboRpcService;
/**
* Class meant to handle commands from the Ground Data System and execute them in Astrobee
*/
public class YourService extends KiboRpcService {
final int LOOP_MAX=5;
final String TAG = this.getClass().getSimpleName();
@Override
protected void runPlan1(){
// the mission starts
api.startMission();
int loop_counter = 0;
// while (true){
// // get the list of active target id
//
// /* ************************************************ */
// /* write your own code and repair the ammonia leak! */
// /* ************************************************ */
//
// // get remaining active time and mission time
// List<Long> timeRemaining = api.getTimeRemaining();
//
// // check the remaining milliseconds of mission time
// if (timeRemaining.get(1) < 60000){
// break;
// }
//
// loop_counter++;
// if (loop_counter == 2){
// break;
// }
// }
List<Integer> list = api.getActiveTargets();
Log.i(TAG, "active targets: " + Arrays.toString(list.toArray()));
// move to a point
Point point = new Point(10.4d, -10.2d, 4.47d);
Quaternion quaternion = new Quaternion(0f, 0f, 0f, 1f);
moveAstrobee(point, quaternion, 'A', true);
point = new Point(10.6d, -10.0d, 5.2988d);
quaternion = new Quaternion(0f, 0f, 0f, 1f);
moveAstrobee(point, quaternion, 'A', true);
point = new Point(11.1d, -9.5d, 5.2988d);
moveAstrobee(point, quaternion, 'A', true);
point = new Point(11.2736d, -9.5d, 5.2988d);
quaternion = new Quaternion(0f, 0f, -0.707f, 0.707f);
moveAstrobee(point, quaternion, 'A',true);
// irradiate the laser
api.laserControl(true);
//api.laserControl(false);
//api.laserControl(true);
// try {
// Thread.sleep(1000);
// }catch (InterruptedException e){
// Thread.currentThread().interrupt();
// }
Bitmap bmpimage = api.getBitmapNavCam();
api.saveBitmapImage(bmpimage,"3_target1Laserbmp.jpg");
// get a camera image
Mat image = api.getMatNavCam();
// take active target snapshots
int target_id = 0;
//target_id = api.getActiveTargets().iterator().next();
Log.i(TAG, "target_id= " + target_id);
api.takeTargetSnapshot(target_id);
api.saveMatImage(image, "target1_test");
//api.laserControl(false);
// turn on the front flash light
api.flashlightControlFront(0.05f);
// get QR code content
String mQrContent = yourMethod();
// turn off the front flash light
api.flashlightControlFront(0.00f);
// notify that astrobee is heading to the goal
//api.notifyGoingToGoal();
/* ********************************************************** */
/* write your own code to move Astrobee to the goal positiion */
/* ********************************************************** */
// send mission completion
//api.reportMissionCompletion(mQrContent);
}
@Override
protected void runPlan2(){
// write your plan 2 here
}
@Override
protected void runPlan3(){
// write your plan 3 here
}
// You can add your method
private String yourMethod(){
return "your method";
}
// private boolean move(Point point1, Quaternion quat1, Boolean print, int tries){
// Result result = api.moveTo(point1, quat1, print);
// int i=0;
// while(!result.hasSucceeded() && i<tries){
// result = api.moveTo(point1, quat1, print);
// i++;
// }
// return result.hasSucceeded();
// }
protected Kinematics.Confidence moveAstrobee(Point point, Quaternion quaternion, char moveType, Boolean printRobotPosition)
{
//Qua_x 0.7071068 Astrobee spin right
//QUa_x -0.7071068 Astrobee spin left
//Qua_y 1 Astrobee look up
//Qua_y -1 Astrobee look down
//Qua_w 1 Astrobee turn right
//Qua_W -1 Astrobee turn left
final boolean DO_FOR_R = false;// Do not repeatedly try for relative move
Result result;
double dX, dY, dZ;
float dOX,dOY,dOZ,dOW;
Point currentPoint ;
Point startPoint ;
Point targetPoint ;
Quaternion currentQuaternion1;
Kinematics.Confidence currentPositionConfidence;
Kinematics kinematics = null;
currentPositionConfidence = Kinematics.Confidence.GOOD;
final double [] kIZ2_min_data = {9.5, -10.5, 4.02};
final double [] kIZ2_max_data = {10.5, -9.6, 4.8};
final double [] kIZ1_min_data = {10.3, -10.2, 4.32};
final double [] kIZ1_max_data = {11.55 ,-6.0, 5.57};
final Vector kIZ2_min = new Vector(kIZ2_min_data);
final Vector kIZ2_max = new Vector(kIZ2_max_data);
final Vector kIZ1_min = new Vector(kIZ1_min_data);
final Vector kIZ1_max = new Vector(kIZ1_max_data);
Vector moveToPoint = new Vector(point);
if(moveToPoint.distanceTo(kIZ1_max)<0.025){
point = moveToPoint.minusScalar(0.025).toPoint();
Log.i(TAG,"Restricted movement due to KIZ 1 max violation");
}
if(kIZ1_min.distanceTo(moveToPoint)<0.025){
point = moveToPoint.minusScalar(-0.025).toPoint();
Log.i(TAG,"Restricted movement due to KIZ 1 min violation");
}
startPoint = api.getRobotKinematics().getPosition();
currentPoint = startPoint;
if(moveType=='R') {
targetPoint = new Point(startPoint.getX()+ point.getX(), startPoint.getY()+point.getY(),
startPoint.getZ()+point.getZ());
result = api.relativeMoveTo(point, quaternion, printRobotPosition);
}else{
targetPoint=point;
result = api.moveTo(point, quaternion, printRobotPosition);
Log.i(TAG,"Moved");
}
int noOfTry = 0;
if(result.hasSucceeded()){
kinematics = api.getRobotKinematics();
if(kinematics.getConfidence() == Kinematics.Confidence.GOOD){
currentPoint = kinematics.getPosition();
if(currentPoint.getX() != point.getX() ||
currentPoint.getY() != point.getY() ||
currentPoint.getZ() != point.getZ()){
currentPositionConfidence = Kinematics.Confidence.POOR;
}
}
}
while((!result.hasSucceeded() || currentPositionConfidence == Kinematics.Confidence.POOR) && noOfTry < LOOP_MAX ){
if(moveType=='R') {
if( DO_FOR_R == true) {
point = new Point(targetPoint.getX() - currentPoint.getX(), targetPoint.getY() - currentPoint.getY(),
targetPoint.getZ() - currentPoint.getZ());
result = api.relativeMoveTo(point, quaternion, printRobotPosition);
}
}else{
// point = new Point(point.getX()-0.015f,point.getY()-0.015f,point.getZ()-0.015f);
result = api.moveTo(point, quaternion, printRobotPosition);
Log.i(TAG,"Moving Loop " + noOfTry);
}
if(result.hasSucceeded()){
kinematics = api.getRobotKinematics();
if(kinematics.getConfidence() == Kinematics.Confidence.GOOD){
currentPoint = kinematics.getPosition();
if(currentPoint.getX() != point.getX() ||
currentPoint.getY() != point.getY() ||
currentPoint.getZ() != point.getZ()){
currentPositionConfidence = Kinematics.Confidence.POOR;
}
}
}
++noOfTry;
}
return (Kinematics.Confidence.GOOD);
}
/************************************************************/
/* computeQuaternion()
/* Uses global values of yaw, pitch, roll to compute the
/* quaternion.
/* rotation x - roll
/* y - pitch
/* z - yaw
/************************************************************/
protected Quaternion computeQuaternion(double roll,double pitch, double yaw)
{
//Precompute sine and cosine values.
//Input Euler Angles are in degrees
double su = (double) Math.sin(roll *Math.PI/360);
double sv = (double)Math.sin(pitch*Math.PI/360);
double sw = (double)Math.sin(yaw *Math.PI/360);
double cu = (double)Math.cos(roll *Math.PI/360);
double cv = (double)Math.cos(pitch*Math.PI/360);
double cw = (double)Math.cos(yaw *Math.PI/360);
//Quaternion
float q0 = 1.0f;
float q1 = 0.0f;
float q2 = 0.0f;
float q3 = 0.0f;
q0 = (float)(cu*cv*cw + su*sv*sw);
q1 = (float)(su*cv*cw - cu*sv*sw);
q2 = (float)(cu*sv*cw + su*cv*sw);
q3 = (float)(cu*cv*sw - su*sv*cw);
//Display Quaternion, rounded to three sig. figs.
q0 = (float)Math.floor(q0*10000)/10000;
q1 = (float)Math.floor(q1*10000)/10000;
q2 = (float)Math.floor(q2*10000)/10000;
q3 = (float)Math.floor(q3*10000)/10000;
return(new Quaternion (q1,q2,q3,q0));
}
protected static void wait(int sec)
{
int ms = sec* 1000;
try
{
Thread.sleep(ms);
}
catch(InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
}