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