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 "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
00037
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
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 {
00149
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
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) {
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 }