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 "BallTrackingHead7.h"
00016
00017 BallTrackingHead7::BallTrackingHead7() : state(BTHS7_IDLE),
00018 fbkID(oprimitiveID_UNDEF),
00019 initSensorIndex(false),
00020 sensorRegions(),
00021 lastRefPan(0),
00022 lastRefTilt(0)
00023 {
00024 for (int i = 0; i < NUM_JOINTS; i++) {
00025 jointID[i] = oprimitiveID_UNDEF;
00026 sensoridx[i] = -1;
00027 }
00028 for (int i = 0; i < NUM_COMMAND_VECTOR; i++) region[i] = 0;
00029 }
00030
00031 OStatus
00032 BallTrackingHead7::DoInit(const OSystemEvent& event)
00033 {
00034 OSYSDEBUG(("BallTrackingHead7::DoInit()\n"));
00035
00036 NEW_ALL_SUBJECT_AND_OBSERVER;
00037 REGISTER_ALL_ENTRY;
00038 SET_ALL_READY_AND_NOTIFY_ENTRY;
00039
00040 OpenPrimitives();
00041 NewCommandVectorData();
00042 SetCdtVectorDataOfPinkBall();
00043
00044 return oSUCCESS;
00045 }
00046
00047 OStatus
00048 BallTrackingHead7::DoStart(const OSystemEvent& event)
00049 {
00050 OSYSDEBUG(("BallTrackingHead7::DoStart()\n"));
00051
00052 Execute(STAND2STAND_NULL);
00053 state = BTHS7_WAITING_STAND2STAND_RESULT;
00054
00055 ENABLE_ALL_SUBJECT;
00056 ASSERT_READY_TO_ALL_OBSERVER;
00057
00058 return oSUCCESS;
00059 }
00060
00061 OStatus
00062 BallTrackingHead7::DoStop(const OSystemEvent& event)
00063 {
00064 OSYSDEBUG(("BallTrackingHead7::DoStop()\n"));
00065
00066 state = BTHS7_IDLE;
00067
00068 DISABLE_ALL_SUBJECT;
00069 DEASSERT_READY_TO_ALL_OBSERVER;
00070
00071 return oSUCCESS;
00072 }
00073
00074 OStatus
00075 BallTrackingHead7::DoDestroy(const OSystemEvent& event)
00076 {
00077 DELETE_ALL_SUBJECT_AND_OBSERVER;
00078 return oSUCCESS;
00079 }
00080
00081 void
00082 BallTrackingHead7::NotifyResult(const ONotifyEvent& event)
00083 {
00084 MoNetResult* result = (MoNetResult*)event.Data(0);
00085 if (result->status != monetCOMPLETION &&
00086 result->status != monetBUSY) {
00087 OSYSLOG1((osyslogERROR,
00088 "%s : MoNetResult error [commandID %d,status %d]",
00089 "BallTrackingHead7::NotifyResult()",
00090 result->commandID, result->status));
00091 }
00092
00093 if (state == BTHS7_IDLE) {
00094
00095 ;
00096
00097 } else if (state == BTHS7_WAITING_STAND2STAND_RESULT) {
00098
00099 SearchBall();
00100 state = BTHS7_SEARCHING_BALL;
00101
00102 } else {
00103
00104 if (result->status == monetBUSY) {
00105 if (result->commandID == PLAY_FOUND_SOUND) {
00106 OSYSPRINT(("Execute(PLAY_FOUND_SOUND) monetBUSY\n"));
00107 } else if (result->commandID == PLAY_LOST_SOUND) {
00108 OSYSPRINT(("Execute(PLAY_LOST_SOUND) monetBUSY\n"));
00109 }
00110 }
00111
00112 }
00113
00114 observer[event.ObsIndex()]->AssertReady();
00115 }
00116
00117 void
00118 BallTrackingHead7::OpenPrimitives()
00119 {
00120 OStatus result;
00121
00122 for (int i = 0; i < NUM_JOINTS; i++) {
00123 result = OPENR::OpenPrimitive(JOINT_LOCATOR[i], &jointID[i]);
00124 if (result != oSUCCESS) {
00125 OSYSLOG1((osyslogERROR, "%s : %s %d",
00126 "BallTrackingHead7::OpenPrimitives()",
00127 "OPENR::OpenPrimitive() FAILED", result));
00128 }
00129 }
00130
00131 result = OPENR::OpenPrimitive(FBK_LOCATOR, &fbkID);
00132 if (result != oSUCCESS) {
00133 OSYSLOG1((osyslogERROR, "%s : %s %d",
00134 "BallTrackingHead7::OpenPrimitives()",
00135 "OPENR::OpenPrimitive() FAILED", result));
00136 }
00137 }
00138
00139 void
00140 BallTrackingHead7::NewCommandVectorData()
00141 {
00142 OStatus result;
00143 MemoryRegionID cmdVecDataID;
00144 OCommandVectorData* cmdVecData;
00145 OCommandInfo* info;
00146
00147 for (int i = 0; i < NUM_COMMAND_VECTOR; i++) {
00148
00149 result = OPENR::NewCommandVectorData(NUM_JOINTS,
00150 &cmdVecDataID, &cmdVecData);
00151 if (result != oSUCCESS) {
00152 OSYSLOG1((osyslogERROR, "%s : %s %d",
00153 "BallTrackingHead7::NewCommandVectorData()",
00154 "OPENR::NewCommandVectorData() FAILED", result));
00155 }
00156
00157 region[i] = new RCRegion(cmdVecData->vectorInfo.memRegionID,
00158 cmdVecData->vectorInfo.offset,
00159 (void*)cmdVecData,
00160 cmdVecData->vectorInfo.totalSize);
00161
00162 cmdVecData->SetNumData(NUM_JOINTS);
00163
00164 for (int j = 0; j < NUM_JOINTS; j++) {
00165 info = cmdVecData->GetInfo(j);
00166 info->Set(odataJOINT_COMMAND2, jointID[j], NUM_FRAMES);
00167 }
00168 }
00169 }
00170
00171 void
00172 BallTrackingHead7::Execute(MoNetCommandID cmdID)
00173 {
00174 MoNetCommand cmd(cmdID);
00175 subject[sbjCommand]->SetData(&cmd, sizeof(cmd));
00176 subject[sbjCommand]->NotifyObservers();
00177 }