00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "Sensors.h"
00013 #include <OPENR/OPENRAPI.h>
00014 #include <iostream.h>
00015 #include <OPENR/SharedMemoryHeader.h>
00016
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);
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
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
00064
00065
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
00071 }
00072 stream.skip(1000000);
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];
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
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
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321