MovingEar7.cc

Go to the documentation of this file.
00001 //
00002 // Copyright 2003 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 <OPENR/OSyslog.h>
00014 #include <OPENR/core_macro.h>
00015 #include "MovingEar7.h"
00016 
00017 MovingEar7::MovingEar7() : movingEarState(MES_IDLE)
00018 {
00019     for (int i = 0; i < NUM_EARS; i++) earID[i] = oprimitiveID_UNDEF;
00020     for (int i = 0; i < NUM_COMMAND_VECTOR; i++) region[i] = 0;
00021 }
00022 
00023 OStatus
00024 MovingEar7::DoInit(const OSystemEvent& event)
00025 {
00026     OSYSDEBUG(("MovingEar7::DoInit()\n"));
00027 
00028     NEW_ALL_SUBJECT_AND_OBSERVER;
00029     REGISTER_ALL_ENTRY;
00030     SET_ALL_READY_AND_NOTIFY_ENTRY;
00031 
00032     OpenPrimitives();
00033     NewCommandVectorData();
00034 
00035     // 
00036     // OPENR::SetMotorPower(opowerON) is executed in blinkingLED.
00037     // So, it isn't necessary here.
00038     //
00039     
00040     return oSUCCESS;
00041 }
00042 
00043 OStatus
00044 MovingEar7::DoStart(const OSystemEvent& event)
00045 {
00046     OSYSDEBUG(("MovingEar7::DoStart()\n"));
00047 
00048     ENABLE_ALL_SUBJECT;
00049     ASSERT_READY_TO_ALL_OBSERVER;
00050 
00051     MoveEar();
00052     movingEarState = MES_START;
00053 
00054     return oSUCCESS;
00055 }
00056 
00057 OStatus
00058 MovingEar7::DoStop(const OSystemEvent& event)
00059 {
00060     OSYSDEBUG(("MovingEar7::DoStop()\n"));
00061 
00062     movingEarState = MES_IDLE;
00063 
00064     DISABLE_ALL_SUBJECT;
00065     DEASSERT_READY_TO_ALL_OBSERVER;
00066 
00067     return oSUCCESS;
00068 }
00069 
00070 OStatus
00071 MovingEar7::DoDestroy(const OSystemEvent& event)
00072 {
00073     DELETE_ALL_SUBJECT_AND_OBSERVER;
00074     return oSUCCESS;
00075 }
00076 
00077 void
00078 MovingEar7::Ready(const OReadyEvent& event)
00079 {
00080     OSYSDEBUG(("MovingEar7::Ready()\n"));
00081 
00082     if (movingEarState == MES_START) {
00083         OSYSDEBUG(("MES_START\n"));
00084         MoveEar();
00085     }
00086 }
00087 
00088 void
00089 MovingEar7::OpenPrimitives()
00090 {
00091     for (int i = 0; i < NUM_EARS; i++) {
00092         OStatus result = OPENR::OpenPrimitive(EAR_LOCATOR[i], &earID[i]);
00093         if (result != oSUCCESS) {
00094             OSYSLOG1((osyslogERROR, "%s : %s %d",
00095                       "MovingEar7::OpenPrimitives()",
00096                       "OPENR::OpenPrimitive() FAILED", result));
00097         }
00098     }
00099 }
00100 
00101 void
00102 MovingEar7::NewCommandVectorData()
00103 {
00104     OStatus result;
00105     MemoryRegionID      cmdVecDataID;
00106     OCommandVectorData* cmdVecData;
00107 
00108     for (int i = 0; i < NUM_COMMAND_VECTOR; i++) {
00109 
00110         result = OPENR::NewCommandVectorData(NUM_EARS, 
00111                                              &cmdVecDataID, &cmdVecData);
00112         if (result != oSUCCESS) {
00113             OSYSLOG1((osyslogERROR, "%s : %s %d",
00114                       "MovingEar7::NewCommandVectorData()",
00115                       "OPENR::NewCommandVectorData() FAILED", result));
00116         }
00117 
00118         region[i] = new RCRegion(cmdVecData->vectorInfo.memRegionID,
00119                                  cmdVecData->vectorInfo.offset,
00120                                  (void*)cmdVecData,
00121                                  cmdVecData->vectorInfo.totalSize);
00122 
00123         cmdVecData->SetNumData(NUM_EARS);
00124 
00125         // 
00126         // Left ear  : earID[0] PRM:/r1/c1/c2/c3/e5-Joint4:15
00127         // Right ear : earID[1] PRM:/r1/c1/c2/c3/e6-Joint4:16
00128         //
00129         //                    Left ear        Right ear
00130         // -------------------------------------------------
00131         // region[0] val[0] : ojoint4_STATE1  ojoint4_STATE0
00132         //           val[1] : ojoint4_STATE0  ojoint4_STATE0
00133         //           val[2] : ojoint4_STATE0  ojoint4_STATE0
00134         //           val[3] : ojoint4_STATE0  ojoint4_STATE0
00135         //           val[4] : ojoint4_STATE0  ojoint4_STATE0
00136         //           val[5] : ojoint4_STATE0  ojoint4_STATE0
00137         //           val[6] : ojoint4_STATE0  ojoint4_STATE0
00138         //           val[7] : ojoint4_STATE0  ojoint4_STATE0
00139         // region[1] val[0] : ojoint4_STATE0  ojoint4_STATE1
00140         //           val[1] : ojoint4_STATE0  ojoint4_STATE0
00141         //           val[2] : ojoint4_STATE0  ojoint4_STATE0
00142         //           val[3] : ojoint4_STATE0  ojoint4_STATE0
00143         //           val[4] : ojoint4_STATE0  ojoint4_STATE0
00144         //           val[5] : ojoint4_STATE0  ojoint4_STATE0
00145         //           val[6] : ojoint4_STATE0  ojoint4_STATE0
00146         //           val[7] : ojoint4_STATE0  ojoint4_STATE0
00147         //
00148         {
00149             // Left ear
00150             OCommandInfo* info = cmdVecData->GetInfo(0);
00151             info->Set(odataJOINT_COMMAND4, earID[0], ocommandMAX_FRAMES);
00152 
00153             OCommandData* data = cmdVecData->GetData(0);
00154             OJointCommandValue4* val = (OJointCommandValue4*)data->value;
00155             for (int k = 0; k < ocommandMAX_FRAMES; k++) {
00156                 if (i == 0 && k == 0) {
00157                     val[k].value = ojoint4_STATE1;
00158                 } else {
00159                     val[k].value = ojoint4_STATE0;
00160                 }
00161                 val[k].period = 16;
00162             }
00163         }
00164 
00165         {
00166             // Right ear
00167             OCommandInfo* info = cmdVecData->GetInfo(1);
00168             info->Set(odataJOINT_COMMAND4, earID[1], ocommandMAX_FRAMES);
00169 
00170             OCommandData* data = cmdVecData->GetData(1);
00171             OJointCommandValue4* val = (OJointCommandValue4*)data->value;
00172             for (int k = 0; k < ocommandMAX_FRAMES; k++) {
00173                 if (i == 1 && k == 0) {
00174                     val[k].value = ojoint4_STATE1;
00175                 } else {
00176                     val[k].value = ojoint4_STATE0;
00177                 }
00178                 val[k].period = 16;
00179             }
00180         }
00181     }
00182 }
00183 
00184 void
00185 MovingEar7::MoveEar()
00186 {
00187     static int index = -1;
00188 
00189     if (index == -1) { // MoveEar() is called first time.
00190         index = 0;
00191         subject[sbjMove]->SetData(region[index]);
00192         index++;
00193     } 
00194 
00195     subject[sbjMove]->SetData(region[index]);
00196     subject[sbjMove]->NotifyObservers();
00197 
00198     index++;
00199     index = index % NUM_COMMAND_VECTOR;
00200 }

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