00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <OPENR/OPENRAPI.h>
00013 #include <OPENR/OSyslog.h>
00014 #include <OPENR/core_macro.h>
00015 #include "MovingEar.h"
00016
00017 MovingEar::MovingEar() : 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 MovingEar::DoInit(const OSystemEvent& event)
00025 {
00026 OSYSDEBUG(("MovingEar::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
00037
00038
00039
00040 return oSUCCESS;
00041 }
00042
00043 OStatus
00044 MovingEar::DoStart(const OSystemEvent& event)
00045 {
00046 OSYSDEBUG(("MovingEar::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 MovingEar::DoStop(const OSystemEvent& event)
00059 {
00060 OSYSDEBUG(("MovingEar::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 MovingEar::DoDestroy(const OSystemEvent& event)
00072 {
00073 DELETE_ALL_SUBJECT_AND_OBSERVER;
00074 return oSUCCESS;
00075 }
00076
00077 void
00078 MovingEar::Ready(const OReadyEvent& event)
00079 {
00080 OSYSDEBUG(("MovingEar::Ready()\n"));
00081
00082 if (movingEarState == MES_START) {
00083 OSYSDEBUG(("MES_START\n"));
00084 MoveEar();
00085 }
00086 }
00087
00088 void
00089 MovingEar::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 "MovingEar::OpenPrimitives()",
00096 "OPENR::OpenPrimitive() FAILED", result));
00097 }
00098 }
00099 }
00100
00101 void
00102 MovingEar::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 "MovingEar::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 for (int j = 0; j < NUM_EARS; j++) {
00126 OCommandInfo* info = cmdVecData->GetInfo(j);
00127 info->Set(odataJOINT_COMMAND3, earID[j], ocommandMAX_FRAMES);
00128
00129 OCommandData* data = cmdVecData->GetData(j);
00130 OJointCommandValue3* val = (OJointCommandValue3*)data->value;
00131 for (int k = 0; k < ocommandMAX_FRAMES; k++) {
00132 if (i % 2 == 0) {
00133 val[k].value = ojoint3_STATE0;
00134 } else {
00135 val[k].value = ojoint3_STATE1;
00136 }
00137 }
00138 }
00139 }
00140 }
00141
00142 void
00143 MovingEar::MoveEar()
00144 {
00145 static int index = -1;
00146
00147 if (index == -1) {
00148 index = 0;
00149 subject[sbjMove]->SetData(region[index]);
00150 index++;
00151 }
00152
00153 subject[sbjMove]->SetData(region[index]);
00154 subject[sbjMove]->NotifyObservers();
00155
00156 index++;
00157 index = index % NUM_COMMAND_VECTOR;
00158 }