Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Platform/Aperios1.3.2/Sensors.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file Platform/Aperios1.3.2/Sensors.cpp
00003 *
00004 * Implementation of system dependend streaming operators for images and sensor data
00005 *
00006 * @author Martin Lötzsch
00007 * @author Sebastian Petters
00008 * @author Thomas Röfer
00009 * @author Uwe Düffert
00010 */ 
00011 
00012 #include "Sensors.h"
00013 #include <OPENR/OPENRAPI.h>
00014 #include <iostream.h>
00015 #include <OPENR/SharedMemoryHeader.h>
00016 //#include <OPENR/OPrimitiveControl.h>
00017 #include "Tools/Streams/InStreams.h"
00018 #include "Tools/Streams/OutStreams.h"
00019 #include "Tools/Location.h"
00020 #include "Tools/Actorics/RobotDimensions.h"
00021 #include "Representations/Perception/CameraParameters.h"
00022 #include "SystemCall.h"
00023 
00024 Sensors::Sensors () 
00025 {
00026   InBinaryFile fin(getLocation().getModelFilename("camera.cfg"));
00027   if (fin.exists())
00028   {
00029     fin >> cameraParameters;
00030   }
00031   else
00032   {
00033     cameraParameters.theWhiteBalance = CameraParameters::wb_indoor_mode;
00034     cameraParameters.theGain         = CameraParameters::gain_low;
00035     cameraParameters.theShutterSpeed = CameraParameters::shutter_mid;
00036   }
00037   
00038   setCameraParameters(cameraParameters);  // it occurred to me that the parameters should not only be read from the file but also set into action, hope this fixes the problem :-) - ronnie brunn
00039 }
00040 
00041 void Sensors::setCameraParameters(CameraParameters &cameraParameters)
00042 {
00043   static OPrimitiveID fbkID = 0;
00044   OPENR::OpenPrimitive("PRM:/r1/c1/c2/c3/i1-FbkImageSensor:F1", &fbkID);
00045   OPrimitiveControl_CameraParam wb(cameraParameters.theWhiteBalance + 1);
00046   OPENR::ControlPrimitive(fbkID, oprmreqCAM_SET_WHITE_BALANCE, &wb, sizeof(wb), 0, 0);
00047   OPrimitiveControl_CameraParam gain(cameraParameters.theGain + 1);
00048   OPENR::ControlPrimitive(fbkID, oprmreqCAM_SET_GAIN, &gain, sizeof(gain), 0, 0);
00049   OPrimitiveControl_CameraParam shutter(cameraParameters.theShutterSpeed + 1);
00050   OPENR::ControlPrimitive(fbkID, oprmreqCAM_SET_SHUTTER_SPEED, &shutter, sizeof(shutter), 0, 0);
00051 }
00052 
00053 In& operator>>(In& stream,Image& image)
00054 {  
00055   //only read the header
00056   unsigned char buffer[512];
00057   stream.read(buffer,512);
00058   
00059   OFbkImageVectorData* data = reinterpret_cast<OFbkImageVectorData*>(buffer);
00060   image.cameraInfo.resolutionHeight = data->GetInfo(0)->height;
00061   image.cameraInfo.resolutionWidth = data->GetInfo(0)->width;
00062   image.frameNumber = data->GetInfo(0)->frameNumber;
00063   //int numOfBands = data->GetInfo(0)->dataSize / image.cameraInfo.resolutionHeight / image.cameraInfo.resolutionWidth;
00064   
00065   // this code even works if rows in "image" are longer than the data received
00066   for(int y=0; y < image.cameraInfo.resolutionHeight; y++)
00067   {
00068     for(int c = 0; c < 6; ++c)
00069       stream.read(&image.image[y][c][0], image.cameraInfo.resolutionWidth);
00070     //stream.skip(image.cameraInfo.resolutionWidth * 3);
00071   }
00072   stream.skip(1000000); // skip anything else
00073 
00074   image.setCameraInfo();
00075 
00076   for (int i = 0; i < 16; i++)
00077   {
00078     image.image[image.cameraInfo.resolutionHeight-1][0][i] = image.image[image.cameraInfo.resolutionHeight-2][0][i];
00079     image.image[image.cameraInfo.resolutionHeight-1][1][i] = image.image[image.cameraInfo.resolutionHeight-2][1][i];
00080     image.image[image.cameraInfo.resolutionHeight-1][2][i] = image.image[image.cameraInfo.resolutionHeight-2][2][i];
00081   }
00082   
00083   return stream;
00084 }
00085 In& operator>>(In& stream,SensorDataBuffer& sensorDataBuffer)
00086 {
00087   static const int translateERS7[] =
00088   {
00089     SensorData::mouth,
00090     SensorData::chin,
00091     SensorData::headTilt,
00092     SensorData::head,
00093     SensorData::headPsdNear, 
00094     SensorData::headPsdFar,
00095     SensorData::headPan, 
00096     SensorData::neckTilt,
00097     SensorData::pawFL, 
00098     SensorData::legFL3, 
00099     SensorData::legFL2, 
00100     SensorData::legFL1,
00101     SensorData::pawHL, 
00102     SensorData::legHL3, 
00103     SensorData::legHL2, 
00104     SensorData::legHL1,
00105     SensorData::pawFR, 
00106     SensorData::legFR3, 
00107     SensorData::legFR2, 
00108     SensorData::legFR1,
00109     SensorData::pawHR, 
00110     SensorData::legHR3, 
00111     SensorData::legHR2, 
00112     SensorData::legHR1,
00113     SensorData::tailTilt,
00114     SensorData::tailPan, 
00115     SensorData::accelerationX, 
00116     SensorData::accelerationY, 
00117     SensorData::accelerationZ,
00118     SensorData::bodyPsd,
00119     SensorData::wlan,
00120     SensorData::backR,
00121     SensorData::backM, 
00122     SensorData::backF
00123   };
00124 
00125 #ifdef __GNUC__
00126   char buffer[12288];
00127 #else // GreenHills
00128   char buffer[9120]; // this should never be used with ERS-7
00129 #endif
00130   bool isERS210 = SystemCall::getRobotDesign() == RobotDesign::ERS210;
00131   stream.read(buffer, isERS210 ? sizeof(buffer) : 9984);
00132   
00133   OSensorFrameVectorData& data = *(OSensorFrameVectorData*) buffer;
00134   
00135   sensorDataBuffer.numOfFrames = data.GetInfo(0)->numFrames;
00136   
00137   for (int j = 0; j < sensorDataBuffer.numOfFrames; j++)
00138   {
00139     if(isERS210)
00140       for (int i = 0; i < SensorData::numOfSensor_ERS210; ++i)
00141       {
00142         OSensorFrameData* pData = data.GetData(i);
00143         sensorDataBuffer.frame[j].data[i] = pData->frame[j].value;
00144         
00145         if (data.GetInfo(i)->type == odataJOINT_VALUE)
00146           sensorDataBuffer.frame[j].refValue[i] = 
00147           ((OJointValue*)(&(pData->frame[j])))->refValue;
00148       }
00149     else
00150       for (int i = 0; i < SensorData::numOfSensor_ERS7; ++i)
00151       {
00152         int index = translateERS7[i];
00153         OSensorFrameData* pData = data.GetData(i);
00154         sensorDataBuffer.frame[j].data[index] = pData->frame[j].value;
00155         
00156         if (data.GetInfo(i)->type == odataJOINT_VALUE)
00157           sensorDataBuffer.frame[j].refValue[index] = 
00158           ((OJointValue*)(&(pData->frame[j])))->refValue;
00159       }
00160 
00161     //open-r coordinates different than ours
00162     sensorDataBuffer.frame[j].data[SensorData::accelerationY]=
00163       -sensorDataBuffer.frame[j].data[SensorData::accelerationY];
00164     
00165     sensorDataBuffer.frame[j].frameNumber = data.GetInfo(0)->frameNumber + j;
00166   }
00167   
00168   return stream;
00169 }
00170 
00171 /*
00172  * Change log :
00173  * 
00174  * $Log: Sensors.cpp,v $
00175  * Revision 1.3  2004/05/27 17:13:37  jhoffman
00176  * - renaming: tilt1 -> neckTilt,  pan -> headPan,  tilt2 -> headTilt
00177  * - clipping included for setJoints
00178  * - removed some microrad/rad-bugs
00179  * - bodyPosture constructor and "=" operator fixed
00180  *
00181  * Revision 1.2  2004/05/27 10:08:08  thomas
00182  * added model-specific locations
00183  *
00184  * Revision 1.1.1.1  2004/05/22 17:23:35  cvsadm
00185  * created new repository GT2004_WM
00186  *
00187  * Revision 1.9  2004/04/07 13:00:47  risler
00188  * ddd checkin after go04 - second part
00189  *
00190  * Revision 1.3  2004/04/07 11:44:06  risler
00191  * added sending low res images
00192  * added Image::setCameraInfo
00193  *
00194  * Revision 1.2  2004/03/29 15:19:04  Marc
00195  * Intruduced the Black and White Image
00196  * Normal Images (not Jpeg) images were now send as Color Image with BW
00197  *
00198  * Revision 1.8  2004/03/17 12:35:13  nistico
00199  * Fixed problem with loading of intrinsic camera parameters
00200  *
00201  * Revision 1.7  2004/01/13 11:57:38  dueffert
00202  * doxygen comment corrected
00203  *
00204  * Revision 1.6  2004/01/05 16:52:53  risler
00205  * ERS7 Sensor translation fixed
00206  *
00207  * Revision 1.5  2003/12/31 20:16:13  roefer
00208  * SensorData for ERS-7
00209  *
00210  * Revision 1.4  2003/12/30 20:12:03  roefer
00211  * Image size is now 208 x 160. Smaller images are placed in the upper left corner
00212  *
00213  * Revision 1.3  2003/12/15 11:49:09  juengel
00214  * Introduced CameraInfo
00215  *
00216  * Revision 1.2  2003/11/12 12:42:44  dueffert
00217  * image processing now works with sdk-1.1.3-r2 AND sdk-1.1.4-r1
00218  *
00219  * Revision 1.1  2003/10/07 10:06:59  cvsadm
00220  * Created GT2004 (M.J.)
00221  *
00222  * Revision 1.3  2003/09/30 10:51:12  dueffert
00223  * typos fixed
00224  *
00225  * Revision 1.2  2003/09/26 15:30:28  juengel
00226  * Renamed DataTypes to representations.
00227  *
00228  * Revision 1.1.1.1  2003/07/02 09:40:24  cvsadm
00229  * created new repository for the competitions in Padova from the 
00230  * tamara CVS (Tuesday 2:00 pm)
00231  *
00232  * removed unused solutions
00233  *
00234  * Revision 1.11  2003/05/11 17:03:00  risler
00235  * added location.cfg
00236  *
00237  * Revision 1.10  2003/05/03 15:26:29  risler
00238  * added refValue to SensorData
00239  *
00240  * Revision 1.9  2003/05/02 18:26:18  risler
00241  * SensorDataBuffer added
00242  * replaced SensorData with SensorDataBuffer
00243  * full SensorData resolution now accessible
00244  *
00245  * Revision 1.8  2003/04/19 04:47:19  pruente
00246  * removed comment lines for not confusing the reader
00247  *
00248  * Revision 1.7  2003/04/19 04:46:15  pruente
00249  * Merged in changes by Andr\'{e} at GO2003:
00250  * - Made camera.cfg fail-proof
00251  *
00252  * - Fixed "first 16 pixels of last line" image bug
00253  *   Beautified fail-proof camera.cfg strategy
00254  *
00255  * Revision 1.6  2003/04/04 21:28:35  roefer
00256  * Communication protocol changed
00257  *
00258  * Revision 1.5  2003/02/17 10:41:00  dueffert
00259  * greenhills backport
00260  *
00261  * Revision 1.4  2003/02/10 13:59:26  dueffert
00262  * gcc32 adaption
00263  *
00264  * Revision 1.3  2002/12/05 23:17:23  roefer
00265  * Camera parameters corrected
00266  *
00267  * Revision 1.2  2002/09/16 15:55:16  dueffert
00268  * Martins changes to Win32 adapted to Aperios
00269  *
00270  * Revision 1.1  2002/09/10 15:40:04  cvsadm
00271  * Created new project GT2003 (M.L.)
00272  * - Cleaned up the /Src/DataTypes directory
00273  * - Removed challenge related source code
00274  * - Removed processing of incoming audio data
00275  * - Renamed AcousticMessage to SoundRequest
00276  *
00277  * Revision 1.6  2002/08/30 17:10:57  dueffert
00278  * removed unused includes
00279  *
00280  * Revision 1.5  2002/07/25 14:31:27  roefer
00281  * gcc compilation errors fixed
00282  *
00283  * Revision 1.4  2002/07/23 13:39:39  loetzsch
00284  * - new streaming classes
00285  * - removed many #include statements
00286  * - new design of debugging architecture
00287  * - exchanged StaticQueue with MessageQueue
00288  *
00289  * Revision 1.3  2002/07/13 10:54:58  roefer
00290  * New command and sound sender
00291  *
00292  * Revision 1.2  2002/05/14 21:06:58  hebbel
00293  * in operator for SoundDataIn included
00294  *
00295  * Revision 1.1.1.1  2002/05/10 12:40:18  cvsadm
00296  * Moved GT2002 Project from ute to tamara.
00297  *
00298  * Revision 1.7  2002/03/28 17:44:45  loetzsch
00299  * new streaming operator caused debug assertions
00300  *
00301  * Revision 1.6  2002/03/27 15:25:07  brunn
00302  * camera parameters werden ab jetzt nicht nur geladen sondern auch mit den geladenen werten initialisiert ;-)
00303  *
00304  * Revision 1.5  2002/03/26 18:59:23  loetzsch
00305  * enabled faster streaming operator
00306  *
00307  * Revision 1.4  2002/02/01 15:02:41  risler
00308  * Acceleration sensor adjusted to coordinate system
00309  *
00310  * Revision 1.3  2002/01/23 07:47:25  loetzsch
00311  * der In >>  - Streaming operator liest nun auch die frameNumber
00312  *
00313  * Revision 1.2  2001/12/19 18:37:32  bach
00314  * Camera.cfg added
00315  * Sensors: CameraParameters are set
00316  *
00317  * Revision 1.1  2001/12/19 16:03:55  bach
00318  * SystemDataTypes replaced by Sensors
00319  *
00320  *
00321  */

Generated on Thu Sep 23 19:57:34 2004 for GT2004 by doxygen 1.3.6