MTNAgent7.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/OPENRAPI.h>
00013 #include "MTNAgent7.h"
00014 
00015 static const int DRX1000_INDEX[] = {
00016     HEAD_TILT1,
00017     HEAD_PAN,
00018     HEAD_TILT2,
00019     MOUTH,
00020     LEFT_EAR,
00021     RIGHT_EAR,
00022     LFLEG_J1,
00023     LFLEG_J2,
00024     LFLEG_J3,
00025     LRLEG_J1,
00026     LRLEG_J2,
00027     LRLEG_J3,
00028     RFLEG_J1,
00029     RFLEG_J2,
00030     RFLEG_J3,
00031     RRLEG_J1,
00032     RRLEG_J2,
00033     RRLEG_J3,
00034     TAIL_TILT,
00035     TAIL_PAN
00036 };    
00037 
00038 MTNAgent7::MTNAgent7() : motionODA(0), mtn()
00039 {
00040 }
00041 
00042 void
00043 MTNAgent7::Init(ODA* oda)
00044 {
00045     motionODA = oda;
00046 }
00047 
00048 bool
00049 MTNAgent7::AreYou(MoNetAgentID agent)
00050 {
00051     OSYSDEBUG(("MTNAgent7::AreYou(%d)\n", agent));
00052     return (agent == monetagentMTN) ? true : false;
00053 }
00054 
00055 void
00056 MTNAgent7::NotifyCommand(const MoNetAgentCommand& command,
00057                         MoNetAgentResult* result)
00058 {
00059     OSYSDEBUG(("MTNAgent7::NotifyCommand()\n"));
00060     OSYSDEBUG(("  agent        : %d\n",   command.agent));
00061     OSYSDEBUG(("  index        : %d\n",   command.index));
00062     OSYSDEBUG(("  syncKey      : %08x\n", command.syncKey));
00063     OSYSDEBUG(("  startPosture : %d\n",   command.startPosture));
00064     OSYSDEBUG(("  endPosture   : %d\n",   command.endPosture));
00065 
00066     if (command.index == monetagentMTN_NULL_MOTION) {
00067         result->agent      = command.agent;
00068         result->index      = command.index;
00069         result->status     = monetCOMPLETION;
00070         result->endPosture = command.endPosture;
00071         return;
00072     }
00073 
00074     MTNFile* mtnfile = (MTNFile*)motionODA->GetData(command.index);
00075     if (mtnfile == 0) {
00076         result->agent      = command.agent;
00077         result->index      = command.index;
00078         result->status     = monetINVALID_ARG;
00079         result->endPosture = command.startPosture;
00080         return;
00081     }
00082     
00083     mtn.Set(mtnfile);
00084     MoNetStatus status = Move(command.syncKey);
00085 
00086     result->agent      = command.agent;
00087     result->index      = command.index;
00088     result->status     = status;
00089     result->endPosture = monetpostureUNDEF;
00090 }
00091 
00092 void
00093 MTNAgent7::ReadyEffector(const MoNetAgentCommand& command,
00094                         MoNetAgentResult* result)
00095 {
00096     result->agent      = command.agent;
00097     result->index      = command.index;
00098     result->endPosture = monetpostureUNDEF;
00099 
00100     MoNetStatus status = Move(ovrsynckeyUNDEF);
00101     if (status == monetCOMPLETION) {
00102         result->endPosture = command.endPosture;
00103     }
00104 
00105     result->status = status;
00106 }
00107 
00108 MoNetStatus
00109 MTNAgent7::Move(OVRSyncKey syncKey)
00110 {
00111     RCRegion* rgn = moNetAgentManager->FindFreeCommandRegion();
00112     OCommandVectorData* cmdVecData = (OCommandVectorData*)rgn->Base();
00113     cmdVecData->vectorInfo.syncKey = syncKey;
00114 
00115     MoNetStatus st = SetPrimitiveID(cmdVecData, mtn.GetRobotDesign());
00116     if (st != monetSUCCESS) {
00117         OSYSLOG1((osyslogERROR, "%s : %s %s",
00118                   "MTNAgent7::Move()",
00119                   "SetPrimitiveID() FAILED", mtn.GetName()));
00120         return monetINVALID_ARG;
00121     }
00122 
00123     int nframes = mtn.InterpolateCommandVectorData(cmdVecData, NUM_FRAMES);
00124     if (nframes == -1) {
00125         OSYSLOG1((osyslogERROR, "%s : %s %s",
00126                   "MTNAgent7::Move()",
00127                   "mtn.InterpolateCommandVectorData() FAILED", mtn.GetName()));
00128         return monetINVALID_ARG;
00129     }
00130 
00131     mtn.Next(nframes);
00132 
00133     moNetAgentManager->Effector()->SetData(rgn);
00134     moNetAgentManager->Effector()->NotifyObservers();
00135 
00136     return (mtn.More() == true) ? monetSUCCESS : monetCOMPLETION;
00137 }
00138 
00139 MoNetStatus
00140 MTNAgent7::SetPrimitiveID(OCommandVectorData* cmdVec, char* robotDesign)
00141 {
00142     if (strcmp(robotDesign, "DRX-1000") == 0) {
00143 
00144         if (cmdVec->vectorInfo.maxNumData < DRX1000_NUM_JOINTS) {
00145             return monetINVALID_ARG;
00146         }
00147 
00148         for (int i = 0; i < DRX1000_NUM_JOINTS; i++) {
00149             OCommandInfo* info = cmdVec->GetInfo(i);
00150             OPrimitiveID id = moNetAgentManager->PrimitiveID(DRX1000_INDEX[i]);
00151             info->Set(odataJOINT_COMMAND2, id, 0);
00152         }
00153 
00154         cmdVec->SetNumData(DRX1000_NUM_JOINTS);
00155 
00156         return monetSUCCESS;
00157 
00158     } else {
00159 
00160         return monetINVALID_ARG;
00161 
00162     }
00163 }
00164 
00165 void
00166 MTNAgent7::SetJointGain()
00167 {
00168     OSYSDEBUG(("MTNAgent7::SetJointGain()\n"));
00169 
00170     OPrimitiveID tilt1ID = moNetAgentManager->PrimitiveID(HEAD_TILT1);
00171     OPrimitiveID panID   = moNetAgentManager->PrimitiveID(HEAD_PAN);
00172     OPrimitiveID tilt2ID = moNetAgentManager->PrimitiveID(HEAD_TILT2);
00173 
00174     OPENR::EnableJointGain(tilt1ID);
00175     OPENR::SetJointGain(tilt1ID,
00176                         TILT1_PGAIN, TILT1_IGAIN, TILT1_DGAIN,
00177                         PSHIFT, ISHIFT, DSHIFT);
00178     
00179     OPENR::EnableJointGain(panID);
00180     OPENR::SetJointGain(panID,
00181                         PAN_PGAIN, PAN_IGAIN, PAN_DGAIN,
00182                         PSHIFT, ISHIFT, DSHIFT);
00183 
00184     OPENR::EnableJointGain(tilt2ID);
00185     OPENR::SetJointGain(tilt2ID,
00186                         TILT2_PGAIN, TILT2_IGAIN, TILT2_DGAIN,
00187                         PSHIFT, ISHIFT, DSHIFT);
00188 
00189     int base = RFLEG_J1;
00190     for (int i = 0; i < 4; i++) {
00191 
00192         OPrimitiveID j1ID = moNetAgentManager->PrimitiveID(base + 3 * i);
00193         OPrimitiveID j2ID = moNetAgentManager->PrimitiveID(base + 3 * i + 1);
00194         OPrimitiveID j3ID = moNetAgentManager->PrimitiveID(base + 3 * i + 2);
00195         
00196         OPENR::EnableJointGain(j1ID);        
00197         OPENR::SetJointGain(j1ID,
00198                             J1_PGAIN, J1_IGAIN, J1_DGAIN,
00199                             PSHIFT, ISHIFT, DSHIFT);
00200 
00201         OPENR::EnableJointGain(j2ID);
00202         OPENR::SetJointGain(j2ID,
00203                             J2_PGAIN, J2_IGAIN, J2_DGAIN,
00204                             PSHIFT, ISHIFT, DSHIFT);
00205 
00206         OPENR::EnableJointGain(j3ID);
00207         OPENR::SetJointGain(j3ID,
00208                             J3_PGAIN, J3_IGAIN, J3_DGAIN,
00209                             PSHIFT, ISHIFT, DSHIFT);
00210     }
00211 
00212     OPrimitiveID tailtiltID = moNetAgentManager->PrimitiveID(TAIL_TILT);
00213     OPrimitiveID tailpanID  = moNetAgentManager->PrimitiveID(TAIL_PAN);
00214 
00215     OPENR::EnableJointGain(tailtiltID);
00216     OPENR::SetJointGain(tailtiltID,
00217                         TAIL_PGAIN, TAIL_IGAIN, TAIL_DGAIN,
00218                         PSHIFT, ISHIFT, DSHIFT);
00219 
00220     OPENR::EnableJointGain(tailpanID);
00221     OPENR::SetJointGain(tailpanID,
00222                         TAIL_PGAIN, TAIL_IGAIN, TAIL_DGAIN,
00223                         PSHIFT, ISHIFT, DSHIFT);
00224 }

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