00001 /** 00002 * @file GT2004SensorDataProcessor.h 00003 * 00004 * This file contains a class for Sensor Data Processing. 00005 */ 00006 00007 #ifndef __GT2004SensorDataProcessor_h_ 00008 #define __GT2004SensorDataProcessor_h_ 00009 00010 #include "SensorDataProcessor.h" 00011 #include "Tools/RingBuffer.h" 00012 #include "Tools/Math/Common.h" 00013 00014 static const int gt2004SensorDataProcessorBufferSize = 20; 00015 00016 /** angles above which crash will be detected 00017 * @attention adjust the angles to values in GetupEngine 00018 */ 00019 const double gt2004SensorDataProcessorFalldownTiltAngle = fromDegrees(60); 00020 const double gt2004SensorDataProcessorFalldownRollAngle = fromDegrees(60); 00021 const double gt2004SensorDataProcessorRolledOnWallAngle = fromDegrees(19); 00022 00023 /** 00024 * @class GT2004SensorDataProcessor 00025 * 00026 * The default SensorDataProcessor in the GT2004 project. 00027 */ 00028 class GT2004SensorDataProcessor : public SensorDataProcessor 00029 { 00030 public: 00031 /** 00032 * Constructor 00033 * @param interfaces The paramters of the HeadControl module. 00034 */ 00035 GT2004SensorDataProcessor(const SensorDataProcessorInterfaces& interfaces); 00036 00037 /** Executes the module */ 00038 virtual void execute(); 00039 00040 /** Returns the angle speed of the camera [degrees/second] */ 00041 double getCameraVelocity() 00042 { 00043 return getCameraVelocity(SensorData::headPan); 00044 } 00045 double getCameraVelocity(const SensorData::sensors joint); 00046 00047 /** Calculates the distance to objects in front of the bodyPSD */ 00048 double getDistanceToSIFOC(); 00049 00050 protected: 00051 /** calculates the offset and the rotation of the camera matrix */ 00052 virtual void buildCameraMatrix(const SensorData& sensorData, const BodyPosture& bP, CameraMatrix& cameraMatrix); 00053 00054 /** detects whether the robot fell down. */ 00055 virtual bool detectFallDown(); 00056 00057 /** current averaged values from acceleration sensors, longer period for gravity*/ 00058 Vector3<double> gravity; 00059 00060 private: 00061 unsigned long tempSysTime; 00062 00063 00064 /** current averaged values from acceleration sensors, shorter period for acceleration*/ 00065 Vector3<double> accelerationWithGrav; 00066 00067 /** calculates a spot relative to the robot that was detected by the PSD sensor */ 00068 void buildPSDPercept(const SensorData& sensorData, const CameraMatrix& cameraMatrix, SinglePSDPercept& psdPercept); 00069 00070 int detectSwitches(); 00071 BodyPercept::MouthStates detectMouthState(); 00072 bool detectPickup(const Vector3<double>& gravity, 00073 const Vector3<double>& acceleration); 00074 00075 /** The frame number of the last received image */ 00076 unsigned long lastImageFrameNumber; 00077 00078 /** The average neck tilt, head pan and tilt of the robot (used in this order) */ 00079 double previousAverage[3], actAverage[3]; 00080 00081 /** Stores values of SensorData for averaging */ 00082 class SensorDataRingBuffer : public RingBuffer<SensorData,gt2004SensorDataProcessorBufferSize> 00083 { 00084 public: 00085 /** 00086 * calculates an average value by summing up last ticks values 00087 * @warning not efficient, use updateAverage instead if possible 00088 */ 00089 double getAverage (SensorData::sensors sensor, int ticks); 00090 00091 /** 00092 * calculates an average value by subtracting oldest and adding newest value 00093 */ 00094 void updateAverage (SensorData::sensors sensor, int ticks, double& average); 00095 00096 long interpolate (SensorData::sensors sensor, unsigned long frame); 00097 }; 00098 00099 void calculateBodyPostureFromLegSensors(const SensorData& sensorData, BodyPosture& bP); 00100 void calculateBodyPostureFromAccelerationSensors(const SensorData& sensorData, BodyPosture& bP); 00101 00102 SensorDataRingBuffer sensorDataRingBuffer; 00103 RingBuffer<CameraMatrix,gt2004SensorDataProcessorBufferSize> cameraMatrixRingBuffer; 00104 RingBuffer<BodyPosture,gt2004SensorDataProcessorBufferSize> bodyPostureRingBuffer; 00105 unsigned long leftRollStartTime; 00106 unsigned long rightRollStartTime; 00107 }; 00108 00109 #endif// __GT2004SensorDataProcessor_h_ 00110 00111 /* 00112 * Change log : 00113 * 00114 * $Log: GT2004SensorDataProcessor.h,v $ 00115 * Revision 1.1 2004/07/10 00:18:31 spranger 00116 * renamed (readded) for coderelease 00117 * 00118 * Revision 1.6 2004/06/17 12:17:15 schmitt 00119 * Modified getCameraVelocity() 00120 * Selection of the speed each head joint is now possible 00121 * Default is headPan 00122 * 00123 * Revision 1.5 2004/06/16 17:07:33 cesarz 00124 * Moved body PSD calculations 00125 * 00126 * Revision 1.4 2004/06/16 12:40:02 cesarz 00127 * implemented getCameraVelocity() 00128 * 00129 * Revision 1.3 2004/05/26 20:18:05 juengel 00130 * Calculation of BodyPosture. 00131 * 00132 * Revision 1.2 2004/05/24 14:14:26 juengel 00133 * New button evaluation. 00134 * 00135 * Revision 1.1.1.1 2004/05/22 17:21:30 cvsadm 00136 * created new repository GT2004_WM 00137 * 00138 * Revision 1.5 2004/04/09 11:35:53 roefer 00139 * Bremen Byters German Open check-in 00140 * 00141 * Revision 1.4 2004/04/07 12:28:59 risler 00142 * ddd checkin after go04 - first part 00143 * 00144 * Revision 1.2 2004/04/02 19:10:48 risler 00145 * robot no longer is crashed when using dash 00146 * 00147 * Revision 1.1.1.1 2004/03/29 08:28:47 Administrator 00148 * initial transfer from tamara 00149 * 00150 * Revision 1.3 2004/03/08 02:11:51 roefer 00151 * Interfaces should be const 00152 * 00153 * Revision 1.2 2004/02/04 13:41:33 roefer 00154 * Some place holders for BB2004 modules added 00155 * 00156 * Revision 1.1 2003/10/06 14:10:14 cvsadm 00157 * Created GT2004 (M.J.) 00158 * 00159 * Revision 1.2 2003/07/06 12:05:31 schumann 00160 * added foreleg opening angle for ball challenge 00161 * 00162 * Revision 1.1.1.1 2003/07/02 09:40:24 cvsadm 00163 * created new repository for the competitions in Padova from the 00164 * tamara CVS (Tuesday 2:00 pm) 00165 * 00166 * removed unused solutions 00167 * 00168 * Revision 1.14 2003/06/20 15:32:32 dueffert 00169 * getting from down from wall by rolling added 00170 * 00171 * Revision 1.13 2003/05/14 19:54:42 risler 00172 * PSDPercept contains all points from one frame 00173 * 00174 * Revision 1.12 2003/05/02 18:26:18 risler 00175 * SensorDataBuffer added 00176 * replaced SensorData with SensorDataBuffer 00177 * full SensorData resolution now accessible 00178 * 00179 * Revision 1.11 2003/04/04 17:51:23 hebbel 00180 * Removed not needed OUTPUTs 00181 * 00182 * Revision 1.10 2003/04/04 16:08:59 cesarz 00183 * mouth values adepted 00184 * 00185 * Revision 1.9 2003/04/01 22:40:44 cesarz 00186 * added mouth states 00187 * 00188 * Revision 1.8 2003/01/30 11:26:47 juengel 00189 * Added tailPosition to bodyPercept 00190 * 00191 * Revision 1.7 2002/10/10 13:09:49 loetzsch 00192 * First experiments with the PSD Sensor 00193 * - SensorDataProcessor now calculates PSDPercept 00194 * - Added the PerceptBehaviorControl solution PSDTest 00195 * - Added the RadarViewer3D to RobotControl, which can display the Points3D structure 00196 * 00197 * Revision 1.6 2002/09/22 18:40:53 risler 00198 * added new math functions, removed GTMath library 00199 * 00200 * Revision 1.5 2002/09/17 23:55:22 loetzsch 00201 * - unraveled several datatypes 00202 * - changed the WATCH macro 00203 * - completed the process restructuring 00204 * 00205 * Revision 1.4 2002/09/12 12:24:09 juengel 00206 * continued change of module/solution mechanisms 00207 * 00208 * Revision 1.3 2002/09/10 21:07:30 loetzsch 00209 * continued change of module/solution mechanisms 00210 * 00211 * Revision 1.2 2002/09/10 17:53:40 loetzsch 00212 * First draft of new Module/Solution Mechanisms 00213 * 00214 * Revision 1.1 2002/09/10 15:36:16 cvsadm 00215 * Created new project GT2003 (M.L.) 00216 * - Cleaned up the /Src/DataTypes directory 00217 * - Removed challenge related source code 00218 * - Removed processing of incoming audio data 00219 * - Renamed AcousticMessage to SoundRequest 00220 * 00221 * Revision 1.1.1.1 2002/05/10 12:40:15 cvsadm 00222 * Moved GT2002 Project from ute to tamara. 00223 * 00224 * Revision 1.18 2002/04/23 10:38:30 risler 00225 * renamed headOdometry to headState 00226 * 00227 * Revision 1.17 2002/04/17 17:04:40 risler 00228 * Darmstadt GO 00229 * 00230 * Revision 1.16 2002/04/08 18:35:07 risler 00231 * decreased buffer size 00232 * 00233 * Revision 1.15 2002/04/08 17:48:28 risler 00234 * added tilt angle calculation, pickedUp detection 00235 * some cleaning up 00236 * 00237 * Revision 1.14 2002/04/02 13:10:20 dueffert 00238 * big change: odometryData and cameraMatrix in image now, old logfiles may be obsolete 00239 * 00240 * Revision 1.13 2002/03/05 17:58:43 risler 00241 * added detectPickup 00242 * 00243 * Revision 1.12 2002/02/14 16:45:00 petters 00244 * no message 00245 * 00246 * Revision 1.11 2002/02/05 20:26:46 petters 00247 * ... uncommented 00248 * 00249 * Revision 1.10 2002/02/05 17:34:18 petters 00250 * interpolation functions in sensor data buffer added (not tested -> commented out) 00251 * 00252 * Revision 1.9 2002/02/03 09:32:54 risler 00253 * RingBuffer from DefaultSensorDataProcessor now is seperate class 00254 * 00255 * Revision 1.8 2002/02/01 15:03:23 risler 00256 * Removed pickup detection, as not working with paw sensors 00257 * 00258 * Revision 1.7 2002/01/20 23:35:06 loetzsch 00259 * Added parameter imageFrameNumber to execute(...) 00260 * 00261 * Revision 1.6 2002/01/18 12:24:17 mkunz 00262 * build camera matrix added 00263 * 00264 * Revision 1.5 2002/01/18 11:23:17 petters 00265 * return bodypercept added 00266 * 00267 * Revision 1.4 2001/12/23 23:45:28 petters 00268 * sensordatabuffer implemented, state detector implemented, switch detector implemented 00269 * 00270 * Revision 1.3 2001/12/12 20:21:12 petters 00271 * Streaming for SensorData / Image implemented; Conflict solved 00272 * 00273 * Revision 1.2 2001/12/10 17:47:07 risler 00274 * change log added 00275 * 00276 */