00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "GT2004HeadControl.h"
00010 #include "Tools/Math/Common.h"
00011 #include "Tools/Math/Geometry.h"
00012 #include "Tools/FieldDimensions.h"
00013
00014 void GT2004HeadControlBasicBehaviors::registerBasicBehaviors(Xabsl2Engine& engine)
00015 {
00016 engine.registerBasicBehavior(basicBehaviorBeginBallSearchAtBallPositionSeen);
00017 engine.registerBasicBehavior(basicBehaviorBeginBallSearchAtBallPositionPropagated);
00018 engine.registerBasicBehavior(basicBehaviorBeginBallSearchAtBallPositionCommunicated);
00019 engine.registerBasicBehavior(basicBehaviorLookAroundAtSeenBall);
00020 engine.registerBasicBehavior(basicBehaviorOtherHeadMovements);
00021 engine.registerBasicBehavior(basicBehaviorFindBall);
00022 engine.registerBasicBehavior(basicBehaviorLookAtBall);
00023 engine.registerBasicBehavior(basicBehaviorLookAtCloseLandmark);
00024 engine.registerBasicBehavior(basicBehaviorLookAtBallAndClosestLandmark);
00025 engine.registerBasicBehavior(basicBehaviorReturnToBall);
00026 engine.registerBasicBehavior(basicBehaviorDirectedScanForLandmarks);
00027 engine.registerBasicBehavior(basicBehaviorScanBackToBall);
00028 engine.registerBasicBehavior(basicBehaviorScanAwayFromBall);
00029 engine.registerBasicBehavior(basicBehaviorGrabBall);
00030 engine.registerBasicBehavior(basicBehaviorReleaseBall);
00031 engine.registerBasicBehavior(basicBehaviorWaitForGrab);
00032 engine.registerBasicBehavior(basicBehaviorSearchForBallLeft);
00033 engine.registerBasicBehavior(basicBehaviorSearchForBallRight);
00034 }
00035
00036 void GT2004BasicBehaviorLookAtBall::execute()
00037 {
00038
00039 headControl.useCommunicatedBall = true;
00040
00041 double neckTilt, headPan, headTilt;
00042 headControl.getLookAtBallAngles(ballModel.seen, neckTilt, headPan, headTilt);
00043 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00044 }
00045
00046
00047 void GT2004BasicBehaviorSearchForBallLeft::execute()
00048 {
00049 double neckTilt, headPan, headTilt;
00050 if ((!basicBehaviorWasActiveDuringLastExecutionOfEngine) || headPathPlanner.isLastPathFinished())
00051 {
00052 headControl.searchForBallLeft();
00053 }
00054 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00055 headControl.setJoints(neckTilt, headPan, headTilt);
00056 }
00057
00058 void GT2004BasicBehaviorSearchForBallRight::execute()
00059 {
00060 double neckTilt, headPan, headTilt;
00061 if ((!basicBehaviorWasActiveDuringLastExecutionOfEngine) || headPathPlanner.isLastPathFinished())
00062 {
00063 headControl.searchForBallRight();
00064 }
00065 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00066 headControl.setJoints(neckTilt, headPan, headTilt);
00067 }
00068
00069 void GT2004BasicBehaviorLookAroundAtSeenBall::execute()
00070 {
00071 double neckTilt, headPan, headTilt;
00072
00073 if ((!basicBehaviorWasActiveDuringLastExecutionOfEngine) || headPathPlanner.isLastPathFinished())
00074 {
00075 Vector3<double> leftDown,
00076 rightDown,
00077 leftTop,
00078 rightTop;
00079
00080 Vector3<double> ballPosition3d;
00081 ballPosition3d.x = (double) ballModel.seen.x;
00082 ballPosition3d.y = (double) ballModel.seen.y;
00083 ballPosition3d.z = 0;
00084 Vector2<double> toBall = ballModel.seen - robotPose.translation;
00085
00086
00087
00088
00089
00090 Vector2<int> cameraImageOffset(0,0);
00091
00092 double neckTilt,headPan,headTilt;
00093 headControl.simpleLookAtPointOnField(ballPosition3d,cameraImageOffset,neckTilt,headPan,headTilt);
00094 Vector3<double> ballAngles (neckTilt,headPan,headTilt);
00095
00096
00097
00098 leftDown = ballAngles;
00099 rightDown = leftDown;
00100 leftTop = leftDown;
00101 rightDown = leftDown;
00102
00103 leftDown.y += 0.6;
00104
00105
00106 rightDown.y -= 0.6;
00107
00108
00109 leftTop.y += 0.6;
00110 leftTop.x += 0.2;
00111
00112 rightTop.y -= 0.6;
00113 rightTop.x += 0.2;
00114
00115 Vector3<double> points[]={leftDown,
00116 rightDown,
00117 rightTop,
00118 leftTop};
00119 long durations[] = {100,100,100,100};
00120
00121 headPathPlanner.init(points,durations,(sizeof(points)/sizeof(Vector3<double>)),false);
00122
00123 }
00124 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00125 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00126
00127 }
00128
00129 void GT2004BasicBehaviorLookAtCloseLandmark::execute()
00130 {
00131 double neckTilt, headPan, headTilt;
00132 int closest = headControl.calculateClosestLandmark(headPathPlanner.lastHeadPan, 0);
00133
00134
00135 if (!basicBehaviorWasActiveDuringLastExecutionOfEngine)
00136 {
00137 panCount = 0;
00138 lastScanWasLeft = (headPathPlanner.lastHeadPan < 0);
00139 }
00140
00141
00142
00143
00144 if (closest == -1 && panCount < 2)
00145 {
00146 OUTPUT (idText, text, "Looking at closest landmark...");
00147 headPathPlanner.getAngles (neckTilt, headPan, headTilt);
00148
00149 if (headPan > headControl.headMiddleLeft.y)
00150 {
00151 lastScanWasLeft = true;
00152 panCount++;
00153 headControl.setJoints (headControl.headRight.x, headControl.headRight.y, headControl.headRight.z);
00154 }
00155 else if (headPan > headControl.headMiddleRight.y)
00156 {
00157 lastScanWasLeft = false;
00158 panCount++;
00159 headControl.setJoints (headControl.headLeft.x, headControl.headLeft.y, headControl.headLeft.z);
00160 }
00161 else if (!lastScanWasLeft)
00162 headControl.setJoints (headControl.headLeft.x, headControl.headLeft.y, headControl.headLeft.z);
00163 else
00164 headControl.setJoints (headControl.headRight.x, headControl.headRight.y, headControl.headRight.z);
00165
00166 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00167 closest = headControl.calculateClosestLandmark (headPan, 0);
00168 }
00169
00170 headControl.aimAtLandmark(closest, neckTilt, headPan, headTilt);
00171
00172 headControl.setJoints(neckTilt, headPan, headTilt, 4.0);
00173
00174 CIRCLE(headControlField,
00175 targetPointOnLandmark[closest].position.x, targetPointOnLandmark[closest].position.y, 100,
00176 2, 0, Drawings::red);
00177 DEBUG_DRAWING_FINISHED(headControlField);
00178 }
00179
00180
00181 void GT2004BasicBehaviorDirectedScanForLandmarks::execute()
00182 {
00183 double neckTilt, headPan, headTilt;
00184
00185
00186 if (!basicBehaviorWasActiveDuringLastExecutionOfEngine)
00187 {
00188 leftOrRight *= -1;
00189 lastScanWasLeft = (leftOrRight > 0);
00190 }
00191
00192
00193
00194
00195
00196
00197
00198 int closest = headControl.calculateClosestLandmark(headPathPlanner.lastHeadPan + leftOrRight*.1, leftOrRight);
00199
00200
00201 if (!basicBehaviorWasActiveDuringLastExecutionOfEngine)
00202 {
00203 currentLandmark = closest;
00204 nextLandmark = -1;
00205 waitSomeBeforeLookingAtNextLandmark = 0;
00206 }
00207
00208
00209
00210
00211 if (closest != nextLandmark)
00212 {
00213 if ((nextLandmark != -1) || (closest != -1))
00214 {
00215 nextLandmark = closest;
00216 waitSomeBeforeLookingAtNextLandmark = 1;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226 }
00227
00228
00229
00230
00231 if (waitSomeBeforeLookingAtNextLandmark)
00232 {
00233 CIRCLE(headControlField,
00234 targetPointOnLandmark[currentLandmark].position.x, targetPointOnLandmark[currentLandmark].position.y, 100,
00235 2, 0, Drawings::red);
00236 waitSomeBeforeLookingAtNextLandmark++;
00237 }
00238
00239
00240
00241 if (waitSomeBeforeLookingAtNextLandmark > 15)
00242 {
00243 currentLandmark = nextLandmark;
00244 waitSomeBeforeLookingAtNextLandmark = -1;
00245 }
00246
00247 CIRCLE(headControlField,
00248 targetPointOnLandmark[currentLandmark].position.x, targetPointOnLandmark[currentLandmark].position.y, 80,
00249 2, 0, Drawings::yellow);
00250
00251 DEBUG_DRAWING_FINISHED(headControlField);
00252
00253
00254 double angleToCurrent = Geometry::angleTo(robotPose, Vector2<double>(targetPointOnLandmark[currentLandmark].position.x, targetPointOnLandmark[currentLandmark].position.y));
00255 if((closest == -1) ||
00256 (fabs(angleToCurrent) > headControl.jointLimitHeadPanP + cameraInfo.openingAngleWidth/2))
00257 {
00258 nextLandmarkIsWithinReach = false;
00259 }
00260 else
00261 {
00262 nextLandmarkIsWithinReach = true;
00263 }
00264
00265 if (currentLandmark != -1)
00266 headControl.aimAtLandmark(currentLandmark, neckTilt, headPan, headTilt);
00267
00268 headControl.setJoints(neckTilt, headPan, headTilt, 4);
00269 }
00270
00271
00272
00273 void GT2004BasicBehaviorLookAtBallAndClosestLandmark::execute()
00274 {
00275 double neckTiltBall, headPanBall, headTiltBall;
00276 headControl.getLookAtBallAngles(ballModel.seen, neckTiltBall, headPanBall, headTiltBall);
00277
00278 double neckTiltLM, headPanLM, headTiltLM;
00279 int closest = headControl.calculateClosestLandmark(Geometry::angleTo(robotPose, ballModel.seen));
00280 if (closest != -1)
00281 {
00282 headControl.simpleLookAtPointOnField(
00283 targetPointOnLandmark[closest].position,
00284 Vector2<int>(0, 0),
00285 neckTiltLM, headPanLM, headTiltLM);
00286 }
00287 else
00288 {
00289
00290 }
00291
00292
00293 double openingAngleOfBall = tan(2*ballRadius/((ballModel.seen-robotPose.translation).abs()));
00294 Vector2<double> landmarkInXYPlane(targetPointOnLandmark[closest].position.x, targetPointOnLandmark[closest].position.y);
00295 double openingAngleWidthOfLandmark = tan(2*targetPointOnLandmark[closest].width/((landmarkInXYPlane-robotPose.translation).abs()));
00296
00297
00298 double panDiff = headPanBall - headPanLM;
00299 double tiltDiff = headTiltBall - headTiltLM;
00300
00301
00302
00303 double minAngle = .2, maxAngle = 1.2;
00304 Range<double> angleRange(minAngle, maxAngle);
00305 double panDiffTmp = angleRange.limit(panDiff);
00306
00307
00308
00309
00310 double adjustmentWeight = 1-(panDiffTmp-minAngle)/(maxAngle-minAngle);
00311 Range<double> weightRange(0,1);
00312 adjustmentWeight = weightRange.limit(adjustmentWeight);
00313
00314
00315 double minBClose = 350, maxBClose = 700;
00316 Range<double> ballCloseRange(minBClose, maxBClose);
00317 double ballIsClose = (Geometry::fieldCoord2Relative(robotPose, ballModel.seen)).abs();
00318 ballIsClose = ballCloseRange.limit(ballIsClose);
00319 ballIsClose = (ballIsClose - minBClose)/(maxBClose-minBClose);
00320
00321 adjustmentWeight *= ballIsClose;
00322
00323
00324 if (fabs(panDiff) + openingAngleWidthOfLandmark > cameraInfo.openingAngleWidth/2)
00325 {
00326 double maxPanAdjustment = cameraInfo.openingAngleWidth/2 - 2.5*openingAngleOfBall;
00327 double panAdjustment = -panDiff+sgn(panDiff)*(cameraInfo.openingAngleWidth/2.5-openingAngleWidthOfLandmark);
00328 if (fabs(headPanLM) > 0.7*headControl.jointLimitHeadPanP)
00329 panAdjustment = 0;
00330
00331 panAdjustment = Range<double>::Range(-maxPanAdjustment,maxPanAdjustment).limit(panAdjustment);
00332
00333 headPanBall += panAdjustment*adjustmentWeight;
00334 }
00335
00336
00337
00338
00339
00340 if (headTiltLM > headTiltBall)
00341 if (headTiltLM - headTiltBall > cameraInfo.openingAngleHeight/2)
00342 {
00343 double maxTiltAdjustment = cameraInfo.openingAngleHeight/2 - openingAngleOfBall;
00344 if(maxTiltAdjustment < 0)
00345 maxTiltAdjustment = 0;
00346 double tiltAdjustment = -tiltDiff-cameraInfo.openingAngleHeight/2.5;
00347 if (fabs(headPanLM) > 0.7*headControl.jointLimitHeadPanP)
00348 tiltAdjustment = 0;
00349 Range<double> tiltClipping(0, maxTiltAdjustment);
00350 tiltAdjustment = tiltClipping.limit(tiltAdjustment);
00351
00352
00353 headTiltBall += tiltAdjustment*adjustmentWeight;
00354 }
00355
00356 headControl.setJoints(neckTiltBall, headPanBall, headTiltBall);
00357
00358 LINE(headControlField,
00359 robotPose.translation.x, robotPose.translation.y,
00360 robotPose.translation.x + 2000*cos(headPanBall+robotPose.rotation), robotPose.translation.y + 2000*sin(headPanBall+robotPose.rotation),
00361 20, 0, Drawings::red);
00362
00363 CIRCLE(headControlField,
00364 targetPointOnLandmark[closest].position.x, targetPointOnLandmark[closest].position.y, 100,
00365 2, 0, Drawings::red);
00366 DEBUG_DRAWING_FINISHED(headControlField);
00367 }
00368
00369 void GT2004BasicBehaviorBeginBallSearchAtBallPositionSeen::execute()
00370 {
00371 double neckTilt, headPan, headTilt;
00372 if ((!basicBehaviorWasActiveDuringLastExecutionOfEngine) || headPathPlanner.isLastPathFinished())
00373 {
00374
00375
00376 headControl.beginBallSearchAt((Vector2<double>) ballModel.seen);
00377 }
00378 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00379 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00380
00381 }
00382
00383 void GT2004BasicBehaviorBeginBallSearchAtBallPositionPropagated::execute()
00384 {
00385 double neckTilt, headPan, headTilt;
00386 if ((!basicBehaviorWasActiveDuringLastExecutionOfEngine) || headPathPlanner.isLastPathFinished())
00387 {
00388
00389
00390 headControl.beginBallSearchAt((Vector2<double>) ballModel.propagated);
00391 }
00392 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00393 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00394
00395 }
00396
00397 void GT2004BasicBehaviorBeginBallSearchAtBallPositionCommunicated::execute()
00398 {
00399 double neckTilt, headPan, headTilt;
00400 if ((!basicBehaviorWasActiveDuringLastExecutionOfEngine) || headPathPlanner.isLastPathFinished())
00401 {
00402
00403
00404 headControl.beginBallSearchAt((Vector2<double>) ballModel.communicated);
00405 }
00406 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00407 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00408
00409 }
00410
00411
00412 void GT2004BasicBehaviorFindBall::execute()
00413 {
00414 double neckTilt, headPan, headTilt;
00415 bool headPanSide=headControl.headPanIsLeft();
00416 int jumped=0;
00417
00418 if ((!basicBehaviorWasActiveDuringLastExecutionOfEngine) || headPathPlanner.isLastPathFinished())
00419 {
00420 Vector3<double> leftRightSweepTop,
00421 leftRightSweepBottom,
00422 halfLeftRightSweep,
00423 halfLeftRightSweepBottom;
00424
00425 if(!basicBehaviorWasActiveDuringLastExecutionOfEngine)
00426 {
00427 if (headControlMode.headControlMode == HeadControlMode::searchForBallLeft)
00428 lastScanWasLeft = false;
00429 else if (headControlMode.headControlMode == HeadControlMode::searchForBallRight)
00430 lastScanWasLeft = true;
00431 else
00432 lastScanWasLeft=!headPanSide;
00433 }
00434 if (!lastScanWasLeft)
00435 {
00436 leftRightSweepTop = headControl.headLeft;
00437 leftRightSweepBottom = headControl.headLeftDown;
00438 halfLeftRightSweep = headControl.headMiddleLeft;
00439 halfLeftRightSweepBottom = headControl.headMiddleLeftDown;
00440 }
00441 else
00442 {
00443 leftRightSweepTop = headControl.headRight;
00444 leftRightSweepBottom = headControl.headRightDown;
00445 halfLeftRightSweep = headControl.headMiddleRight;
00446 halfLeftRightSweepBottom = headControl.headMiddleRightDown;
00447 }
00448
00449 Vector3<double> points[]={headControl.headDown,
00450 headControl.headDown,
00451 halfLeftRightSweepBottom,
00452 leftRightSweepBottom,
00453 leftRightSweepTop,
00454 halfLeftRightSweep,
00455 headControl.headUp};
00456 long durations[] = {100,40,80,120,80,200,120};
00457
00458
00459
00460 Vector3<double> *ppoints = points;
00461 long *pdurations = durations;
00462
00463 while (headControl.headPositionDistanceToActualPosition(points[jumped],headPanSide)<0
00464 && jumped<3
00465 && !basicBehaviorWasActiveDuringLastExecutionOfEngine)
00466 {
00467 ppoints++;
00468 pdurations++;
00469 jumped++;
00470 }
00471
00472 headPathPlanner.init(ppoints,pdurations,(sizeof(points)/sizeof(Vector3<double>))-jumped);
00473 lastScanWasLeft = !lastScanWasLeft;
00474 }
00475 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00476 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00477 }
00478
00479 void GT2004BasicBehaviorReturnToBall::execute()
00480 {
00481 double neckTilt, headPan, headTilt;
00482 headControl.getLookAtBallAngles(ballModel.seen, neckTilt, headPan, headTilt);
00483 headControl.setJoints(neckTilt, headPan, headTilt);
00484 }
00485
00486 void GT2004BasicBehaviorScanAwayFromBall::execute()
00487 {
00488 double neckTilt, headPan, headTilt;
00489 if (!basicBehaviorWasActiveDuringLastExecutionOfEngine)
00490 {
00491 if (lastScanWasLeft)
00492 {
00493 Vector3<double> centerTop( 0, headPathPlanner.lastHeadPan-0.07, 0.25),
00494 rightTop( 0, max(-1.2,headPathPlanner.lastHeadPan-1.5),0),
00495 rightBottom( 0, max(-1.2,headPathPlanner.lastHeadPan-1.5),-0.25);
00496 Vector3<double> points[3]={centerTop,rightTop,rightBottom};
00497 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00498 }
00499 else
00500 {
00501 Vector3<double> centerTop( 0, headPathPlanner.lastHeadPan+0.07,min(headPathPlanner.lastHeadTilt+0.2,0.1)),
00502 leftTop( 0, min(1.2,headPathPlanner.lastHeadPan+1.5),0),
00503 leftBottom( 0, min(1.2,headPathPlanner.lastHeadPan+1.5),-0.25);
00504 Vector3<double> points[3]={centerTop,leftTop,leftBottom};
00505 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00506 }
00507 lastScanWasLeft = !lastScanWasLeft;
00508 }
00509
00510 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00511 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00512 }
00513
00514 void GT2004BasicBehaviorScanBackToBall::execute()
00515 {
00516 double neckTilt, headPan, headTilt;
00517 headControl.getLookAtBallAngles(ballModel.seen, neckTilt, headPan, headTilt);
00518 headControl.setJoints(neckTilt, headPan, headTilt, 4.0);
00519 }
00520
00521 void GT2004BasicBehaviorGrabBall::execute()
00522 {
00523 double neckTilt, headPan, headTilt;
00524 if(!basicBehaviorWasActiveDuringLastExecutionOfEngine)
00525 {
00526
00527 pidData.setValues(JointData::neckTilt,0x20,0x08,0x0C);
00528 pidData.setValues(JointData::headPan,0x0A,0x08,0x0C);
00529 pidData.setValues(JointData::headTilt,0x0A,0x08,0x0C);
00530
00531 Vector3<double>
00532 prepare(-0.5, 0.0, 0.37),
00533 grab( -1.0, 0.0, 0.6);
00534 Vector3<double> points[2]={prepare, grab};
00535 long durations[2]={50,50} ;
00536 headPathPlanner.init(points, durations,sizeof(points)/sizeof(Vector3<double>),false);
00537 }
00538 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00539 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00540 }
00541
00542 void GT2004BasicBehaviorReleaseBall::execute()
00543 {
00544 double neckTilt, headPan, headTilt;
00545 if(!basicBehaviorWasActiveDuringLastExecutionOfEngine)
00546 {
00547
00548 pidData.setValues(JointData::neckTilt,0x20,0x08,0x0C);
00549 pidData.setValues(JointData::headPan,0x0A,0x08,0x0C);
00550 pidData.setValues(JointData::headTilt,0x0A,0x08,0x0C);
00551
00552 Vector3<double>
00553 release(0.0, 0.0, 0.0);
00554 Vector3<double> points[1]={release};
00555 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00556 }
00557 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00558 if(!headPathPlanner.isLastPathFinished())
00559 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00560 }
00561
00562 void GT2004BasicBehaviorWaitForGrab::execute()
00563 {
00564 headControl.setJointsDirect(-0.5, 0.0, 0.37);
00565 }
00566
00567 void GT2004BasicBehaviorOtherHeadMovements::execute()
00568 {
00569 double neckTilt, headPan, headTilt;
00570 if (robotPose.getValidity()>0.5)
00571 {
00572 lastTimeOfGoodSL=SystemCall::getCurrentSystemTime();
00573 }
00574
00575 switch (headControlMode.headControlMode)
00576 {
00577 case HeadControlMode::openChallengeReset:
00578 pidData.setToDefaults();
00579 break;
00580 case HeadControlMode::openChallengeJoysickMode:
00581 pidData.setToDefaults();
00582 pidData.setValues(JointData::headPan,0,0,0);
00583 pidData.setValues(JointData::neckTilt,0,0,0);
00584 pidData.setValues(JointData::legFR1,0,0,0);
00585 pidData.setValues(JointData::legFR2,0,0,0);
00586 pidData.setValues(JointData::legFR3,0,0,0);
00587 pidData.setValues(JointData::legFL1,0,0,0);
00588 pidData.setValues(JointData::legFL2,0,0,0);
00589 pidData.setValues(JointData::legFL3,0,0,0);
00590
00591 pidData.setValues(JointData::legHR1,0,0,0);
00592 pidData.setValues(JointData::legHR2,0,0,0);
00593 pidData.setValues(JointData::legHR3,0,0,0);
00594 pidData.setValues(JointData::legHL1,0,0,0);
00595 pidData.setValues(JointData::legHL2,0,0,0);
00596 pidData.setValues(JointData::legHL3,0,0,0);
00597
00598 pidData.setValues(JointData::mouth,0,0,0);
00599 pidData.setValues(JointData::tailPan,0,0,0);
00600 pidData.setValues(JointData::tailTilt,0,0,0);
00601 break;
00602 case HeadControlMode::openChallengePullBridge:
00603 pidData.setToDefaults();
00604 pidData.setValues(JointData::headPan,0,0,0);
00605 pidData.setValues(JointData::neckTilt,0,0,0);
00606 pidData.setValues(JointData::mouth,0,0,0);
00607 headMotionRequest.tilt=153256;
00608 this->headMotionRequest.mouth = 0;
00609 break;
00610 case HeadControlMode::openChallengeTest:
00611 pidData.setToDefaults();
00612 pidData.setValues(JointData::neckTilt,0,0,0);
00613 this->headMotionRequest.mouth = -20000000;
00614 break;
00615 case HeadControlMode::openChallengeGoToBridge:
00616 pidData.setToDefaults();
00617 headControl.setJointsDirect(0.153,0,0.363,-2.0);
00618 break;
00619 case HeadControlMode::none:
00620
00621 break;
00622
00623 case HeadControlMode::lookLeft:
00624 {
00625 Vector3<double> left(-0.55, 1.6, -0.3);
00626 lastScanWasLeft = true;
00627 if(headControl.lastHeadControlMode != headControlMode.headControlMode)
00628 {
00629 Vector3<double> points[]={headControl.headDown,left};
00630 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00631 }
00632 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00633 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00634 }
00635 break;
00636
00637 case HeadControlMode::lookRight:
00638 {
00639 Vector3<double> right(-0.55, -1.6, -0.3);
00640
00641 lastScanWasLeft = false;
00642 if(headControl.lastHeadControlMode != headControlMode.headControlMode)
00643 {
00644 Vector3<double> points[]={headControl.headDown,right};
00645 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00646 }
00647 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00648 headControl.setJointsDirect(neckTilt, headPan, headTilt, 0);
00649 }
00650 break;
00651
00652 case HeadControlMode::searchForLandmarks:
00653 {
00654
00655
00656
00657
00658
00659 if(headControl.lastHeadControlMode != headControlMode.headControlMode)
00660 {
00661 if(lastScanWasLeft)
00662 {
00663 Vector3<double> points[2]={headControl.headLeft,headControl.headRight};
00664 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00665 lastScanWasLeft = !lastScanWasLeft;
00666 }
00667 else
00668 {
00669 Vector3<double> points[3]={headControl.headRight, headControl.headUp, headControl.headLeft};
00670 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00671 lastScanWasLeft = !lastScanWasLeft;
00672 }
00673 }
00674
00675 if(headPathPlanner.getAngles(neckTilt, headPan, headTilt))
00676 {
00677 if(lastScanWasLeft)
00678 {
00679 Vector3<double> points[2]={headControl.headUp,headControl.headRight};
00680 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00681 lastScanWasLeft = !lastScanWasLeft;
00682 }
00683 else
00684 {
00685 Vector3<double> points[2]={headControl.headUp, headControl.headLeft};
00686 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00687 lastScanWasLeft = !lastScanWasLeft;
00688 }
00689 }
00690 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00691 break;
00692 }
00693
00694 case HeadControlMode::searchForLandmarksHeadLow:
00695 {
00696 Vector3<double> left((bodyPosture.bodyTiltCalculatedFromLegSensors - cameraInfo.openingAngleHeight / 6.0 - .8), 1.0, 0.5);
00697 Vector3<double> right((bodyPosture.bodyTiltCalculatedFromLegSensors - cameraInfo.openingAngleHeight / 6.0 - .8), -1.0, 0.5);
00698 Vector3<double> center((bodyPosture.bodyTiltCalculatedFromLegSensors - cameraInfo.openingAngleHeight / 2.0 - .2), 0.0, 0.5);
00699
00700 if(headControl.lastHeadControlMode != headControlMode.headControlMode)
00701 {
00702 if(lastScanWasLeft)
00703 {
00704 Vector3<double> points[2]={left, right};
00705 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 150);
00706 lastScanWasLeft = !lastScanWasLeft;
00707 }
00708 else
00709 {
00710 Vector3<double> points[3]={right, center, left};
00711 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 150);
00712 lastScanWasLeft = !lastScanWasLeft;
00713 }
00714 }
00715
00716 if(headPathPlanner.getAngles(neckTilt, headPan, headTilt))
00717 {
00718 if(lastScanWasLeft)
00719 {
00720 Vector3<double> points[2]={center, right};
00721 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 150);
00722 lastScanWasLeft = !lastScanWasLeft;
00723 }
00724 else
00725 {
00726 Vector3<double> points[2]={center, left};
00727 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 150);
00728 lastScanWasLeft = !lastScanWasLeft;
00729 }
00730 }
00731 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00732 break;
00733 }
00734
00735 case HeadControlMode::lookStraightAhead:
00736 headControl.setJointsDirect(0.0, 0.0, 0.0, 0.05);
00737 break;
00738
00739 case HeadControlMode::lookTowardOpponentGoal:
00740 headControl.setJointsDirect(0.0, -robotPose.rotation, 0.0, 0.0);
00741 break;
00742
00743 case HeadControlMode::lookBetweenFeet:
00744 headControl.setJointsDirect(-1.0, 0.0, 0.0);
00745 break;
00746
00747 case HeadControlMode::lookToStars:
00748 headControl.setJoints(headControl.jointLimitNeckTiltP, 0.0, headControl.jointLimitHeadTiltP, 0, -.7);
00749 break;
00750 case HeadControlMode::lookParallelToGround:
00751 if (bodyPosture.bodyTiltCalculatedFromAccelerationSensors>0)
00752 headControl.setJoints(0.0, 0.0, bodyPosture.bodyTiltCalculatedFromAccelerationSensors);
00753 else
00754 headControl.setJoints(bodyPosture.bodyTiltCalculatedFromAccelerationSensors, 0.0, 0.0);
00755 break;
00756
00757 case HeadControlMode::direct:
00758 if (headPathPlanner.isLastPathFinished())
00759 {
00760 Vector3<double> point((double )headControlMode.directTilt/1000000.0,(double )headControlMode.directPan/1000000.0,(double )headControlMode.directRoll/1000000.0);
00761 Vector3<double> points[1]={point};
00762 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 2000);
00763 }
00764 headPathPlanner.getAngles(neckTilt, headPan, headTilt);
00765 headControl.setJointsDirect(neckTilt, headPan, headTilt);
00766 break;
00767
00768 case HeadControlMode::stayAsForced:
00769 {
00770 const double neckTiltTolerance = 0.06;
00771 const double headPanTolerance = 0.06;
00772 const double headTiltTolerance = 0.05;
00773
00774 double neckTiltDiff = sensorDataBuffer.lastFrame().data[SensorData::neckTilt] - headMotionRequest.tilt;
00775 double headPanDiff = sensorDataBuffer.lastFrame().data[SensorData::headPan] - headMotionRequest.pan;
00776 double headTiltDiff = sensorDataBuffer.lastFrame().data[SensorData::headTilt] - headMotionRequest.roll;
00777
00778 if (neckTiltDiff > neckTiltTolerance)
00779 {
00780 headMotionRequest.tilt += (long)(neckTiltDiff-neckTiltTolerance);
00781 }
00782 else if (neckTiltDiff < -neckTiltTolerance)
00783 {
00784 headMotionRequest.tilt += (long)(neckTiltDiff+neckTiltTolerance);
00785 }
00786
00787 if (headPanDiff > headPanTolerance)
00788 {
00789 headMotionRequest.pan += (long)(headPanDiff-headPanTolerance);
00790 }
00791 else if (headPanDiff < -headPanTolerance)
00792 {
00793 headMotionRequest.pan += (long)(headPanDiff+headPanTolerance);
00794 }
00795
00796 if (headTiltDiff > headTiltTolerance)
00797 {
00798 headMotionRequest.roll += (long)(headTiltDiff-headTiltTolerance);
00799 }
00800 else if (headTiltDiff < -headTiltTolerance)
00801 {
00802 headMotionRequest.roll += (long)(headTiltDiff+headTiltTolerance);
00803 }
00804 break;
00805 }
00806 case HeadControlMode::watchOrigin:
00807 {
00808 Vector3<double> point(0,0,180);
00809
00810 if (robotPose.getValidity()<0.5)
00811 {
00812
00813 if(headPathPlanner.isLastPathFinished())
00814 {
00815 unsigned long blindTime=SystemCall::getTimeSince(lastTimeOfGoodSL);
00816 double odoRot=currentOdometryData.rotation-lastOdometryData.rotation;
00817 if ((fabs(robotPose.rotation)<1.3)&&
00818 ((blindTime<500)||
00819 ((fabs(odoRot)<0.004)&&(blindTime<1300))
00820 )
00821 )
00822 {
00823
00824 if(headPathPlanner.isLastPathFinished())
00825 {
00826 if(lastScanWasLeft)
00827 {
00828 headControl.simpleLookAtPointOnField(point,Vector2<int>(-65,0),neckTilt,headPan,headTilt);
00829 Vector3<double> right(neckTilt,headPan,headTilt);
00830 Vector3<double> points[1]={right};
00831 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00832 }
00833 else
00834 {
00835 headControl.simpleLookAtPointOnField(point,Vector2<int>(65,0),neckTilt,headPan,headTilt);
00836 Vector3<double> left(neckTilt,headPan,headTilt);
00837 Vector3<double> points[1]={left};
00838 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 100);
00839 }
00840 lastScanWasLeft=!lastScanWasLeft;
00841 }
00842 }
00843 else if (odoRot==0)
00844 {
00845
00846 }
00847 else if (odoRot>0)
00848 {
00849
00850
00851 lastScanWasLeft=true;
00852 static Vector3<double> point7(0.05,1.5 ,0.05);
00853 Vector3<double> points[1]={point7};
00854 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 450);
00855 }
00856 else
00857 {
00858
00859 lastScanWasLeft=false;
00860 static Vector3<double> point7(0.05,-1.5 ,0.05);
00861 Vector3<double> points[1]={point7};
00862 headPathPlanner.oldInit(points, sizeof(points)/sizeof(Vector3<double>), 450);
00863 }
00864 }
00865 headPathPlanner.getAngles(neckTilt,headPan,headTilt);
00866 headControl.setJointsDirect(neckTilt,headPan,headTilt);
00867 }
00868 else
00869 {
00870
00871 if (robotPose.rotation<-1.45)
00872 {
00873 headControl.setJointsDirect(0.05, 1.5, 0.05);
00874 }
00875 else if (robotPose.rotation>1.45)
00876 {
00877 headControl.setJointsDirect(0.05, -1.5, 0.05);
00878 }
00879 else
00880 {
00881 double rota=-robotPose.speedbyDistanceToGoal*30;
00882 rota /= 2;
00883 headControl.simpleLookAtPointOnField(point,Vector2<int>((int)rota,0),neckTilt,headPan,headTilt);
00884 headControl.setJointsDirect(neckTilt,headPan,headTilt);
00885 }
00886 }
00887 break;
00888 }
00889 case HeadControlMode::calibrateHeadSpeed:
00890 if (headControl.calibrateHeadSpeedIsReady())
00891 {
00892
00893 headControl.setJoints(headControl.jointLimitNeckTiltP, 0.0, headControl.jointLimitHeadTiltP, 0, -.7);
00894 }
00895 else
00896 {
00897 headControl.calibrateHeadSpeed();
00898 headPathPlanner.getAngles(neckTilt,headPan,headTilt);
00899 headControl.setJointsDirect(neckTilt,headPan,headTilt);
00900 }
00901 break;
00902
00903 default:
00904 errorHandler.error("GT2004BasicBehaviorOtherHeadMovements::execute(): head control mode \"%s\" is not implemented.",
00905 HeadControlMode::getHeadControlModeName(headControlMode.headControlMode));
00906 break;
00907 }
00908 lastOdometryData = currentOdometryData;
00909 }
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096