00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 #include <math.h>
00059
00060
00061 #include <cob_generic_can/CanESD.h>
00062 #include <cob_generic_can/CanPeakSys.h>
00063 #include <cob_generic_can/CanPeakSysUSB.h>
00064 #include <cob_base_drive_chain/CanCtrlPltfCOb3.h>
00065
00066
00067
00068
00069 CanCtrlPltfCOb3::CanCtrlPltfCOb3(std::string iniDirectory)
00070 {
00071 sIniDirectory = iniDirectory;
00072 IniFile iniFile;
00073 iniFile.SetFileName(sIniDirectory + "Platform.ini", "PltfHardwareCoB3.h");
00074
00075
00076 iniFile.GetKeyInt("Config", "NumberOfMotors", &m_iNumMotors, true);
00077 iniFile.GetKeyInt("Config", "NumberOfWheels", &m_iNumDrives, true);
00078
00079 if(m_iNumMotors < 2 || m_iNumMotors > 8) {
00080 m_iNumMotors = 8;
00081 m_iNumDrives = 4;
00082 }
00083
00084
00085 m_pCanCtrl = NULL;
00086
00087
00088 m_vpMotor.resize(m_iNumMotors);
00089
00090 for(int i=0; i<m_iNumMotors; i++)
00091 {
00092 m_vpMotor[i] = NULL;
00093 }
00094
00095 m_viMotorID.resize(m_iNumMotors);
00096
00097
00098 if(m_iNumMotors >= 1)
00099 m_viMotorID[0] = CANNODE_WHEEL1DRIVEMOTOR;
00100 if(m_iNumMotors >= 2)
00101 m_viMotorID[1] = CANNODE_WHEEL1STEERMOTOR;
00102 if(m_iNumMotors >= 3)
00103 m_viMotorID[2] = CANNODE_WHEEL2DRIVEMOTOR;
00104 if(m_iNumMotors >= 4)
00105 m_viMotorID[3] = CANNODE_WHEEL2STEERMOTOR;
00106 if(m_iNumMotors >= 5)
00107 m_viMotorID[4] = CANNODE_WHEEL3DRIVEMOTOR;
00108 if(m_iNumMotors >= 6)
00109 m_viMotorID[5] = CANNODE_WHEEL3STEERMOTOR;
00110 if(m_iNumMotors >= 7)
00111 m_viMotorID[6] = CANNODE_WHEEL4DRIVEMOTOR;
00112 if(m_iNumMotors == 8)
00113 m_viMotorID[7] = CANNODE_WHEEL4STEERMOTOR;
00114
00115
00116 m_Param.dCanTimeout = 7;
00117
00118 if(m_iNumMotors >= 1)
00119 m_Param.iHasWheel1DriveMotor = 0;
00120 if(m_iNumMotors >= 2)
00121 m_Param.iHasWheel1SteerMotor = 0;
00122 if(m_iNumMotors >= 3)
00123 m_Param.iHasWheel2DriveMotor = 0;
00124 if(m_iNumMotors >= 4)
00125 m_Param.iHasWheel2SteerMotor = 0;
00126 if(m_iNumMotors >= 5)
00127 m_Param.iHasWheel3DriveMotor = 0;
00128 if(m_iNumMotors >= 6)
00129 m_Param.iHasWheel3SteerMotor = 0;
00130 if(m_iNumMotors >= 7)
00131 m_Param.iHasWheel4DriveMotor = 0;
00132 if(m_iNumMotors == 8)
00133 m_Param.iHasWheel4SteerMotor = 0;
00134
00135 m_Param.iHasRelayBoard = 0;
00136 m_Param.iHasIOBoard = 0;
00137 m_Param.iHasUSBoard = 0;
00138 m_Param.iHasGyroBoard = 0;
00139 m_Param.iHasRadarBoard = 0;
00140
00141 m_bWatchdogErr = false;
00142
00143
00144
00145
00146
00147
00148 if(m_iNumMotors >= 1)
00149 {
00150 m_CanOpenIDParam.TxPDO1_W1Drive = 0x182;
00151 m_CanOpenIDParam.TxPDO2_W1Drive = 0x282;
00152 m_CanOpenIDParam.RxPDO2_W1Drive = 0x302;
00153 m_CanOpenIDParam.TxSDO_W1Drive = 0x582;
00154 m_CanOpenIDParam.RxSDO_W1Drive = 0x602;
00155 }
00156
00157 if(m_iNumMotors >= 2)
00158 {
00159 m_CanOpenIDParam.TxPDO1_W1Steer = 0x181;
00160 m_CanOpenIDParam.TxPDO2_W1Steer = 0x281;
00161 m_CanOpenIDParam.RxPDO2_W1Steer = 0x301;
00162 m_CanOpenIDParam.TxSDO_W1Steer = 0x581;
00163 m_CanOpenIDParam.RxSDO_W1Steer = 0x601;
00164 }
00165
00166
00167 if(m_iNumMotors >= 3)
00168 {
00169 m_CanOpenIDParam.TxPDO1_W2Drive = 0x184;
00170 m_CanOpenIDParam.TxPDO2_W2Drive = 0x284;
00171 m_CanOpenIDParam.RxPDO2_W2Drive = 0x304;
00172 m_CanOpenIDParam.TxSDO_W2Drive = 0x584;
00173 m_CanOpenIDParam.RxSDO_W2Drive = 0x604;
00174 }
00175
00176 if(m_iNumMotors >= 4)
00177 {
00178 m_CanOpenIDParam.TxPDO1_W2Steer = 0x183;
00179 m_CanOpenIDParam.TxPDO2_W2Steer = 0x283;
00180 m_CanOpenIDParam.RxPDO2_W2Steer = 0x303;
00181 m_CanOpenIDParam.TxSDO_W2Steer = 0x583;
00182 m_CanOpenIDParam.RxSDO_W2Steer = 0x603;
00183 }
00184
00185
00186 if(m_iNumMotors >= 5)
00187 {
00188 m_CanOpenIDParam.TxPDO1_W3Drive = 0x188;
00189 m_CanOpenIDParam.TxPDO2_W3Drive = 0x288;
00190 m_CanOpenIDParam.RxPDO2_W3Drive = 0x308;
00191 m_CanOpenIDParam.TxSDO_W3Drive = 0x588;
00192 m_CanOpenIDParam.RxSDO_W3Drive = 0x608;
00193 }
00194
00195 if(m_iNumMotors >= 6)
00196 {
00197 m_CanOpenIDParam.TxPDO1_W3Steer = 0x187;
00198 m_CanOpenIDParam.TxPDO2_W3Steer = 0x287;
00199 m_CanOpenIDParam.RxPDO2_W3Steer = 0x307;
00200 m_CanOpenIDParam.TxSDO_W3Steer = 0x587;
00201 m_CanOpenIDParam.RxSDO_W3Steer = 0x607;
00202 }
00203
00204
00205 if(m_iNumMotors >= 7)
00206 {
00207 m_CanOpenIDParam.TxPDO1_W4Drive = 0x186;
00208 m_CanOpenIDParam.TxPDO2_W4Drive = 0x286;
00209 m_CanOpenIDParam.RxPDO2_W4Drive = 0x306;
00210 m_CanOpenIDParam.TxSDO_W4Drive = 0x586;
00211 m_CanOpenIDParam.RxSDO_W4Drive = 0x606;
00212 }
00213
00214 if(m_iNumMotors == 8)
00215 {
00216 m_CanOpenIDParam.TxPDO1_W4Steer = 0x185;
00217 m_CanOpenIDParam.TxPDO2_W4Steer = 0x285;
00218 m_CanOpenIDParam.RxPDO2_W4Steer = 0x305;
00219 m_CanOpenIDParam.TxSDO_W4Steer = 0x585;
00220 m_CanOpenIDParam.RxSDO_W4Steer = 0x605;
00221 }
00222 }
00223
00224
00225 CanCtrlPltfCOb3::~CanCtrlPltfCOb3()
00226 {
00227
00228 if (m_pCanCtrl != NULL)
00229 {
00230 delete m_pCanCtrl;
00231 }
00232
00233 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
00234 {
00235 if (m_vpMotor[i] != NULL)
00236 {
00237 delete m_vpMotor[i];
00238 }
00239 }
00240
00241 }
00242
00243
00244 void CanCtrlPltfCOb3::readConfiguration()
00245 {
00246
00247 int iTypeCan = 0;
00248 int iMaxMessages = 0;
00249
00250 DriveParam DriveParamW1DriveMotor;
00251 DriveParam DriveParamW1SteerMotor;
00252 DriveParam DriveParamW2DriveMotor;
00253 DriveParam DriveParamW2SteerMotor;
00254 DriveParam DriveParamW3DriveMotor;
00255 DriveParam DriveParamW3SteerMotor;
00256 DriveParam DriveParamW4DriveMotor;
00257 DriveParam DriveParamW4SteerMotor;
00258
00259 std::string strTypeDrive;
00260 std::string strTypeSteer;
00261
00262 double dScaleToMM;
00263
00264
00265 m_IniFile.SetFileName(sIniDirectory + "Platform.ini", "CanCtrlPltfCOb3.cpp");
00266
00267 m_IniFile.GetKeyInt("Geom", "RadiusWheel", &m_Param.iRadiusWheelMM, true);
00268 m_IniFile.GetKeyInt("Geom", "DistSteerAxisToDriveWheelCenter", &m_Param.iDistSteerAxisToDriveWheelMM, true);
00269
00270 if(m_iNumDrives >= 1)
00271 m_IniFile.GetKeyDouble("DrivePrms", "Wheel1SteerDriveCoupling", &m_Param.dWheel1SteerDriveCoupling, true);
00272 if(m_iNumDrives >= 2)
00273 m_IniFile.GetKeyDouble("DrivePrms", "Wheel2SteerDriveCoupling", &m_Param.dWheel2SteerDriveCoupling, true);
00274 if(m_iNumDrives >= 3)
00275 m_IniFile.GetKeyDouble("DrivePrms", "Wheel3SteerDriveCoupling", &m_Param.dWheel3SteerDriveCoupling, true);
00276 if(m_iNumDrives == 4)
00277 m_IniFile.GetKeyDouble("DrivePrms", "Wheel4SteerDriveCoupling", &m_Param.dWheel4SteerDriveCoupling, true);
00278
00279
00280
00281 m_IniFile.SetFileName(sIniDirectory + "CanCtrl.ini", "CanCtrlPltfCOb3.cpp");
00282
00283 std::cout << "Can configuration of the platform:" << std::endl;
00284
00285
00286 m_IniFile.GetKeyInt("TypeCan", "Can", &iTypeCan, true);
00287 if (iTypeCan == 0)
00288 {
00289 sComposed = sIniDirectory;
00290 sComposed += "CanCtrl.ini";
00291 m_pCanCtrl = new CanPeakSys(sComposed.c_str());
00292 std::cout << "Uses CAN-Peak-Systems dongle" << std::endl;
00293 }
00294 else if (iTypeCan == 1)
00295 {
00296 sComposed = sIniDirectory;
00297 sComposed += "CanCtrl.ini";
00298 m_pCanCtrl = new CANPeakSysUSB(sComposed.c_str());
00299 std::cout << "Uses CAN-Peak-USB" << std::endl;
00300 }
00301 else if (iTypeCan == 2)
00302 {
00303 sComposed = sIniDirectory;
00304 sComposed += "CanCtrl.ini";
00305 m_pCanCtrl = new CanESD(sComposed.c_str(), false);
00306 std::cout << "Uses CAN-ESD-card" << std::endl;
00307 }
00308
00309
00310
00311
00312 if(m_iNumDrives >= 1)
00313 {
00314 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO1_W1Drive", &m_CanOpenIDParam.TxPDO1_W1Drive, true);
00315 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO2_W1Drive", &m_CanOpenIDParam.TxPDO2_W1Drive, true);
00316 m_IniFile.GetKeyInt("CanOpenIDs", "RxPDO2_W1Drive", &m_CanOpenIDParam.RxPDO2_W1Drive, true);
00317 m_IniFile.GetKeyInt("CanOpenIDs", "TxSDO_W1Drive", &m_CanOpenIDParam.TxSDO_W1Drive, true);
00318 m_IniFile.GetKeyInt("CanOpenIDs", "RxSDO_W1Drive", &m_CanOpenIDParam.RxSDO_W1Drive, true);
00319 }
00320
00321 if(m_iNumDrives >= 1)
00322 {
00323 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO1_W1Steer", &m_CanOpenIDParam.TxPDO1_W1Steer, true);
00324 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO2_W1Steer", &m_CanOpenIDParam.TxPDO2_W1Steer, true);
00325 m_IniFile.GetKeyInt("CanOpenIDs", "RxPDO2_W1Steer", &m_CanOpenIDParam.RxPDO2_W1Steer, true);
00326 m_IniFile.GetKeyInt("CanOpenIDs", "TxSDO_W1Steer", &m_CanOpenIDParam.TxSDO_W1Steer, true);
00327 m_IniFile.GetKeyInt("CanOpenIDs", "RxSDO_W1Steer", &m_CanOpenIDParam.RxSDO_W1Steer, true);
00328 }
00329
00330
00331
00332 if(m_iNumDrives >= 2)
00333 {
00334 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO1_W2Drive", &m_CanOpenIDParam.TxPDO1_W2Drive, true);
00335 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO2_W2Drive", &m_CanOpenIDParam.TxPDO2_W2Drive, true);
00336 m_IniFile.GetKeyInt("CanOpenIDs", "RxPDO2_W2Drive", &m_CanOpenIDParam.RxPDO2_W2Drive, true);
00337 m_IniFile.GetKeyInt("CanOpenIDs", "TxSDO_W2Drive", &m_CanOpenIDParam.TxSDO_W2Drive, true);
00338 m_IniFile.GetKeyInt("CanOpenIDs", "RxSDO_W2Drive", &m_CanOpenIDParam.RxSDO_W2Drive, true);
00339 }
00340
00341 if(m_iNumDrives >= 2)
00342 {
00343 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO1_W2Steer", &m_CanOpenIDParam.TxPDO1_W2Steer, true);
00344 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO2_W2Steer", &m_CanOpenIDParam.TxPDO2_W2Steer, true);
00345 m_IniFile.GetKeyInt("CanOpenIDs", "RxPDO2_W2Steer", &m_CanOpenIDParam.RxPDO2_W2Steer, true);
00346 m_IniFile.GetKeyInt("CanOpenIDs", "TxSDO_W2Steer", &m_CanOpenIDParam.TxSDO_W2Steer, true);
00347 m_IniFile.GetKeyInt("CanOpenIDs", "RxSDO_W2Steer", &m_CanOpenIDParam.RxSDO_W2Steer, true);
00348 }
00349
00350
00351
00352 if(m_iNumDrives >= 3)
00353 {
00354 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO1_W3Drive", &m_CanOpenIDParam.TxPDO1_W3Drive, true);
00355 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO2_W3Drive", &m_CanOpenIDParam.TxPDO2_W3Drive, true);
00356 m_IniFile.GetKeyInt("CanOpenIDs", "RxPDO2_W3Drive", &m_CanOpenIDParam.RxPDO2_W3Drive, true);
00357 m_IniFile.GetKeyInt("CanOpenIDs", "TxSDO_W3Drive", &m_CanOpenIDParam.TxSDO_W3Drive, true);
00358 m_IniFile.GetKeyInt("CanOpenIDs", "RxSDO_W3Drive", &m_CanOpenIDParam.RxSDO_W3Drive, true);
00359 }
00360
00361 if(m_iNumDrives >= 3)
00362 {
00363 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO1_W3Steer", &m_CanOpenIDParam.TxPDO1_W3Steer, true);
00364 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO2_W3Steer", &m_CanOpenIDParam.TxPDO2_W3Steer, true);
00365 m_IniFile.GetKeyInt("CanOpenIDs", "RxPDO2_W3Steer", &m_CanOpenIDParam.RxPDO2_W3Steer, true);
00366 m_IniFile.GetKeyInt("CanOpenIDs", "TxSDO_W3Steer", &m_CanOpenIDParam.TxSDO_W3Steer, true);
00367 m_IniFile.GetKeyInt("CanOpenIDs", "RxSDO_W3Steer", &m_CanOpenIDParam.RxSDO_W3Steer, true);
00368 }
00369
00370
00371
00372 if(m_iNumDrives >= 4)
00373 {
00374 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO1_W4Drive", &m_CanOpenIDParam.TxPDO1_W4Drive, true);
00375 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO2_W4Drive", &m_CanOpenIDParam.TxPDO2_W4Drive, true);
00376 m_IniFile.GetKeyInt("CanOpenIDs", "RxPDO2_W4Drive", &m_CanOpenIDParam.RxPDO2_W4Drive, true);
00377 m_IniFile.GetKeyInt("CanOpenIDs", "TxSDO_W4Drive", &m_CanOpenIDParam.TxSDO_W4Drive, true);
00378 m_IniFile.GetKeyInt("CanOpenIDs", "RxSDO_W4Drive", &m_CanOpenIDParam.RxSDO_W4Drive, true);
00379 }
00380
00381 if(m_iNumDrives == 4)
00382 {
00383 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO1_W4Steer", &m_CanOpenIDParam.TxPDO1_W4Steer, true);
00384 m_IniFile.GetKeyInt("CanOpenIDs", "TxPDO2_W4Steer", &m_CanOpenIDParam.TxPDO2_W4Steer, true);
00385 m_IniFile.GetKeyInt("CanOpenIDs", "RxPDO2_W4Steer", &m_CanOpenIDParam.RxPDO2_W4Steer, true);
00386 m_IniFile.GetKeyInt("CanOpenIDs", "TxSDO_W4Steer", &m_CanOpenIDParam.TxSDO_W4Steer, true);
00387 m_IniFile.GetKeyInt("CanOpenIDs", "RxSDO_W4Steer", &m_CanOpenIDParam.RxSDO_W4Steer, true);
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 if(m_iNumDrives >= 1)
00406 {
00407 m_IniFile.GetKeyInt("Drive1", "EncIncrPerRevMot", &(m_GearMotDrive1.iEncIncrPerRevMot), true);
00408 m_IniFile.GetKeyDouble("Drive1", "VelMeasFrqHz", &(m_GearMotDrive1.dVelMeasFrqHz), true);
00409 m_IniFile.GetKeyDouble("Drive1", "BeltRatio", &(m_GearMotDrive1.dBeltRatio), true);
00410 m_IniFile.GetKeyDouble("Drive1", "GearRatio", &(m_GearMotDrive1.dGearRatio), true);
00411 m_IniFile.GetKeyInt("Drive1", "Sign", &(m_GearMotDrive1.iSign), true);
00412 m_IniFile.GetKeyDouble("Drive1", "VelMaxEncIncrS", &(m_GearMotDrive1.dVelMaxEncIncrS), true);
00413 m_IniFile.GetKeyDouble("Drive1", "AccIncrS", &(m_GearMotDrive1.dAccIncrS2), true);
00414 m_IniFile.GetKeyDouble("Drive1", "DecIncrS", &(m_GearMotDrive1.dDecIncrS2), true);
00415 m_IniFile.GetKeyInt("Drive1", "EncOffsetIncr",&(m_GearMotDrive1.iEncOffsetIncr),true);
00416 m_IniFile.GetKeyBool("Drive1", "IsSteering", &(m_GearMotDrive1.bIsSteer), true);
00417 m_IniFile.GetKeyDouble("Drive1", "CurrentToTorque", &(m_GearMotDrive1.dCurrentToTorque), false);
00418 m_IniFile.GetKeyDouble("Drive1", "CurrMax", &(m_GearMotDrive1.dCurrMax), false);
00419 m_IniFile.GetKeyInt("Drive1", "HomingDigIn", &(m_GearMotDrive1.iHomingDigIn), false);
00420 }
00421
00422
00423 if(m_iNumDrives >= 2)
00424 {
00425 m_IniFile.GetKeyInt("Drive2", "EncIncrPerRevMot", &(m_GearMotDrive2.iEncIncrPerRevMot), true);
00426 m_IniFile.GetKeyDouble("Drive2", "VelMeasFrqHz", &(m_GearMotDrive2.dVelMeasFrqHz), true);
00427 m_IniFile.GetKeyDouble("Drive2", "BeltRatio", &(m_GearMotDrive2.dBeltRatio), true);
00428 m_IniFile.GetKeyDouble("Drive2", "GearRatio", &(m_GearMotDrive2.dGearRatio), true);
00429 m_IniFile.GetKeyInt("Drive2", "Sign", &(m_GearMotDrive2.iSign), true);
00430 m_IniFile.GetKeyDouble("Drive2", "VelMaxEncIncrS", &(m_GearMotDrive2.dVelMaxEncIncrS), true);
00431 m_IniFile.GetKeyDouble("Drive2", "AccIncrS", &(m_GearMotDrive2.dAccIncrS2), true);
00432 m_IniFile.GetKeyDouble("Drive2", "DecIncrS", &(m_GearMotDrive2.dDecIncrS2), true);
00433 m_IniFile.GetKeyInt("Drive2", "EncOffsetIncr",&(m_GearMotDrive2.iEncOffsetIncr),true);
00434 m_IniFile.GetKeyBool("Drive2", "IsSteering", &(m_GearMotDrive2.bIsSteer), true);
00435 m_IniFile.GetKeyDouble("Drive2", "CurrentToTorque", &(m_GearMotDrive2.dCurrentToTorque), false);
00436 m_IniFile.GetKeyDouble("Drive2", "CurrMax", &(m_GearMotDrive2.dCurrMax), false);
00437 m_IniFile.GetKeyInt("Drive2", "HomingDigIn", &(m_GearMotDrive2.iHomingDigIn), false);
00438 }
00439
00440
00441 if(m_iNumDrives >= 3)
00442 {
00443 m_IniFile.GetKeyInt("Drive3", "EncIncrPerRevMot", &(m_GearMotDrive3.iEncIncrPerRevMot), true);
00444 m_IniFile.GetKeyDouble("Drive3", "VelMeasFrqHz", &(m_GearMotDrive3.dVelMeasFrqHz), true);
00445 m_IniFile.GetKeyDouble("Drive3", "BeltRatio", &(m_GearMotDrive3.dBeltRatio), true);
00446 m_IniFile.GetKeyDouble("Drive3", "GearRatio", &(m_GearMotDrive3.dGearRatio), true);
00447 m_IniFile.GetKeyInt("Drive3", "Sign", &(m_GearMotDrive3.iSign), true);
00448 m_IniFile.GetKeyDouble("Drive3", "VelMaxEncIncrS", &(m_GearMotDrive3.dVelMaxEncIncrS), true);
00449 m_IniFile.GetKeyDouble("Drive3", "AccIncrS", &(m_GearMotDrive3.dAccIncrS2), true);
00450 m_IniFile.GetKeyDouble("Drive3", "DecIncrS", &(m_GearMotDrive3.dDecIncrS2), true);
00451 m_IniFile.GetKeyInt("Drive3", "EncOffsetIncr",&(m_GearMotDrive3.iEncOffsetIncr),true);
00452 m_IniFile.GetKeyBool("Drive3", "IsSteering", &(m_GearMotDrive3.bIsSteer), true);
00453 m_IniFile.GetKeyDouble("Drive3", "CurrentToTorque", &(m_GearMotDrive3.dCurrentToTorque), false);
00454 m_IniFile.GetKeyDouble("Drive3", "CurrMax", &(m_GearMotDrive3.dCurrMax), false);
00455 m_IniFile.GetKeyInt("Drive3", "HomingDigIn", &(m_GearMotDrive3.iHomingDigIn), false);
00456 }
00457
00458
00459 if(m_iNumDrives == 4)
00460 {
00461 m_IniFile.GetKeyInt("Drive4", "EncIncrPerRevMot", &(m_GearMotDrive4.iEncIncrPerRevMot), true);
00462 m_IniFile.GetKeyDouble("Drive4", "VelMeasFrqHz", &(m_GearMotDrive4.dVelMeasFrqHz), true);
00463 m_IniFile.GetKeyDouble("Drive4", "BeltRatio", &(m_GearMotDrive4.dBeltRatio), true);
00464 m_IniFile.GetKeyDouble("Drive4", "GearRatio", &(m_GearMotDrive4.dGearRatio), true);
00465 m_IniFile.GetKeyInt("Drive4", "Sign", &(m_GearMotDrive4.iSign), true);
00466 m_IniFile.GetKeyDouble("Drive4", "VelMaxEncIncrS", &(m_GearMotDrive4.dVelMaxEncIncrS), true);
00467 m_IniFile.GetKeyDouble("Drive4", "AccIncrS", &(m_GearMotDrive4.dAccIncrS2), true);
00468 m_IniFile.GetKeyDouble("Drive4", "DecIncrS", &(m_GearMotDrive4.dDecIncrS2), true);
00469 m_IniFile.GetKeyInt("Drive4", "EncOffsetIncr",&(m_GearMotDrive4.iEncOffsetIncr),true);
00470 m_IniFile.GetKeyBool("Drive4", "IsSteering", &(m_GearMotDrive4.bIsSteer), true);
00471 m_IniFile.GetKeyDouble("Drive4", "CurrentToTorque", &(m_GearMotDrive4.dCurrentToTorque), false);
00472 m_IniFile.GetKeyDouble("Drive4", "CurrMax", &(m_GearMotDrive4.dCurrMax), false);
00473 m_IniFile.GetKeyInt("Drive4", "HomingDigIn", &(m_GearMotDrive4.iHomingDigIn), false);
00474 }
00475
00476
00477 if(m_iNumDrives >= 1)
00478 {
00479 m_IniFile.GetKeyInt("Steer1", "EncIncrPerRevMot", &(m_GearMotSteer1.iEncIncrPerRevMot), true);
00480 m_IniFile.GetKeyDouble("Steer1", "VelMeasFrqHz", &(m_GearMotSteer1.dVelMeasFrqHz), true);
00481 m_IniFile.GetKeyDouble("Steer1", "BeltRatio", &(m_GearMotSteer1.dBeltRatio), true);
00482 m_IniFile.GetKeyDouble("Steer1", "GearRatio", &(m_GearMotSteer1.dGearRatio), true);
00483 m_IniFile.GetKeyInt("Steer1", "Sign", &(m_GearMotSteer1.iSign), true);
00484 m_IniFile.GetKeyDouble("Steer1", "VelMaxEncIncrS", &(m_GearMotSteer1.dVelMaxEncIncrS), true);
00485 m_IniFile.GetKeyDouble("Steer1", "AccIncrS", &(m_GearMotSteer1.dAccIncrS2), true);
00486 m_IniFile.GetKeyDouble("Steer1", "DecIncrS", &(m_GearMotSteer1.dDecIncrS2), true);
00487 m_IniFile.GetKeyInt("Steer1", "EncOffsetIncr",&(m_GearMotSteer1.iEncOffsetIncr),true);
00488 m_IniFile.GetKeyBool("Steer1", "IsSteering", &(m_GearMotSteer1.bIsSteer), true);
00489 m_IniFile.GetKeyDouble("Steer1", "CurrentToTorque", &(m_GearMotSteer1.dCurrentToTorque), false);
00490 m_IniFile.GetKeyDouble("Steer1", "CurrMax", &(m_GearMotSteer1.dCurrMax), false);
00491 m_IniFile.GetKeyInt("Steer1", "HomingDigIn", &(m_GearMotSteer1.iHomingDigIn), false);
00492 }
00493
00494
00495 if(m_iNumDrives >= 2)
00496 {
00497 m_IniFile.GetKeyInt("Steer2", "EncIncrPerRevMot", &(m_GearMotSteer2.iEncIncrPerRevMot), true);
00498 m_IniFile.GetKeyDouble("Steer2", "VelMeasFrqHz", &(m_GearMotSteer2.dVelMeasFrqHz), true);
00499 m_IniFile.GetKeyDouble("Steer2", "BeltRatio", &(m_GearMotSteer2.dBeltRatio), true);
00500 m_IniFile.GetKeyDouble("Steer2", "GearRatio", &(m_GearMotSteer2.dGearRatio), true);
00501 m_IniFile.GetKeyInt("Steer2", "Sign", &(m_GearMotSteer2.iSign), true);
00502 m_IniFile.GetKeyDouble("Steer2", "VelMaxEncIncrS", &(m_GearMotSteer2.dVelMaxEncIncrS), true);
00503 m_IniFile.GetKeyDouble("Steer2", "AccIncrS", &(m_GearMotSteer2.dAccIncrS2), true);
00504 m_IniFile.GetKeyDouble("Steer2", "DecIncrS", &(m_GearMotSteer2.dDecIncrS2), true);
00505 m_IniFile.GetKeyInt("Steer2", "EncOffsetIncr",&(m_GearMotSteer2.iEncOffsetIncr),true);
00506 m_IniFile.GetKeyBool("Steer2", "IsSteering", &(m_GearMotSteer2.bIsSteer), true);
00507 m_IniFile.GetKeyDouble("Steer2", "CurrentToTorque", &(m_GearMotSteer2.dCurrentToTorque), false);
00508 m_IniFile.GetKeyDouble("Steer2", "CurrMax", &(m_GearMotSteer2.dCurrMax), false);
00509 m_IniFile.GetKeyInt("Steer2", "HomingDigIn", &(m_GearMotSteer2.iHomingDigIn), false);
00510 }
00511
00512
00513 if(m_iNumDrives >= 3)
00514 {
00515 m_IniFile.GetKeyInt("Steer3", "EncIncrPerRevMot", &(m_GearMotSteer3.iEncIncrPerRevMot), true);
00516 m_IniFile.GetKeyDouble("Steer3", "VelMeasFrqHz", &(m_GearMotSteer3.dVelMeasFrqHz), true);
00517 m_IniFile.GetKeyDouble("Steer3", "BeltRatio", &(m_GearMotSteer3.dBeltRatio), true);
00518 m_IniFile.GetKeyDouble("Steer3", "GearRatio", &(m_GearMotSteer3.dGearRatio), true);
00519 m_IniFile.GetKeyInt("Steer3", "Sign", &(m_GearMotSteer3.iSign), true);
00520 m_IniFile.GetKeyDouble("Steer3", "VelMaxEncIncrS", &(m_GearMotSteer3.dVelMaxEncIncrS), true);
00521 m_IniFile.GetKeyDouble("Steer3", "AccIncrS", &(m_GearMotSteer3.dAccIncrS2), true);
00522 m_IniFile.GetKeyDouble("Steer3", "DecIncrS", &(m_GearMotSteer3.dDecIncrS2), true);
00523 m_IniFile.GetKeyInt("Steer3", "EncOffsetIncr",&(m_GearMotSteer3.iEncOffsetIncr),true);
00524 m_IniFile.GetKeyBool("Steer3", "IsSteering", &(m_GearMotSteer3.bIsSteer), true);
00525 m_IniFile.GetKeyDouble("Steer3", "CurrentToTorque", &(m_GearMotSteer3.dCurrentToTorque), false);
00526 m_IniFile.GetKeyDouble("Steer3", "CurrMax", &(m_GearMotSteer3.dCurrMax), false);
00527 m_IniFile.GetKeyInt("Steer3", "HomingDigIn", &(m_GearMotSteer3.iHomingDigIn), false);
00528 }
00529
00530
00531 if(m_iNumDrives == 4)
00532 {
00533 m_IniFile.GetKeyInt("Steer4", "EncIncrPerRevMot", &(m_GearMotSteer4.iEncIncrPerRevMot), true);
00534 m_IniFile.GetKeyDouble("Steer4", "VelMeasFrqHz", &(m_GearMotSteer4.dVelMeasFrqHz), true);
00535 m_IniFile.GetKeyDouble("Steer4", "BeltRatio", &(m_GearMotSteer4.dBeltRatio), true);
00536 m_IniFile.GetKeyDouble("Steer4", "GearRatio", &(m_GearMotSteer4.dGearRatio), true);
00537 m_IniFile.GetKeyInt("Steer4", "Sign", &(m_GearMotSteer4.iSign), true);
00538 m_IniFile.GetKeyDouble("Steer4", "VelMaxEncIncrS", &(m_GearMotSteer4.dVelMaxEncIncrS), true);
00539 m_IniFile.GetKeyDouble("Steer4", "AccIncrS", &(m_GearMotSteer4.dAccIncrS2), true);
00540 m_IniFile.GetKeyDouble("Steer4", "DecIncrS", &(m_GearMotSteer4.dDecIncrS2), true);
00541 m_IniFile.GetKeyInt("Steer4", "EncOffsetIncr",&(m_GearMotSteer4.iEncOffsetIncr),true);
00542 m_IniFile.GetKeyBool("Steer4", "IsSteering", &(m_GearMotSteer4.bIsSteer), true);
00543 m_IniFile.GetKeyDouble("Steer4", "CurrentToTorque", &(m_GearMotSteer4.dCurrentToTorque), false);
00544 m_IniFile.GetKeyDouble("Steer4", "CurrMax", &(m_GearMotSteer4.dCurrMax), false);
00545 m_IniFile.GetKeyInt("Steer4", "HomingDigIn", &(m_GearMotSteer4.iHomingDigIn), false);
00546 }
00547
00548 if(m_iNumDrives >= 1)
00549 {
00550 DriveParamW1DriveMotor.setParam(
00551 0,
00552 m_GearMotDrive1.iEncIncrPerRevMot,
00553 m_GearMotDrive1.dVelMeasFrqHz,
00554 m_GearMotDrive1.dBeltRatio,
00555 m_GearMotDrive1.dGearRatio,
00556 m_GearMotDrive1.iSign,
00557 m_GearMotDrive1.dVelMaxEncIncrS,
00558 m_GearMotDrive1.dAccIncrS2,
00559 m_GearMotDrive1.dDecIncrS2,
00560 m_GearMotDrive1.iEncOffsetIncr,
00561 m_GearMotDrive1.bIsSteer,
00562 m_GearMotDrive1.dCurrentToTorque,
00563 m_GearMotDrive1.dCurrMax,
00564 m_GearMotDrive1.iHomingDigIn);
00565 }
00566
00567 if(m_iNumDrives >= 1)
00568 {
00569 DriveParamW1SteerMotor.setParam(
00570 1,
00571 m_GearMotSteer1.iEncIncrPerRevMot,
00572 m_GearMotSteer1.dVelMeasFrqHz,
00573 m_GearMotSteer1.dBeltRatio,
00574 m_GearMotSteer1.dGearRatio,
00575 m_GearMotSteer1.iSign,
00576 m_GearMotSteer1.dVelMaxEncIncrS,
00577 m_GearMotSteer1.dAccIncrS2,
00578 m_GearMotSteer1.dDecIncrS2,
00579 m_GearMotSteer1.iEncOffsetIncr,
00580 m_GearMotSteer1.bIsSteer,
00581 m_GearMotSteer1.dCurrentToTorque,
00582 m_GearMotSteer1.dCurrMax,
00583 m_GearMotSteer1.iHomingDigIn);
00584 }
00585
00586 if(m_iNumDrives >= 2)
00587 {
00588 DriveParamW2DriveMotor.setParam(
00589 2,
00590 m_GearMotDrive2.iEncIncrPerRevMot,
00591 m_GearMotDrive2.dVelMeasFrqHz,
00592 m_GearMotDrive2.dBeltRatio,
00593 m_GearMotDrive2.dGearRatio,
00594 m_GearMotDrive2.iSign,
00595 m_GearMotDrive2.dVelMaxEncIncrS,
00596 m_GearMotDrive2.dAccIncrS2,
00597 m_GearMotDrive2.dDecIncrS2,
00598 m_GearMotDrive2.iEncOffsetIncr,
00599 m_GearMotDrive2.bIsSteer,
00600 m_GearMotDrive2.dCurrentToTorque,
00601 m_GearMotDrive2.dCurrMax,
00602 m_GearMotDrive2.iHomingDigIn);
00603 }
00604
00605 if(m_iNumDrives >= 2)
00606 {
00607 DriveParamW2SteerMotor.setParam(
00608 3,
00609 m_GearMotSteer2.iEncIncrPerRevMot,
00610 m_GearMotSteer2.dVelMeasFrqHz,
00611 m_GearMotSteer2.dBeltRatio,
00612 m_GearMotSteer2.dGearRatio,
00613 m_GearMotSteer2.iSign,
00614 m_GearMotSteer2.dVelMaxEncIncrS,
00615 m_GearMotSteer2.dAccIncrS2,
00616 m_GearMotSteer2.dDecIncrS2,
00617 m_GearMotSteer2.iEncOffsetIncr,
00618 m_GearMotSteer2.bIsSteer,
00619 m_GearMotSteer2.dCurrentToTorque,
00620 m_GearMotSteer2.dCurrMax,
00621 m_GearMotSteer2.iHomingDigIn);
00622 }
00623
00624 if(m_iNumDrives >= 3)
00625 {
00626 DriveParamW3DriveMotor.setParam(
00627 4,
00628 m_GearMotDrive3.iEncIncrPerRevMot,
00629 m_GearMotDrive3.dVelMeasFrqHz,
00630 m_GearMotDrive3.dBeltRatio,
00631 m_GearMotDrive3.dGearRatio,
00632 m_GearMotDrive3.iSign,
00633 m_GearMotDrive3.dVelMaxEncIncrS,
00634 m_GearMotDrive3.dAccIncrS2,
00635 m_GearMotDrive3.dDecIncrS2,
00636 m_GearMotDrive3.iEncOffsetIncr,
00637 m_GearMotDrive3.bIsSteer,
00638 m_GearMotDrive3.dCurrentToTorque,
00639 m_GearMotDrive3.dCurrMax,
00640 m_GearMotDrive3.iHomingDigIn);
00641 }
00642
00643 if(m_iNumDrives >= 3)
00644 {
00645 DriveParamW3SteerMotor.setParam(
00646 5,
00647 m_GearMotSteer3.iEncIncrPerRevMot,
00648 m_GearMotSteer3.dVelMeasFrqHz,
00649 m_GearMotSteer3.dBeltRatio,
00650 m_GearMotSteer3.dGearRatio,
00651 m_GearMotSteer3.iSign,
00652 m_GearMotSteer3.dVelMaxEncIncrS,
00653 m_GearMotSteer3.dAccIncrS2,
00654 m_GearMotSteer3.dDecIncrS2,
00655 m_GearMotSteer3.iEncOffsetIncr,
00656 m_GearMotSteer3.bIsSteer,
00657 m_GearMotSteer3.dCurrentToTorque,
00658 m_GearMotSteer3.dCurrMax,
00659 m_GearMotSteer3.iHomingDigIn);
00660 }
00661
00662 if(m_iNumDrives == 4)
00663 {
00664 DriveParamW4DriveMotor.setParam(
00665 6,
00666 m_GearMotDrive4.iEncIncrPerRevMot,
00667 m_GearMotDrive4.dVelMeasFrqHz,
00668 m_GearMotDrive4.dBeltRatio,
00669 m_GearMotDrive4.dGearRatio,
00670 m_GearMotDrive4.iSign,
00671 m_GearMotDrive4.dVelMaxEncIncrS,
00672 m_GearMotDrive4.dAccIncrS2,
00673 m_GearMotDrive4.dDecIncrS2,
00674 m_GearMotDrive4.iEncOffsetIncr,
00675 m_GearMotDrive4.bIsSteer,
00676 m_GearMotDrive4.dCurrentToTorque,
00677 m_GearMotDrive4.dCurrMax,
00678 m_GearMotDrive4.iHomingDigIn);
00679 }
00680
00681 if(m_iNumDrives == 4)
00682 {
00683 DriveParamW4SteerMotor.setParam(
00684 7,
00685 m_GearMotSteer4.iEncIncrPerRevMot,
00686 m_GearMotSteer4.dVelMeasFrqHz,
00687 m_GearMotSteer4.dBeltRatio,
00688 m_GearMotSteer4.dGearRatio,
00689 m_GearMotSteer4.iSign,
00690 m_GearMotSteer4.dVelMaxEncIncrS,
00691 m_GearMotSteer4.dAccIncrS2,
00692 m_GearMotSteer4.dDecIncrS2,
00693 m_GearMotSteer4.iEncOffsetIncr,
00694 m_GearMotSteer4.bIsSteer,
00695 m_GearMotSteer4.dCurrentToTorque,
00696 m_GearMotSteer4.dCurrMax,
00697 m_GearMotSteer4.iHomingDigIn);
00698 }
00699
00700 m_IniFile.GetKeyDouble("US", "ScaleToMM", &dScaleToMM, true);
00701
00702
00703
00704 m_IniFile.SetFileName(sIniDirectory + "Platform.ini", "CanCtrlPltfCOb3.cpp");
00705
00706
00707
00708
00709 if(m_iNumDrives >= 1)
00710 {
00711 m_IniFile.GetKeyInt("Config", "Wheel1DriveMotor", &m_Param.iHasWheel1DriveMotor, true);
00712 if (m_Param.iHasWheel1DriveMotor == 0)
00713 {
00714
00715 std::cout << "node Wheel1DriveMotor available = 0" << std::endl;
00716 }
00717 else
00718 {
00719
00720 std::cout << "Wheel1DriveMotor available = type version 2" << std::endl;
00721 m_vpMotor[0] = new CanDriveHarmonica();
00722 ((CanDriveHarmonica*) m_vpMotor[0])->setCanOpenParam(
00723 m_CanOpenIDParam.TxPDO1_W1Drive, m_CanOpenIDParam.TxPDO2_W1Drive, m_CanOpenIDParam.RxPDO2_W1Drive,
00724 m_CanOpenIDParam.TxSDO_W1Drive, m_CanOpenIDParam.RxSDO_W1Drive);
00725 m_vpMotor[0]->setCanItf(m_pCanCtrl);
00726 m_vpMotor[0]->setDriveParam(DriveParamW1DriveMotor);
00727 }
00728 }
00729
00730
00731 if(m_iNumDrives >= 1)
00732 {
00733 m_IniFile.GetKeyInt("Config", "Wheel1SteerMotor", &m_Param.iHasWheel1SteerMotor, true);
00734 if (m_Param.iHasWheel1SteerMotor == 0)
00735 {
00736
00737 std::cout << "node Wheel1SteerMotor available = 0" << std::endl;
00738 }
00739 else
00740 {
00741
00742 std::cout << "Wheel1SteerMotor available = type version 2" << std::endl;
00743 m_vpMotor[1] = new CanDriveHarmonica();
00744 ((CanDriveHarmonica*) m_vpMotor[1])->setCanOpenParam(
00745 m_CanOpenIDParam.TxPDO1_W1Steer, m_CanOpenIDParam.TxPDO2_W1Steer, m_CanOpenIDParam.RxPDO2_W1Steer,
00746 m_CanOpenIDParam.TxSDO_W1Steer, m_CanOpenIDParam.RxSDO_W1Steer);
00747 m_vpMotor[1]->setCanItf(m_pCanCtrl);
00748 m_vpMotor[1]->setDriveParam(DriveParamW1SteerMotor);
00749
00750 }
00751 }
00752
00753
00754
00755 if(m_iNumDrives >= 2)
00756 {
00757 m_IniFile.GetKeyInt("Config", "Wheel2DriveMotor", &m_Param.iHasWheel2DriveMotor, true);
00758 if (m_Param.iHasWheel2DriveMotor == 0)
00759 {
00760
00761 std::cout << "node Wheel2DriveMotor available = 0" << std::endl;
00762 }
00763 else
00764 {
00765
00766 std::cout << "Wheel2DriveMotor available = type version 2" << std::endl;
00767 m_vpMotor[2] = new CanDriveHarmonica();
00768 ((CanDriveHarmonica*) m_vpMotor[2])->setCanOpenParam(
00769 m_CanOpenIDParam.TxPDO1_W2Drive, m_CanOpenIDParam.TxPDO2_W2Drive, m_CanOpenIDParam.RxPDO2_W2Drive,
00770 m_CanOpenIDParam.TxSDO_W2Drive, m_CanOpenIDParam.RxSDO_W2Drive);
00771 m_vpMotor[2]->setCanItf(m_pCanCtrl);
00772 m_vpMotor[2]->setDriveParam(DriveParamW2DriveMotor);
00773 }
00774 }
00775
00776
00777 if(m_iNumDrives >= 2)
00778 {
00779 m_IniFile.GetKeyInt("Config", "Wheel2SteerMotor", &m_Param.iHasWheel2SteerMotor, true);
00780 if (m_Param.iHasWheel2SteerMotor == 0)
00781 {
00782
00783 std::cout << "node Wheel2SteerMotor available = 0" << std::endl;
00784 }
00785 else
00786 {
00787
00788 std::cout << "Wheel2SteerMotor available = type version 2" << std::endl;
00789 m_vpMotor[3] = new CanDriveHarmonica();
00790 ((CanDriveHarmonica*) m_vpMotor[3])->setCanOpenParam(
00791 m_CanOpenIDParam.TxPDO1_W2Steer, m_CanOpenIDParam.TxPDO2_W2Steer, m_CanOpenIDParam.RxPDO2_W2Steer,
00792 m_CanOpenIDParam.TxSDO_W2Steer, m_CanOpenIDParam.RxSDO_W2Steer);
00793 m_vpMotor[3]->setCanItf(m_pCanCtrl);
00794 m_vpMotor[3]->setDriveParam(DriveParamW2SteerMotor);
00795
00796 }
00797 }
00798
00799
00800
00801 if(m_iNumDrives >= 3)
00802 {
00803 m_IniFile.GetKeyInt("Config", "Wheel3DriveMotor", &m_Param.iHasWheel3DriveMotor, true);
00804 if (m_Param.iHasWheel3DriveMotor == 0)
00805 {
00806
00807 std::cout << "node Wheel3DriveMotor available = 0" << std::endl;
00808 }
00809 else
00810 {
00811
00812 std::cout << "Wheel3DriveMotor available = type version 2" << std::endl;
00813 m_vpMotor[4] = new CanDriveHarmonica();
00814 ((CanDriveHarmonica*) m_vpMotor[4])->setCanOpenParam(
00815 m_CanOpenIDParam.TxPDO1_W3Drive, m_CanOpenIDParam.TxPDO2_W3Drive, m_CanOpenIDParam.RxPDO2_W3Drive,
00816 m_CanOpenIDParam.TxSDO_W3Drive, m_CanOpenIDParam.RxSDO_W3Drive);
00817 m_vpMotor[4]->setCanItf(m_pCanCtrl);
00818 m_vpMotor[4]->setDriveParam(DriveParamW3DriveMotor);
00819 }
00820 }
00821
00822
00823 if(m_iNumDrives >= 3)
00824 {
00825 m_IniFile.GetKeyInt("Config", "Wheel3SteerMotor", &m_Param.iHasWheel3SteerMotor, true);
00826 if (m_Param.iHasWheel3SteerMotor == 0)
00827 {
00828
00829 std::cout << "node Wheel3SteerMotor available = 0" << std::endl;
00830 }
00831 else
00832 {
00833
00834 std::cout << "Wheel3SteerMotor available = type version 2" << std::endl;
00835 m_vpMotor[5] = new CanDriveHarmonica();
00836 ((CanDriveHarmonica*) m_vpMotor[5])->setCanOpenParam(
00837 m_CanOpenIDParam.TxPDO1_W3Steer, m_CanOpenIDParam.TxPDO2_W3Steer, m_CanOpenIDParam.RxPDO2_W3Steer,
00838 m_CanOpenIDParam.TxSDO_W3Steer, m_CanOpenIDParam.RxSDO_W3Steer);
00839 m_vpMotor[5]->setCanItf(m_pCanCtrl);
00840 m_vpMotor[5]->setDriveParam(DriveParamW3SteerMotor);
00841
00842 }
00843 }
00844
00845
00846
00847 if(m_iNumDrives == 4)
00848 {
00849 m_IniFile.GetKeyInt("Config", "Wheel4DriveMotor", &m_Param.iHasWheel4DriveMotor, true);
00850 if (m_Param.iHasWheel4DriveMotor == 0)
00851 {
00852
00853 std::cout << "node Wheel4DriveMotor available = 0" << std::endl;
00854 }
00855 else
00856 {
00857
00858 std::cout << "Wheel4DriveMotor available = type version 2" << std::endl;
00859 m_vpMotor[6] = new CanDriveHarmonica();
00860 ((CanDriveHarmonica*) m_vpMotor[6])->setCanOpenParam(
00861 m_CanOpenIDParam.TxPDO1_W4Drive, m_CanOpenIDParam.TxPDO2_W4Drive, m_CanOpenIDParam.RxPDO2_W4Drive,
00862 m_CanOpenIDParam.TxSDO_W4Drive, m_CanOpenIDParam.RxSDO_W4Drive);
00863 m_vpMotor[6]->setCanItf(m_pCanCtrl);
00864 m_vpMotor[6]->setDriveParam(DriveParamW4DriveMotor);
00865 }
00866 }
00867
00868
00869 if(m_iNumDrives == 4)
00870 {
00871 m_IniFile.GetKeyInt("Config", "Wheel4SteerMotor", &m_Param.iHasWheel4SteerMotor, true);
00872 if (m_Param.iHasWheel4SteerMotor == 0)
00873 {
00874
00875 std::cout << "node Wheel4SteerMotor available = 0" << std::endl;
00876 }
00877 else
00878 {
00879
00880 std::cout << "Wheel4SteerMotor available = type version 2" << std::endl;
00881 m_vpMotor[7] = new CanDriveHarmonica();
00882 ((CanDriveHarmonica*) m_vpMotor[7])->setCanOpenParam(
00883 m_CanOpenIDParam.TxPDO1_W4Steer, m_CanOpenIDParam.TxPDO2_W4Steer, m_CanOpenIDParam.RxPDO2_W4Steer,
00884 m_CanOpenIDParam.TxSDO_W4Steer, m_CanOpenIDParam.RxSDO_W4Steer);
00885 m_vpMotor[7]->setCanItf(m_pCanCtrl);
00886 m_vpMotor[7]->setDriveParam(DriveParamW4SteerMotor);
00887
00888 }
00889 }
00890
00891 m_IniFile.GetKeyInt("Config", "GenericBufferLen", &iMaxMessages, true);
00892
00893
00894 }
00895
00896
00897 int CanCtrlPltfCOb3::evalCanBuffer()
00898 {
00899 bool bRet;
00900
00901
00902 m_Mutex.lock();
00903
00904
00905 while(m_pCanCtrl->receiveMsg(&m_CanMsgRec) == true)
00906 {
00907 bRet = false;
00908
00909 for (unsigned int i = 0; i < m_vpMotor.size(); i++)
00910 {
00911
00912 bRet |= m_vpMotor[i]->evalReceivedMsg(m_CanMsgRec);
00913 }
00914
00915 if (bRet == false)
00916 {
00917 std::cout << "evalCanBuffer(): Received CAN_Message with unknown identifier " << m_CanMsgRec.m_iID << std::endl;
00918 }
00919 };
00920
00921
00922 m_Mutex.unlock();
00923
00924 return 0;
00925 }
00926
00927
00928 bool CanCtrlPltfCOb3::initPltf()
00929 {
00930
00931 readConfiguration();
00932
00933
00934 std::vector<bool> vbRetDriveMotor;
00935 std::vector<bool> vbRetSteerMotor;
00936 std::vector<CanDriveItf*> vpDriveMotor;
00937 std::vector<CanDriveItf*> vpSteerMotor;
00938 bool bHomingOk;
00939
00940
00941
00942 vbRetDriveMotor.assign(m_iNumDrives,0);
00943 vbRetSteerMotor.assign(m_iNumDrives,0);
00944
00945
00946
00947 for(int i=0; i<=m_iNumMotors; i+=2)
00948 vpDriveMotor.push_back(m_vpMotor[i]);
00949
00950
00951
00952 for(int i=1; i<=m_iNumMotors; i+=2)
00953 vpSteerMotor.push_back(m_vpMotor[i]);
00954
00955
00956
00957
00958 std::vector<double> vdFactorVel;
00959
00960 vdFactorVel.assign(m_iNumDrives,0);
00961 double dhomeVeloRadS = -1.0;
00962
00963
00964
00965 std::cout << "StartCanOpen" << std::endl;
00966 sendNetStartCanOpen();
00967
00968
00969
00970
00971
00972 std::cout << "Initialization of Watchdogs" << std::endl;
00973 for(int i=0; i<m_iNumMotors; i++)
00974 {
00975 m_vpMotor[i]->startWatchdog(true);
00976 }
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986 usleep(10000);
00987
00988
00989 for(int i=0; i<m_iNumMotors; i++)
00990 {
00991 m_vpMotor[i]->startWatchdog(false);
00992 }
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002 usleep(100000);
01003
01004 std::cout << "Initialization of Watchdogs done" << std::endl;
01005
01006
01007
01008
01009
01010 if( m_vpMotor.size() == m_iNumMotors )
01011 {
01012
01013 for (int i = 0; i<m_iNumDrives; i++)
01014 {
01015
01016 vbRetDriveMotor[i] = vpDriveMotor[i]->init();
01017 vbRetSteerMotor[i] = vpSteerMotor[i]->init();
01018 usleep(10000);
01019 vbRetDriveMotor[i] = vbRetDriveMotor[i] && vpDriveMotor[i]->start();
01020 vbRetSteerMotor[i] = vbRetSteerMotor[i] && vpSteerMotor[i]->start();
01021 usleep(10000);
01022
01023 if (vbRetDriveMotor[i] && vbRetSteerMotor[i])
01024 std::cout << "Initialization of Wheel "<< (i+1) << " OK" << std::endl;
01025 else if (!vbRetDriveMotor[i] && vbRetSteerMotor[i])
01026 std::cout << "Initialization of Wheel "<< (i+1) << " ERROR while initializing DRIVE-Motor" << std::endl;
01027 else if (vbRetDriveMotor[i] && !vbRetSteerMotor[i])
01028 std::cout << "Initialization of Wheel "<< (i+1) << " ERROR while initializing STEER-Motor" << std::endl;
01029 else
01030 std::cout << "Initialization of Wheel "<< (i+1) << " ERROR while initializing STEER- and DRIVE-Motor" << std::endl;
01031
01032 vpDriveMotor[i]->setGearVelRadS(0);
01033 vpSteerMotor[i]->setGearVelRadS(0);
01034 }
01035
01036
01037
01038
01039 bHomingOk = true;
01040 for(int i=0; i<m_iNumDrives; i++)
01041 {
01042 if((vbRetDriveMotor[i] && vbRetSteerMotor[i]) == false)
01043 bHomingOk = false;
01044 }
01045 if(bHomingOk)
01046 {
01047
01048 if(m_iNumDrives >= 1)
01049 vdFactorVel[0] = - m_Param.dWheel1SteerDriveCoupling + double(m_Param.iDistSteerAxisToDriveWheelMM) / double(m_Param.iRadiusWheelMM);
01050 if(m_iNumDrives >= 2)
01051 vdFactorVel[1] = - m_Param.dWheel2SteerDriveCoupling + double(m_Param.iDistSteerAxisToDriveWheelMM) / double(m_Param.iRadiusWheelMM);
01052 if(m_iNumDrives >= 3)
01053 vdFactorVel[2] = - m_Param.dWheel3SteerDriveCoupling + double(m_Param.iDistSteerAxisToDriveWheelMM) / double(m_Param.iRadiusWheelMM);
01054 if(m_iNumDrives == 4)
01055 vdFactorVel[3] = - m_Param.dWheel4SteerDriveCoupling + double(m_Param.iDistSteerAxisToDriveWheelMM) / double(m_Param.iRadiusWheelMM);
01056
01057
01058 for (int i = 0; i<m_iNumDrives; i++)
01059 vpSteerMotor[i]->initHoming();
01060
01061
01062 for (int i = 0; i<m_iNumDrives; i++)
01063 {
01064 vpSteerMotor[i]->setGearVelRadS(dhomeVeloRadS);
01065 vpDriveMotor[i]->setGearVelRadS(dhomeVeloRadS * vdFactorVel[i]);
01066 }
01067
01068
01069 usleep(500000);
01070
01071
01072 bool bRet;
01073 do
01074 bRet = m_pCanCtrl->receiveMsg(&m_CanMsgRec);
01075 while(bRet == true);
01076
01077
01078 for (int i = 0; i<m_iNumDrives; i++)
01079 vpSteerMotor[i]->IntprtSetInt(8, 'H', 'M', 1, 1);
01080
01081
01082 bool bAllDone, bTimeOut=false;
01083 int iCnt = 0;
01084 do
01085 {
01086
01087 for (int i = 0; i<m_iNumDrives; i++)
01088 vpSteerMotor[i]->IntprtSetInt(4, 'H', 'M', 1, 0);
01089
01090
01091 evalCanBuffer();
01092
01093
01094 bAllDone = true;
01095 for (int i = 0; i<m_iNumDrives; i++)
01096 {
01097 if (vpSteerMotor[i]->getStatusLimitSwitch())
01098 {
01099 vpSteerMotor[i]->setGearVelRadS(0);
01100 vpDriveMotor[i]->setGearVelRadS(0);
01101 }
01102 bAllDone = bAllDone && vpSteerMotor[i]->getStatusLimitSwitch();
01103 }
01104
01105
01106 if (iCnt++ > 1000)
01107 bTimeOut = true;
01108
01109
01110 usleep(20000);
01111 }
01112 while(!bAllDone && !bTimeOut);
01113
01114
01115 if (bTimeOut)
01116 {
01117 for (int i=0;i<m_iNumDrives;i++)
01118 {
01119 vpSteerMotor[i]->setGearVelRadS(0);
01120 vpDriveMotor[i]->setGearVelRadS(0);
01121 }
01122 std::cout << "Error while Homing: Timeout while waiting for homing signal" << std::endl;
01123 }
01124
01125
01126
01127 evalCanBuffer();
01128
01129
01130
01131
01132 double m_d0 = 2.5;
01133 if (bTimeOut == false)
01134 {
01135 do
01136 {
01137 bAllDone = true;
01138 for (int i = 0; i<m_iNumDrives; i++)
01139 {
01140
01141 double dCurrentPosRad;
01142 vpSteerMotor[i]->getGearPosRad(&dCurrentPosRad);
01143
01144 double dDeltaPhi = 0.0 - dCurrentPosRad;
01145
01146 if (fabs(dDeltaPhi) < 0.03)
01147 {
01148 dDeltaPhi = 0.0;
01149 }
01150 else
01151 {
01152 bAllDone = false;
01153 }
01154 double dVelCmd = m_d0 * dDeltaPhi;
01155
01156 vpSteerMotor[i]->setGearVelRadS(dVelCmd);
01157 vpDriveMotor[i]->setGearVelRadS(dVelCmd*vdFactorVel[i]);
01158 }
01159 usleep(20000);
01160 evalCanBuffer();
01161 } while(!bAllDone);
01162
01163
01164
01165 std::cout << "Wheels homed" << std::endl;
01166 for (int i=0;i<m_iNumDrives;i++)
01167 {
01168 vpSteerMotor[i]->setGearVelRadS(0);
01169 vpDriveMotor[i]->setGearVelRadS(0);
01170 }
01171 }
01172 }
01173 }
01174
01175
01176
01177 for(int i=0; i<m_iNumMotors; i++)
01178 {
01179 m_vpMotor[i]->startWatchdog(true);
01180 }
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 bHomingOk = true;
01194 for(int i=0; i<m_iNumDrives; i++)
01195 {
01196 if((vbRetDriveMotor[i] && vbRetSteerMotor[i]) == false)
01197 {
01198 bHomingOk = false;
01199 }
01200 }
01201 return (bHomingOk);
01202 }
01203
01204
01205 bool CanCtrlPltfCOb3::resetPltf()
01206 {
01207 bool bRetMotor = true;
01208 bool bRet = true;
01209
01210 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01211 {
01212 bRetMotor = m_vpMotor[i]->start();
01213 if (bRetMotor == true)
01214 {
01215 m_vpMotor[i]->setGearVelRadS(0);
01216 }
01217 else
01218 {
01219 std::cout << "Resetting of Motor " << i << " failed" << std::endl;
01220 }
01221
01222 bRet &= bRetMotor;
01223 }
01224 return(bRet);
01225 }
01226
01227
01228 bool CanCtrlPltfCOb3::shutdownPltf()
01229 {
01230
01231 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01232 {
01233 m_vpMotor[i]->shutdown();
01234 }
01235
01236 return true;
01237 }
01238
01239
01240 bool CanCtrlPltfCOb3::isPltfError()
01241 {
01242
01243 bool bErrMotor = false;
01244 std::vector<bool> vbErrMotor;
01245 vbErrMotor.resize(m_vpMotor.size());
01246
01247
01248 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01249 {
01250 vbErrMotor[i] = m_vpMotor[i]->isError();
01251
01252 if( (m_bWatchdogErr == false) && (vbErrMotor[i] == true) )
01253 {
01254 std::cout << "Motor " << i << " error" << std::endl;
01255 }
01256
01257 bErrMotor |= vbErrMotor[i];
01258 }
01259
01260
01261 if(bErrMotor == false)
01262 m_bWatchdogErr = false;
01263 else
01264 m_bWatchdogErr = true;
01265
01266 if (m_bWatchdogErr) return true;
01267
01268
01269
01270 double dWatchTime = 0;
01271
01272 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01273 {
01274 dWatchTime = m_vpMotor[i]->getTimeToLastMsg();
01275
01276 if(dWatchTime < m_Param.dCanTimeout)
01277 {
01278 m_bWatchdogErr = false;
01279 }
01280 if( (dWatchTime > m_Param.dCanTimeout) && (m_bWatchdogErr == false) )
01281 {
01282 std::cout << "timeout CAN motor " << i << std::endl;
01283 m_bWatchdogErr = true;
01284 return true;
01285 }
01286 }
01287
01288 return false;
01289 }
01290
01291
01292 bool CanCtrlPltfCOb3::startWatchdog(bool bStarted)
01293 {
01294
01295 bool bRet = true;
01296
01297 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01298 {
01299 bRet = m_vpMotor[i]->startWatchdog(bStarted);
01300 }
01301
01302 return (bRet);
01303 }
01304
01305
01306 void CanCtrlPltfCOb3::sendNetStartCanOpen()
01307 {
01308 CanMsg msg;
01309
01310 msg.m_iID = 0;
01311 msg.m_iLen = 2;
01312 msg.set(1,0,0,0,0,0,0,0);
01313 m_pCanCtrl->transmitMsg(msg, false);
01314
01315 usleep(100000);
01316 }
01317
01318
01319
01320
01321
01322
01323
01324
01325 int CanCtrlPltfCOb3::setVelGearRadS(int iCanIdent, double dVelGearRadS)
01326 {
01327 m_Mutex.lock();
01328
01329
01330 if (m_bWatchdogErr == true)
01331 {
01332
01333 dVelGearRadS = 0;
01334
01335 }
01336
01337 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01338 {
01339
01340 if(iCanIdent == m_viMotorID[i])
01341 {
01342 m_vpMotor[i]->setGearVelRadS(dVelGearRadS);
01343 }
01344 }
01345
01346 m_Mutex.unlock();
01347
01348 return 0;
01349 }
01350
01351
01352 int CanCtrlPltfCOb3::requestMotPosVel(int iCanIdent)
01353 {
01354 m_Mutex.lock();
01355
01356 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01357 {
01358
01359 if(iCanIdent == m_viMotorID[i])
01360 {
01361 m_vpMotor[i]->requestPosVel();
01362 }
01363 }
01364
01365 m_Mutex.unlock();
01366
01367 return 0;
01368 }
01369
01370
01371 void CanCtrlPltfCOb3::requestDriveStatus()
01372 {
01373 m_Mutex.lock();
01374
01375 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01376 {
01377 m_vpMotor[i]->requestStatus();
01378 }
01379
01380 m_Mutex.unlock();
01381 }
01382
01383
01384 int CanCtrlPltfCOb3::getGearPosVelRadS(int iCanIdent, double* pdAngleGearRad, double* pdVelGearRadS)
01385 {
01386
01387
01388 *pdAngleGearRad = 0;
01389 *pdVelGearRadS = 0;
01390
01391 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01392 {
01393
01394 if(iCanIdent == m_viMotorID[i])
01395 {
01396 m_vpMotor[i]->getGearPosVelRadS(pdAngleGearRad, pdVelGearRadS);
01397 }
01398 }
01399
01400 return 0;
01401 }
01402
01403
01404 int CanCtrlPltfCOb3::getGearDeltaPosVelRadS(int iCanIdent, double* pdAngleGearRad,
01405 double* pdVelGearRadS)
01406 {
01407
01408
01409 *pdAngleGearRad = 0;
01410 *pdVelGearRadS = 0;
01411
01412 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01413 {
01414
01415 if(iCanIdent == m_viMotorID[i])
01416 {
01417 m_vpMotor[i]->getGearDeltaPosVelRadS(pdAngleGearRad, pdVelGearRadS);
01418 }
01419 }
01420
01421 return 0;
01422 }
01423
01424
01425 void CanCtrlPltfCOb3::getStatus(int iCanIdent, int* piStatus, int* piTempCel)
01426 {
01427
01428 *piStatus = 0;
01429 *piTempCel = 0;
01430
01431 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01432 {
01433
01434 if(iCanIdent == m_viMotorID[i])
01435 {
01436 m_vpMotor[i]->getStatus(piStatus, piTempCel);
01437 }
01438 }
01439
01440 }
01441
01442 void CanCtrlPltfCOb3::requestMotorTorque()
01443 {
01444 m_Mutex.lock();
01445
01446 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01447 {
01448 m_vpMotor[i]->requestMotorTorque();
01449 }
01450
01451 m_Mutex.unlock();
01452 }
01453
01454
01455 void CanCtrlPltfCOb3::getMotorTorque(int iCanIdent, double* pdTorqueNm)
01456 {
01457
01458 *pdTorqueNm = 0;
01459
01460 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01461 {
01462
01463 if(iCanIdent == m_viMotorID[i])
01464 {
01465 m_vpMotor[i]->getMotorTorque(pdTorqueNm);
01466 }
01467 }
01468
01469 }
01470
01471 void CanCtrlPltfCOb3::setMotorTorque(int iCanIdent, double dTorqueNm)
01472 {
01473 m_Mutex.lock();
01474
01475 for(unsigned int i = 0; i < m_vpMotor.size(); i++)
01476 {
01477
01478 if(iCanIdent == m_viMotorID[i])
01479 {
01480 m_vpMotor[i]->setMotorTorque(dTorqueNm);
01481 }
01482 }
01483
01484 m_Mutex.unlock();
01485 }
01486
01487
01488
01489
01490
01491
01492 int CanCtrlPltfCOb3::ElmoRecordings(int iFlag, int iParam, std::string sString) {
01493 int tempRet = 0;
01494 int bRet = 0;
01495
01496 switch(iFlag) {
01497 case 0:
01498 for(unsigned int i = 0; i < m_vpMotor.size(); i++) {
01499 m_vpMotor[i]->setRecorder(0, iParam);
01500 }
01501 return 0;
01502
01503 case 1:
01504 for(unsigned int i = 0; i < m_vpMotor.size(); i++) {
01505 if(tempRet = m_vpMotor[i]->setRecorder(1, iParam, sString) > bRet) bRet = tempRet;
01506 }
01507 return bRet;
01508
01509 case 99:
01510 for(unsigned int i = 0; i < m_vpMotor.size(); i++) {
01511 m_vpMotor[i]->setRecorder(99, 0);
01512 }
01513 return 0;
01514
01515 case 100:
01516 for(unsigned int i = 0; i < m_vpMotor.size(); i++) {
01517 bRet += m_vpMotor[i]->setRecorder(2, 0);
01518 }
01519 return bRet;
01520
01521 default:
01522 return -1;
01523 }
01524 }