00001 /** 00002 * @file GT2004HeadControl.h 00003 * 00004 * Definition of class GT2004HeadControl. 00005 * 00006 * @author Marc Dassler 00007 * @author Jan Hoffmann 00008 * @author Uwe Düffert 00009 * @author Martin Lötzsch 00010 */ 00011 00012 #ifndef __GT2004HeadControl_h__ 00013 #define __GT2004HeadControl_h__ 00014 00015 #include "../Xabsl2HeadControl.h" 00016 00017 #include "GT2004HeadPathPlanner.h" 00018 #include "GT2004HeadControlSymbols.h" 00019 #include "GT2004HeadControlBasicBehaviors.h" 00020 00021 /** 00022 * @class GT2004HeadControl 00023 * 00024 * The GT2004 version of the HeadControl module. 00025 * 00026 * @author Marc Dassler 00027 * @author Jan Hoffmann 00028 * @author Uwe Düffert 00029 * @author Martin Lötzsch 00030 */ 00031 class GT2004HeadControl : public Xabsl2HeadControl 00032 { 00033 public: 00034 /** 00035 * Constructor. 00036 * @param interfaces The paramters of the HeadControl module. 00037 */ 00038 GT2004HeadControl(HeadControlInterfaces& interfaces); 00039 00040 /** Destructor. */ 00041 ~GT2004HeadControl(){} 00042 00043 /** Executes the module */ 00044 virtual void execute(); 00045 00046 /** 00047 * Is called for every incoming debug message. 00048 * @param message An interface to read the message from the queue 00049 * @return if the messag was read 00050 */ 00051 virtual bool handleMessage(InMessage& message); 00052 00053 /** Registers symbols and basic behaviors at the engine */ 00054 virtual void registerSymbolsAndBasicBehaviors(); 00055 00056 /** An instance of the head path planner */ 00057 GT2004HeadPathPlanner headPathPlanner; 00058 00059 /** If true, the last head movement was directed to the left side (of the ball) */ 00060 bool lastScanWasLeft; 00061 00062 /** Is true, if the head is on the left side */ 00063 bool headPanIsLeft(); 00064 00065 /** put the sensor values in var pos */ 00066 void getSensorHeadAngles(Vector3<double>& pos); 00067 00068 /** returns a distance between actual position and comp. the small results are better */ 00069 double headPositionDistanceToActualPosition(Vector3<double> comp,bool leftSide); 00070 00071 /** The head control mode that was executed in the last frame */ 00072 HeadControlMode::HeadControlModes lastHeadControlMode; 00073 00074 /** Information about the used camera */ 00075 CameraInfo cameraInfo; 00076 00077 /** The symbols used by the Xabsl2Engine */ 00078 GT2004HeadControlSymbols symbols; 00079 00080 /** The basic behaviors used by the Xabsl2Engine */ 00081 GT2004HeadControlBasicBehaviors basicBehaviors; 00082 00083 /** The minimum head speed in urad per frame: 4000 = 28.6°/s */ 00084 enum {minHeadSpeed=4000}; 00085 00086 00087 /** deals with setting the head joints and performs 00088 optimizations so that the head does not move too fast 00089 angles are in RAD and NOT EVER AGAIN(!!) IN MICRORAD! 00090 */ 00091 void setJoints(double tilt, double pan, double roll, double speed=0, double mouth=0); 00092 00093 /* Writes the joint angles to the HeadMotionRequest without optimization and smoothing */ 00094 void setJointsDirect(double tilt, double pan, double roll, double mouth=0); 00095 00096 void simpleLookAtPointRelativeToRobot(const Vector3<double> pos, Vector2<int> offset, double& neckTilt, double& headPan, double& headTilt); 00097 00098 /** Simplified "look at 3d-point" on field with offset point in camera image 00099 this is straight-forward for the ERS210, but the ERS7 has two 00100 tilt joints that can both be used to look at something. Lookatpoint 00101 uses the two following methods to find a 'good' solution. */ 00102 void simpleLookAtPointOnField(const Vector3<double> pos, Vector2<int> offset, double& neckTilt, double& headPan, double& headTilt); 00103 00104 /** Simplified "look at 3d-point" subroutine trying to find tilt1 solution for given tilt2/roll. this is useful on ERS210 and ERS7 00105 *@return true when matching angles were found */ 00106 bool simpleLookAtPointFixNeckTilt(const Vector3<double> &aim, const double& tilt1, double& headPan, double& headTilt); 00107 00108 /** look at 3d-point on field with offset point in camera image 00109 this is straight-forward for the ERS210, but the ERS7 has two 00110 tilt joints that can both be used to look at something. Lookatpoint 00111 uses the two following methods to find a 'good' solution. */ 00112 void lookAtPoint(const Vector3<double> &pos,const Vector2<int> &offset,double& tilt,double& pan,double& roll); 00113 00114 /** look at 3d-point subroutine trying to find tilt1 solution for given tilt2/roll. this is useful on ERS210 and ERS7 00115 *@return true when matching angles were found */ 00116 bool lookAtPointFixHeadTilt(const Vector3<double> &aim, const double& xtan, const double& ytan, double& tilt1, double& pan, const double& tilt2); 00117 00118 /** look at 3d-point subroutine trying to find tilt2 solution for given tilt1. this is only useful on ERS7 00119 *@return true when matching angles were found */ 00120 bool lookAtPointFixNeckTilt(const Vector3<double> &aim, const double& xtan, const double& ytan, const double& tilt, double& pan, double& tilt2); 00121 00122 /** return the closest landmark w.r.t. a given direction; also, 00123 * the next landmark to the left (or right) can be calculated. */ 00124 int calculateClosestLandmark(double direction = 0, double nextLeftOrRight = 0); 00125 00126 /** call look-at-point depending on whether the landmark has has a z-dimension 00127 * the offset in the image is adjusted: landmarks on the ground are aimed at differently from goals and corner posts*/ 00128 void aimAtLandmark(int landmark, double& neckTilt, double& headPan, double& headTilt); 00129 00130 /** returns the angles that are good for looking at the ball */ 00131 void getLookAtBallAngles(const Vector2<double> ballOnField, double& neckTilt, double& headPan, double& headTilt); 00132 00133 /** stores the number of frames "setjoints" has been close to its destination */ 00134 int setJointsIsCloseToDestination; 00135 00136 /** true if the max pan of the head joint is reached */ 00137 bool setJointsMaxPanReached; 00138 00139 /** initial the main angles for the head movement */ 00140 void setupMainAngles(); 00141 00142 00143 /** basic headpositions for the gaze */ 00144 Vector3<double> headLeft; 00145 Vector3<double> headRight; 00146 Vector3<double> headMiddleLeft; 00147 Vector3<double> headMiddleLeftDown; 00148 Vector3<double> headMiddleRight; 00149 Vector3<double> headMiddleRightDown; 00150 Vector3<double> headRightDown; 00151 Vector3<double> headLeftDown; 00152 Vector3<double> headUp; 00153 Vector3<double> headDown; 00154 00155 /** speed in rad/s for head movement. its used for headpathplanner and the calibration */ 00156 double speedNeckTilt; 00157 double speedHeadPan; 00158 double speedHeadTilt; 00159 00160 /* this calculates the speed of the head motors. 00161 later the speeds where used for the headPathPlanner for calculating realistic headmotions */ 00162 void calibrateHeadSpeed(); 00163 00164 /* if the ball get losts, he belives in the communicated ball */ 00165 00166 bool useCommunicatedBall; 00167 00168 enum 00169 { 00170 calibrationStateStart, 00171 calibrationStateLeft, 00172 calibrationStateLeftWait, 00173 calibrationStateRight, 00174 calibrationStateRightWait, 00175 calibrationStateDownTilt1, 00176 calibrationStateDownTilt1Wait, 00177 calibrationStateUpTilt1, 00178 calibrationStateUpTilt1Wait, 00179 calibrationStateDownTilt2, 00180 calibrationStateDownTilt2Wait, 00181 calibrationStateUpTilt2, 00182 calibrationStateUpTilt2Wait, 00183 calibrationStateUseResults, 00184 calibrationStateReady 00185 } calibrationState; 00186 00187 long calibrationTime; 00188 int calibrationTimeOutsTilt1,calibrationTimeOutsPan,calibrationTimeOutsTilt2; 00189 int calibrationRoundCount,calibrationSuccessfulRounds; 00190 00191 void calibrationReset() 00192 { 00193 calibrationTimeOutsTilt1 = 0; 00194 calibrationTimeOutsPan = 0; 00195 calibrationTimeOutsTilt2 = 0; 00196 calibrationState = calibrationStateStart; 00197 } 00198 /* return true, if the position is reached more or less */ 00199 bool headPositionReached(Vector3<double> pos) 00200 { 00201 return headPathPlanner.headPositionReached(pos); 00202 } 00203 00204 /** return the index of the last seen beacon */ 00205 int getLastSeenBeaconIndex(); 00206 00207 /** return the time of the last seen beacon */ 00208 long getTimeOfLastSeenBeacon(int index); 00209 00210 /** return the time between the two last seen beacons */ 00211 long getTimeBetweenSeen2LastBeacons(int index); 00212 00213 /* return true, if the calibration move is over the time to reach the given position */ 00214 bool isTimedOut() 00215 { 00216 return (SystemCall::getTimeSince(calibrationTime)>2500); 00217 } 00218 /* return true, if the calibration process is ready */ 00219 bool calibrateHeadSpeedIsReady() 00220 { 00221 return (calibrationState==calibrationStateReady); 00222 } 00223 00224 /** looks to the left/right side an aearch for ball. Used for kicks */ 00225 void searchForBallLeft(); 00226 void searchForBallRight(); 00227 00228 /** begin a ball search by the given start position */ 00229 void beginBallSearchAt(Vector2<double> ballPosition2d); 00230 00231 private: 00232 Range<double> jointRangeNeckTilt, jointRangeHeadPan, jointRangeHeadTilt; 00233 00234 // the following are used to improve performance of set-joints when the robot is turning fast 00235 OdometryData lastOdometryData; 00236 RobotPose lastRobotPose; 00237 }; 00238 00239 #endif //__GT2004HeadControl_h__ 00240 00241 /* 00242 * Change log : 00243 * 00244 * $Log: GT2004HeadControl.h,v $ 00245 * Revision 1.22 2004/07/02 10:27:03 jhoffman 00246 * - preparation for compensating robot motions by appropriate head motion (no actual changes) 00247 * - headControl-Mode added for testing 00248 * - look-at-ball-and-closest-landmark uses quicker head movement 00249 * 00250 * Revision 1.21 2004/07/01 18:21:16 dassler 00251 * Added BasicBehavior and HeadControlMode: 00252 * search-for-ball-left 00253 * search-for-ball-right 00254 * Test is needed 00255 * 00256 * Revision 1.20 2004/06/29 17:06:53 dassler 00257 * find ball scans first to the side where the head pan angle is smaller 00258 * 00259 * Revision 1.19 2004/06/29 10:17:00 dassler 00260 * find ball choose side to scan dependent of headPan 00261 * 00262 * Revision 1.18 2004/06/28 14:00:04 jhoffman 00263 * - scan back to ball slower 00264 * - directed scan briefly stops at landmarks 00265 * - input symbol set-joints-is-close-to-destination implemented and added to behavior 00266 * - merged marcs changes into track-ball-strict 00267 * 00268 * Revision 1.17 2004/06/28 09:46:57 dassler 00269 * introduced some more headcontrol symbols 00270 * time-since-last-seen-beacon 00271 * time-between-last-beacons 00272 * 00273 * Revision 1.16 2004/06/18 18:28:39 dassler 00274 * introduced basic-behavior: 00275 * BeginBallSearchAtBallPositionSeen 00276 * BeginBallSearchAtBallPositionCommunicated 00277 * BeginBallSearchAtBallPositionPropagated 00278 * 00279 * track-ball modified and build in ball-just-lost 00280 * 00281 * Revision 1.15 2004/06/17 22:02:13 dassler 00282 * LookLeft/Right set to the the berlin gaze 00283 * searchForBall headPath optimzied. 00284 * 00285 * Revision 1.14 2004/06/17 15:39:33 dassler 00286 * LandmarkState added 00287 * 00288 * Revision 1.12 2004/06/15 16:29:56 jhoffman 00289 * check in for practice match 00290 * 00291 * Revision 1.11 2004/06/14 20:12:10 jhoffman 00292 * - numerous changes and additions to headcontrol 00293 * - cameraInfo default constructor now creates ERS7 info 00294 * - debug drawing "headcontrolfield" added 00295 * 00296 * Revision 1.10 2004/06/08 18:37:11 juengel 00297 * Added setJointsDirect(). 00298 * 00299 * Revision 1.9 2004/06/05 16:02:49 jhoffman 00300 * - added look-at-ball-and-closest-landmark (basicbahavior) 00301 * - found and removed bug in simple-look-at-point 00302 * 00303 * Revision 1.8 2004/06/04 08:44:12 juengel 00304 * Renamed simpleLookAtPoint to simpleLookAtPointOnField. 00305 * Added simpleLookAtPointRelativeToRobot. 00306 * 00307 * Revision 1.7 2004/06/01 15:05:41 jhoffman 00308 * added "simple-look-at-ball" to gt2004headcontrol 00309 * 00310 * Revision 1.6 2004/05/27 17:13:37 jhoffman 00311 * - renaming: tilt1 -> neckTilt, pan -> headPan, tilt2 -> headTilt 00312 * - clipping included for setJoints 00313 * - removed some microrad/rad-bugs 00314 * - bodyPosture constructor and "=" operator fixed 00315 * 00316 * Revision 1.5 2004/05/25 18:30:12 jhoffman 00317 * landmarks-array in field dimensions 00318 * headcontrol looks at close landmark 00319 * 00320 * Revision 1.4 2004/05/24 18:19:43 jhoffman 00321 * microrad --> rad 00322 * 00323 * Revision 1.3 2004/05/23 22:49:14 loetzsch 00324 * simplified basic behaviors 00325 * 00326 * Revision 1.2 2004/05/23 20:27:57 loetzsch 00327 * some improvements with the head control 00328 * 00329 * Revision 1.1.1.1 2004/05/22 17:19:24 cvsadm 00330 * created new repository GT2004_WM 00331 * 00332 * Revision 1.2 2004/05/18 13:40:00 loetzsch 00333 * registered symbols and basic behaviors for GT2004HeadControl, 00334 * renamed some states and basic behaviors 00335 * 00336 * Revision 1.1 2004/05/14 11:37:08 loetzsch 00337 * support for multiple xabsl2engines in different modules 00338 * preliminary GT2004HeadControl (does not work at all) 00339 * 00340 */