00001
00002
00003
00004
00005
00006 #include "ProcessFramework.h"
00007 #include "Tools/Debugging/Debugging.h"
00008
00009 MotorCommandsSender::MotorCommandsSender(PlatformProcess* process,bool blocking)
00010 : SenderBase<MotorCommands>(process,"Sender.OCommandVectorData.S",blocking),
00011 jointGainsSet(false)
00012 {
00013 package = 0;
00014 numOfLED = SystemCall::getRobotDesign() == RobotDesign::ERS210 ? LEDValue::numOfLED_ERS210 : LEDValue::numOfLED_ERS7;
00015 VERIFY(OPENR::NewCommandVectorData(JointData::numOfJoint + numOfLED,&memID,&cmdVec) == oSUCCESS);
00016 cmdVec->SetNumData(JointData::numOfJoint + numOfLED);
00017
00018 OPENR::SetMotorPower(opowerON);
00019
00020 for(int i = 0; i < JointData::numOfJoint; i++)
00021 {
00022 OPENR::OpenPrimitive((const char*) getPrimitiveJointName(i),&jointId[i]);
00023 OPENR::EnableJointGain(jointId[i]);
00024 OCommandInfo* info = cmdVec->GetInfo(i);
00025 info->Set(odataJOINT_COMMAND2,jointId[i],jointDataBufferNumOfFrames);
00026 }
00027
00028 OPrimitiveID id;
00029
00030 if(SystemCall::getRobotDesign() == RobotDesign::ERS7)
00031 {
00032 for(int i = 0; i < numOfLED; i++)
00033 {
00034 OPENR::OpenPrimitive((const char*) getPrimitiveLEDName(i),&id);
00035 OCommandInfo* info = cmdVec->GetInfo(JointData::numOfJoint + i);
00036 if (i < (int)LEDValue::face1)
00037 {
00038 info->Set(odataLED_COMMAND2,id,jointDataBufferNumOfFrames);
00039 }
00040 else
00041 {
00042 info->Set(odataLED_COMMAND3,id,jointDataBufferNumOfFrames);
00043 }
00044 }
00045 }
00046 else
00047 {
00048 for(int i = 0; i < numOfLED; i++)
00049 {
00050 OPENR::OpenPrimitive((const char*) getPrimitiveLEDName(i),&id);
00051 OCommandInfo* info = cmdVec->GetInfo(JointData::numOfJoint + i);
00052 info->Set(odataLED_COMMAND2,id,jointDataBufferNumOfFrames);
00053 }
00054 }
00055 }
00056
00057 MotorCommandsSender::~MotorCommandsSender()
00058 {
00059 VERIFY(OPENR::DeleteCommandVectorData(memID) == oSUCCESS);
00060 }
00061
00062 void MotorCommandsSender::preparePackage()
00063 {
00064 if(!package)
00065 package = new RCRegion(cmdVec->vectorInfo.memRegionID,
00066 cmdVec->vectorInfo.offset,
00067 (void*) cmdVec,
00068 cmdVec->vectorInfo.totalSize);
00069
00070 const MotorCommands& motorCommands = *static_cast<const MotorCommands*>(this);
00071
00072 for (int i = 0; i < JointData::numOfJoint; i++)
00073 if(!jointGainsSet ||
00074 motorCommands.pidData.p[i] != lastPidData.p[i] ||
00075 motorCommands.pidData.i[i] != lastPidData.i[i] ||
00076 motorCommands.pidData.d[i] != lastPidData.d[i])
00077 {
00078 OPENR::SetJointGain(jointId[i],
00079 motorCommands.pidData.p[i],
00080 motorCommands.pidData.i[i],
00081 motorCommands.pidData.d[i],
00082 0x0E, 0x02, 0x0F);
00083 lastPidData.p[i] = motorCommands.pidData.p[i];
00084 lastPidData.i[i] = motorCommands.pidData.i[i];
00085 lastPidData.d[i] = motorCommands.pidData.d[i];
00086 }
00087 jointGainsSet = true;
00088
00089 long value;
00090 for(int k = 0; k < JointData::numOfJoint; ++k)
00091 {
00092 OCommandData* data = cmdVec->GetData(k);
00093 for(int l = 0; l < jointDataBufferNumOfFrames; ++l)
00094 {
00095 value = motorCommands.jointDataBuffer.frame[l].data[k];
00096 if(value == jointDataInvalidValue)
00097 value = 0;
00098 ((OJointCommandValue2 *)data->value)[l].value = value;
00099 }
00100 }
00101
00102 if(SystemCall::getRobotDesign() == RobotDesign::ERS7)
00103 {
00104 for(int k = 0; k < numOfLED; ++k)
00105 {
00106 OCommandData* data = cmdVec->GetData(JointData::numOfJoint + k);
00107 if ( k < (int)LEDValue::face1 )
00108 {
00109 for(int l = 0; l < jointDataBufferNumOfFrames; l++)
00110 {
00111 ((OLEDCommandValue2 *)data->value)[l].period = 1;
00112 ((OLEDCommandValue2 *)data->value)[l].led = (motorCommands.ledValue.data[l] >> k) & 1;
00113 }
00114 }
00115 else
00116 {
00117 if (k <(int)LEDValue::backFrontBlue)
00118 {
00119 for(int l = 0; l < jointDataBufferNumOfFrames; l++)
00120 {
00121 ((OLEDCommandValue3 *)data->value)[l].period = 1;
00122 ((OLEDCommandValue3 *)data->value)[l].intensity = ((motorCommands.ledValue.data[l] >> k) & 1)*255;
00123 ((OLEDCommandValue3 *)data->value)[l].mode = oled3_MODE_B;
00124 }
00125 }
00126 else
00127 {
00128 for(int l = 0; l < jointDataBufferNumOfFrames; l++)
00129 {
00130 ((OLEDCommandValue3 *)data->value)[l].period = 1;
00131 ((OLEDCommandValue3 *)data->value)[l].intensity = ((motorCommands.ledValue.data[l] >> k) & 1)*255;
00132 ((OLEDCommandValue3 *)data->value)[l].mode = oled3_MODE_UNDEF;
00133 }
00134 }
00135 }
00136 }
00137 }
00138 else
00139 {
00140 for(int k = 0; k < numOfLED; ++k)
00141 {
00142 OCommandData* data = cmdVec->GetData(JointData::numOfJoint + k);
00143 for(int l = 0; l < jointDataBufferNumOfFrames; l++)
00144 {
00145 ((OLEDCommandValue2 *)data->value)[l].period = 1;
00146 ((OLEDCommandValue2 *)data->value)[l].led = (motorCommands.ledValue.data[l] >> k) & 1;
00147 }
00148 }
00149 }
00150 }
00151
00152 void MotorCommandsSender::setPackage(const ObserverID& receiver)
00153 {
00154 VERIFY(SetData(receiver,package) == oSUCCESS);
00155 }
00156
00157 void MotorCommandsSender::freePackage()
00158 {
00159
00160 }
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245