BallTrackingHead7_Sensor.cc

Go to the documentation of this file.
00001 //
00002 // Copyright 2002,2004 Sony Corporation 
00003 //
00004 // Permission to use, copy, modify, and redistribute this software for
00005 // non-commercial use is hereby granted.
00006 //
00007 // This software is provided "as is" without warranty of any kind,
00008 // either expressed or implied, including but not limited to the
00009 // implied warranties of fitness for a particular purpose.
00010 //
00011 
00012 #include <OPENR/OSyslog.h>
00013 #include "BallTrackingHead7.h"
00014 
00015 void
00016 BallTrackingHead7::NotifySensor(const ONotifyEvent& event)
00017 {
00018     RCRegion* rgn = event.RCData(0);
00019 
00020     if (initSensorIndex == false) {
00021         OSensorFrameVectorData* sv = (OSensorFrameVectorData*)rgn->Base();
00022         InitSensorIndex(sv);
00023         initSensorIndex = true;
00024     }
00025 
00026     if (sensorRegions.size() == NUM_SENSOR_VECTOR) {
00027         sensorRegions.front()->RemoveReference();
00028         sensorRegions.pop_front();
00029     }
00030     rgn->AddReference();
00031     sensorRegions.push_back(rgn);
00032 
00033     observer[event.ObsIndex()]->AssertReady();
00034 }
00035 
00036 void
00037 BallTrackingHead7::InitSensorIndex(OSensorFrameVectorData* sensorVec)
00038 {
00039     for (int i = 0; i < NUM_JOINTS; i++) {
00040         for (int j = 0; j < sensorVec->vectorInfo.numData; j++) {
00041             OSensorFrameInfo* info = sensorVec->GetInfo(j);
00042             if (info->primitiveID == jointID[i]) {
00043                 sensoridx[i] = j;
00044                 OSYSDEBUG(("[%2d] %s\n",
00045                            sensoridx[i], JOINT_LOCATOR[i]));
00046                 break;
00047             }
00048         }
00049     }
00050 }
00051 
00052 void
00053 BallTrackingHead7::GetPanTiltAngle(longword frameNum,
00054                                    double* pan, double* tilt)
00055 {
00056     list<RCRegion*>::iterator iter = sensorRegions.begin();
00057     list<RCRegion*>::iterator last = sensorRegions.end();
00058     OSensorFrameVectorData* sv;
00059     OSensorFrameInfo* info;
00060     OSensorFrameData* data;
00061 
00062     while (iter != last) {
00063 
00064         sv = (OSensorFrameVectorData*)(*iter)->Base();
00065         info = sv->GetInfo(sensoridx[PAN_INDEX]);
00066         longword fn = info->frameNumber;
00067 
00068         for (int i = 0; i < info->numFrames; i++) {
00069 
00070             if (fn == frameNum) {
00071 
00072                 data = sv->GetData(sensoridx[PAN_INDEX]);
00073                 *pan = degrees((double)data->frame[i].value / 1000000.0);
00074 
00075                 data = sv->GetData(sensoridx[TILT2_INDEX]);
00076                 *tilt = degrees((double)data->frame[i].value / 1000000.0);
00077 
00078                 return;
00079             }
00080 
00081             fn++;
00082             if (fn > oframeMAX_NUMBER) fn = 1;
00083         }
00084         
00085         ++iter;
00086     }
00087 
00088     //
00089     // If sensor data at frameNum is not found, 
00090     // return latest sensor data.
00091     //
00092     RCRegion* rgn = sensorRegions.back();
00093     sv = (OSensorFrameVectorData*)rgn->Base();
00094     info = sv->GetInfo(sensoridx[PAN_INDEX]);
00095 
00096     data = sv->GetData(sensoridx[PAN_INDEX]);
00097     *pan = degrees((double)data->frame[info->numFrames-1].value / 1000000.0);
00098 
00099     data = sv->GetData(sensoridx[TILT2_INDEX]);
00100     *tilt = degrees((double)data->frame[info->numFrames-1].value / 1000000.0);
00101 }

Generated on Sun Dec 2 23:04:27 2007 for openSDK by  doxygen 1.3.9.1