BallTrackingHead7_Joint.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 <math.h>
00013 #include <OPENR/OPENRAPI.h>
00014 #include <OPENR/OUnits.h>
00015 #include <OPENR/OSyslog.h>
00016 #include <OPENR/ODebug.h>
00017 #include "BallTrackingHead7.h"
00018 
00019 void
00020 BallTrackingHead7::SearchBall()
00021 {
00022     static double phase      = 0.0;
00023     const  double deltaPhase = 0.03;
00024     const  double amplitude  = 70.0; // degrees
00025     
00026     OSYSDEBUG(("BallTrackingHead7::SearchBall()\n"));
00027     if (state != BTHS7_SEARCHING_BALL) {
00028         state = BTHS7_SEARCHING_BALL;
00029         
00030         if (lastRefPan < 0.0) {
00031             phase = lastRefPan / amplitude;
00032         } else {
00033             phase = M_PI - lastRefPan / amplitude;
00034         }
00035     }
00036     
00037     const double panDeltaLimit  = deltaPhase * amplitude; // degrees / 32ms
00038     const double tiltDeltaLimit = 1.0;                    // degrees / 32ms
00039     
00040     double pan  = amplitude * sin(phase);
00041     double tilt = 0.0;
00042     phase += deltaPhase;
00043     
00044     MoveHead(lastRefPan, lastRefTilt,
00045              pan, tilt,
00046              &lastRefPan, &lastRefTilt,
00047              panDeltaLimit, tiltDeltaLimit );
00048 }
00049 
00050 void
00051 BallTrackingHead7::TrackBall(longword frameNum,
00052                              double delta_pan, double delta_tilt)
00053 {
00054     if (state == BTHS7_SEARCHING_BALL) {
00055         state = BTHS7_TRACKING_BALL;
00056     }
00057 
00058     const double panDeltaLimit  = 5.0; // degrees / 32ms
00059     const double tiltDeltaLimit = 5.0; // degrees / 32ms
00060     
00061     double pan, tilt;
00062     GetPanTiltAngle(frameNum, &pan, &tilt);
00063     MoveHead(lastRefPan, lastRefTilt,
00064              pan + delta_pan, tilt + delta_tilt,
00065              &lastRefPan, &lastRefTilt,
00066              panDeltaLimit, tiltDeltaLimit );
00067 }
00068 
00069 void
00070 BallTrackingHead7::MoveHead(double s_pan, double s_tilt, 
00071                             double e_pan, double e_tilt,
00072                             double *r_pan, double *r_tilt,
00073                             double pan_limit, double tilt_limit)
00074 {
00075     RCRegion* rgn = FindFreeRegion();
00076     
00077     if (e_pan > s_pan + pan_limit) {
00078         e_pan = s_pan + pan_limit;
00079     }else
00080         if (e_pan < s_pan - pan_limit) {
00081             e_pan = s_pan - pan_limit;
00082         }
00083     *r_pan = e_pan;
00084     
00085     if (e_tilt > s_tilt + tilt_limit) {
00086         e_tilt = s_tilt + tilt_limit;
00087     }else
00088         if (e_tilt < s_tilt - tilt_limit) {
00089             e_tilt = s_tilt - tilt_limit;
00090         }
00091     *r_tilt = e_tilt;
00092     
00093     SetJointValue(rgn, PAN_INDEX, s_pan, e_pan);
00094     SetJointValue(rgn, TILT2_INDEX, s_tilt, e_tilt);
00095     subject[sbjJoint]->SetData(rgn);
00096     subject[sbjJoint]->NotifyObservers();
00097 }
00098 
00099 void
00100 BallTrackingHead7::SetJointValue(RCRegion* rgn,
00101                                  int idx, double start, double end)
00102 {
00103     OCommandVectorData* cmdVecData = (OCommandVectorData*)rgn->Base();
00104 
00105     OCommandInfo* info = cmdVecData->GetInfo(idx);
00106     info->Set(odataJOINT_COMMAND2, jointID[idx], NUM_FRAMES);
00107 
00108     OCommandData* data = cmdVecData->GetData(idx);
00109     OJointCommandValue2* jval = (OJointCommandValue2*)data->value;
00110 
00111     double delta = end - start;
00112     for (int i = 0; i < NUM_FRAMES; i++) {
00113         double dval = start + (delta * i) / (double)NUM_FRAMES;
00114         jval[i].value = oradians(dval);
00115     }
00116 }
00117 
00118 RCRegion*
00119 BallTrackingHead7::FindFreeRegion()
00120 {
00121     for (int i = 0; i < NUM_COMMAND_VECTOR; i++) {
00122         if (region[i]->NumberOfReference() == 1) return region[i];
00123     }
00124 
00125     return 0;
00126 }

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