Go to the documentation of this file.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 #include <youbot_driver/youbot/DataTrace.hpp>
00052 namespace youbot
00053 {
00054
00055 DataTrace::DataTrace(YouBotJoint& youBotJoint, const std::string Name, const bool overwriteFiles) :
00056 joint(youBotJoint)
00057 {
00058
00059
00060 roundsPerMinuteSetpoint.rpm = 0;
00061 PWMSetpoint.pwm = 0;
00062 encoderSetpoint.encoderTicks = 0;
00063
00064 InverseMovementDirection invertDirectionParameter;
00065 joint.getConfigurationParameter(invertDirectionParameter);
00066 bool inverted = false;
00067 invertDirectionParameter.getParameter(inverted);
00068 if (inverted)
00069 {
00070 invertDirection = -1;
00071 }
00072 else
00073 {
00074 invertDirection = 1;
00075 }
00076
00077 this->name = Name;
00078 if (Name != "")
00079 {
00080 this->path = Name;
00081 this->path.append("/");
00082 }
00083 char input = 0;
00084
00085 if (boost::filesystem::exists((path + "jointDataTrace").c_str()))
00086 {
00087 while (input != 'y' && input != 'n' && overwriteFiles == false)
00088 {
00089 std::cout << "Do you want to overwrite the existing files? [n/y]" << std::endl;
00090
00091 input = getchar();
00092
00093 if (input == 'n')
00094 {
00095 throw std::runtime_error("Will not overwrite files!");
00096 }
00097 }
00098
00099 }
00100 else
00101 {
00102 boost::filesystem::path rootPath(this->path);
00103
00104 if (!boost::filesystem::create_directories(rootPath))
00105 throw std::runtime_error("could not create folder!");
00106
00107 }
00108
00109
00110 }
00111
00112 DataTrace::~DataTrace()
00113 {
00114
00115
00116 }
00117
00118 void DataTrace::startTrace()
00119 {
00120
00121
00122 timeDurationMicroSec = 0;
00123
00124 file.open((path + "jointDataTrace").c_str(), std::fstream::out | std::fstream::trunc);
00125
00126 ptime today;
00127 today = second_clock::local_time();
00128
00129 file << "# Name: " << this->name << std::endl;
00130
00131 file << "# Date: " << boost::posix_time::to_simple_string(today) << std::endl;
00132
00133 JointName jointName;
00134 FirmwareVersion firmwareParameter;
00135 std::string parameterString;
00136 joint.getConfigurationParameter(firmwareParameter);
00137 joint.getConfigurationParameter(jointName);
00138 jointName.toString(parameterString);
00139 file << "# " << parameterString << std::endl;
00140 firmwareParameter.toString(parameterString);
00141 file << "# " << parameterString << std::endl;
00142
00143 file << "# time [milliseconds]" << " " << "angle setpoint [rad]" << " " << "velocity setpoint [rad/s]" << " "
00144 << "RPM setpoint" << " " << "current setpoint [A]" << " " << "torque setpoint [Nm]" << " "
00145 << "ramp generator setpoint [rad/s]" << " " << "encoder setpoint"
00146
00147 << " " << "sensed angle [rad]" << " " << "sensed encoder ticks" << " " << "sensed velocity [rad/s]" << " "
00148 << "sensed RPM" << " " << "sensed current [A]" << " " << "sensed torque [Nm]" << " " << "actual PWM"
00149
00150 << " " << "OVER_CURRENT" << " " << "UNDER_VOLTAGE" << " " << "OVER_VOLTAGE" << " " << "OVER_TEMPERATURE" << " "
00151 << "MOTOR_HALTED" << " " << "HALL_SENSOR_ERROR" << " " << "PWM_MODE_ACTIVE" << " " << "VELOCITY_MODE" << " "
00152 << "POSITION_MODE" << " " << "TORQUE_MODE" << " " << "POSITION_REACHED" << " " << "INITIALIZED" << " "
00153 << "TIMEOUT" << " " << "I2T_EXCEEDED" << " " << std::endl;
00154
00155 parametersBeginTraceFile.open((path + "ParametersAtBegin").c_str(), std::fstream::out | std::fstream::trunc);
00156
00157 parameterVector.push_back(new ActualMotorVoltage);
00158
00159 parameterVector.push_back(new ActualMotorDriverTemperature);
00160 parameterVector.push_back(new I2tSum);
00161 parameterVector.push_back(new PositionError);
00162 parameterVector.push_back(new PositionErrorSum);
00163 parameterVector.push_back(new RampGeneratorSpeed);
00164 parameterVector.push_back(new VelocityError);
00165 parameterVector.push_back(new VelocityErrorSum);
00166
00167 parameterVector.push_back(new DParameterFirstParametersPositionControl);
00168 parameterVector.push_back(new DParameterFirstParametersSpeedControl);
00169 parameterVector.push_back(new DParameterCurrentControl);
00170 parameterVector.push_back(new DParameterSecondParametersPositionControl);
00171 parameterVector.push_back(new DParameterSecondParametersSpeedControl);
00172
00173 parameterVector.push_back(new IClippingParameterFirstParametersPositionControl);
00174 parameterVector.push_back(new IClippingParameterFirstParametersSpeedControl);
00175 parameterVector.push_back(new IClippingParameterCurrentControl);
00176 parameterVector.push_back(new IClippingParameterSecondParametersPositionControl);
00177 parameterVector.push_back(new IClippingParameterSecondParametersSpeedControl);
00178
00179
00180 parameterVector.push_back(new IParameterFirstParametersPositionControl);
00181 parameterVector.push_back(new IParameterFirstParametersSpeedControl);
00182 parameterVector.push_back(new IParameterCurrentControl);
00183 parameterVector.push_back(new IParameterSecondParametersPositionControl);
00184 parameterVector.push_back(new IParameterSecondParametersSpeedControl);
00185
00186 parameterVector.push_back(new MaximumPositioningVelocity);
00187 parameterVector.push_back(new MotorAcceleration);
00188 parameterVector.push_back(new PositionControlSwitchingThreshold);
00189 parameterVector.push_back(new PParameterFirstParametersPositionControl);
00190 parameterVector.push_back(new PParameterFirstParametersSpeedControl);
00191 parameterVector.push_back(new PParameterCurrentControl);
00192 parameterVector.push_back(new PParameterSecondParametersPositionControl);
00193 parameterVector.push_back(new PParameterSecondParametersSpeedControl);
00194 parameterVector.push_back(new RampGeneratorSpeedAndPositionControl);
00195 parameterVector.push_back(new SpeedControlSwitchingThreshold);
00196
00197 parameterVector.push_back(new ActivateOvervoltageProtection);
00198 parameterVector.push_back(new ActualCommutationOffset);
00199
00200 parameterVector.push_back(new BEMFConstant);
00201
00202
00203 parameterVector.push_back(new CommutationMode);
00204 parameterVector.push_back(new CommutationMotorCurrent);
00205 parameterVector.push_back(new CurrentControlLoopDelay);
00206 parameterVector.push_back(new EncoderResolution);
00207 parameterVector.push_back(new EncoderStopSwitch);
00208 parameterVector.push_back(new HallSensorPolarityReversal);
00209 parameterVector.push_back(new I2tExceedCounter);
00210 parameterVector.push_back(new I2tLimit);
00211 parameterVector.push_back(new InitializationMode);
00212 parameterVector.push_back(new InitSineDelay);
00213 parameterVector.push_back(new MassInertiaConstant);
00214 parameterVector.push_back(new MaximumMotorCurrent);
00215 parameterVector.push_back(new MaximumVelocityToSetPosition);
00216 parameterVector.push_back(new MotorCoilResistance);
00217 parameterVector.push_back(new MotorControllerTimeout);
00218 parameterVector.push_back(new MotorPoles);
00219 parameterVector.push_back(new OperationalTime);
00220 parameterVector.push_back(new PIDControlTime);
00221 parameterVector.push_back(new PositionTargetReachedDistance);
00222 parameterVector.push_back(new ReversingEncoderDirection);
00223 parameterVector.push_back(new SetEncoderCounterZeroAtNextNChannel);
00224 parameterVector.push_back(new SetEncoderCounterZeroAtNextSwitch);
00225 parameterVector.push_back(new SetEncoderCounterZeroOnlyOnce);
00226 parameterVector.push_back(new SineInitializationVelocity);
00227 parameterVector.push_back(new StopSwitchPolarity);
00228 parameterVector.push_back(new ThermalWindingTimeConstant);
00229 parameterVector.push_back(new VelocityThresholdForHallFX);
00230 parameterVector.push_back(new MotorHaltedVelocity);
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 parametersBeginTraceFile << "Name: " << this->name << std::endl;
00247 parametersBeginTraceFile << "Date: " << boost::posix_time::to_simple_string(today) << std::endl;
00248
00249 jointName.toString(parameterString);
00250
00251 parametersBeginTraceFile << parameterString << std::endl;
00252 firmwareParameter.toString(parameterString);
00253 parametersBeginTraceFile << parameterString << std::endl;
00254
00255 TorqueConstant torqueconst;
00256 joint.getConfigurationParameter(torqueconst);
00257 torqueconst.toString(parameterString);
00258
00259 parametersBeginTraceFile << parameterString << std::endl;
00260
00261 JointLimits jointLimits;
00262 joint.getConfigurationParameter(jointLimits);
00263 jointLimits.toString(parameterString);
00264
00265 parametersBeginTraceFile << parameterString << std::endl;
00266
00267 EncoderTicksPerRound encoderTicksPerRound;
00268 joint.getConfigurationParameter(encoderTicksPerRound);
00269 encoderTicksPerRound.toString(parameterString);
00270
00271 parametersBeginTraceFile << parameterString << std::endl;
00272
00273 GearRatio gearRatio;
00274 joint.getConfigurationParameter(gearRatio);
00275 gearRatio.toString(parameterString);
00276
00277 parametersBeginTraceFile << parameterString << std::endl;
00278
00279 InverseMovementDirection inverseMovementDirection;
00280 joint.getConfigurationParameter(inverseMovementDirection);
00281 inverseMovementDirection.toString(parameterString);
00282
00283 parametersBeginTraceFile << parameterString << std::endl;
00284
00285 for (unsigned int i = 0; i < parameterVector.size(); i++)
00286 {
00287 joint.getConfigurationParameter(*(parameterVector[i]));
00288 parameterVector[i]->toString(parameterString);
00289
00290 parametersBeginTraceFile << parameterString << std::endl;
00291 }
00292 parametersBeginTraceFile.close();
00293
00294 traceStartTime = microsec_clock::local_time();
00295
00296 }
00297
00298 void DataTrace::stopTrace()
00299 {
00300
00301 file.close();
00302
00303 parametersEndTraceFile.open((path + "ParametersAfterTrace").c_str(), std::fstream::out | std::fstream::trunc);
00304 std::string parameterString;
00305
00306 parametersEndTraceFile << "Name: " << this->name << std::endl;
00307 ptime today;
00308 today = second_clock::local_time();
00309 parametersEndTraceFile << "Date: " << boost::posix_time::to_simple_string(today) << std::endl;
00310
00311 JointName jointName;
00312 joint.getConfigurationParameter(jointName);
00313 jointName.toString(parameterString);
00314
00315 parametersEndTraceFile << parameterString << std::endl;
00316
00317 FirmwareVersion firmwareParameter;
00318 joint.getConfigurationParameter(firmwareParameter);
00319 firmwareParameter.toString(parameterString);
00320 parametersEndTraceFile << parameterString << std::endl;
00321
00322 TorqueConstant torqueconst;
00323 joint.getConfigurationParameter(torqueconst);
00324 torqueconst.toString(parameterString);
00325
00326 parametersEndTraceFile << parameterString << std::endl;
00327
00328 JointLimits jointLimits;
00329 joint.getConfigurationParameter(jointLimits);
00330 jointLimits.toString(parameterString);
00331
00332 parametersEndTraceFile << parameterString << std::endl;
00333
00334 EncoderTicksPerRound encoderTicksPerRound;
00335 joint.getConfigurationParameter(encoderTicksPerRound);
00336 encoderTicksPerRound.toString(parameterString);
00337
00338 parametersEndTraceFile << parameterString << std::endl;
00339
00340 GearRatio gearRatio;
00341 joint.getConfigurationParameter(gearRatio);
00342 gearRatio.toString(parameterString);
00343
00344 parametersEndTraceFile << parameterString << std::endl;
00345
00346 InverseMovementDirection inverseMovementDirection;
00347 joint.getConfigurationParameter(inverseMovementDirection);
00348 inverseMovementDirection.toString(parameterString);
00349
00350 parametersEndTraceFile << parameterString << std::endl;
00351
00352 for (unsigned int i = 0; i < parameterVector.size(); i++)
00353 {
00354 joint.getConfigurationParameter(*(parameterVector[i]));
00355 parameterVector[i]->toString(parameterString);
00356 parametersEndTraceFile << parameterString << std::endl;
00357 delete parameterVector[i];
00358 }
00359
00360 parametersEndTraceFile.close();
00361
00362 }
00363
00364 void DataTrace::plotTrace()
00365 {
00366
00367
00368 std::string executeString = "cd ";
00369 executeString.append(path);
00370 executeString.append("; gnuplot ../../gnuplotconfig > /dev/null 2>&1");
00371 if (!std::system(executeString.c_str()))
00372 {
00373
00374 }
00375
00376 }
00377
00378 void DataTrace::updateTrace(const JointAngleSetpoint& setpoint)
00379 {
00380
00381 angleSetpoint = setpoint;
00382 controllerMode = POSITION_CONTROL_RAD;
00383 this->update();
00384
00385 }
00386
00387 void DataTrace::updateTrace(const JointVelocitySetpoint& setpoint)
00388 {
00389
00390 velocitySetpoint = setpoint;
00391 controllerMode = VELOCITY_CONTROL_RAD_SEC;
00392 this->update();
00393
00394 }
00395
00396 void DataTrace::updateTrace(const JointRoundsPerMinuteSetpoint& setpoint)
00397 {
00398
00399 roundsPerMinuteSetpoint = setpoint;
00400 controllerMode = VELOCITY_CONTROL_RPM;
00401 this->update();
00402
00403 }
00404
00405 void DataTrace::updateTrace(const JointCurrentSetpoint& setpoint)
00406 {
00407
00408 currentSetpoint = setpoint;
00409 controllerMode = CURRENT_CONTROL_MODE;
00410 this->update();
00411
00412 }
00413
00414 void DataTrace::updateTrace(const JointTorqueSetpoint& setpoint)
00415 {
00416
00417 torqueSetpoint = setpoint;
00418 controllerMode = TORQUE_CONTROL_MODE;
00419 this->update();
00420
00421 }
00422
00423 void DataTrace::updateTrace(const JointEncoderSetpoint& setpoint)
00424 {
00425
00426 encoderSetpoint = setpoint;
00427 controllerMode = POSITION_CONTROL_ENC;
00428 this->update();
00429
00430 }
00431
00432 void DataTrace::updateTrace()
00433 {
00434
00435 YouBotSlaveMsg message;
00436 joint.getData(message);
00437 switch (message.stctOutput.controllerMode)
00438 {
00439 case MOTOR_STOP:
00440 controllerMode = NOT_DEFINED;
00441 break;
00442 case POSITION_CONTROL:
00443 encoderSetpoint.encoderTicks = message.stctOutput.value * invertDirection;
00444 controllerMode = POSITION_CONTROL_ENC;
00445 break;
00446 case VELOCITY_CONTROL:
00447 roundsPerMinuteSetpoint.rpm = message.stctOutput.value * invertDirection;
00448 controllerMode = VELOCITY_CONTROL_RPM;
00449 break;
00450 case NO_MORE_ACTION:
00451 controllerMode = NOT_DEFINED;
00452 break;
00453 case SET_POSITION_TO_REFERENCE:
00454 controllerMode = NOT_DEFINED;
00455 break;
00456 case CURRENT_MODE:
00457 currentSetpoint.current = (double)message.stctOutput.value / 1000.0 * invertDirection * ampere;
00458 controllerMode = CURRENT_CONTROL_MODE;
00459 break;
00460 default:
00461 controllerMode = NOT_DEFINED;
00462 break;
00463 };
00464
00465 this->update();
00466
00467 }
00468
00469 unsigned long DataTrace::getTimeDurationMilliSec()
00470 {
00471
00472 return timeDurationMicroSec;
00473
00474 }
00475
00476 void DataTrace::update()
00477 {
00478
00479 timeDuration = microsec_clock::local_time() - traceStartTime;
00480 timeDurationMicroSec = timeDuration.total_milliseconds();
00481 unsigned int statusFlags;
00482 joint.getStatus(statusFlags);
00483 joint.getData(sensedAngle);
00484 joint.getData(sensedEncoderTicks);
00485 joint.getData(sensedVelocity);
00486 joint.getData(sensedRoundsPerMinute);
00487 joint.getData(sensedCurrent);
00488 joint.getData(sensedTorque);
00489 joint.getData(targetAngle);
00490 joint.getData(targetVelocity);
00491 joint.getData(targetCurrent);
00492 joint.getData(rampGenSetpoint);
00493
00494 std::stringstream angleSet, angleEncSet, velSet, velRPMSet, currentSet, pwmSet, torqueSet;
00495
00496 switch (controllerMode)
00497 {
00498 case POSITION_CONTROL_RAD:
00499 angleSet << angleSetpoint.angle.value();
00500 angleEncSet << "NaN";
00501 velSet << targetVelocity.angularVelocity.value();
00502 velRPMSet << "NaN";
00503 currentSet << targetCurrent.current.value();
00504 pwmSet << "NaN";
00505 torqueSet << "NaN";
00506 break;
00507 case POSITION_CONTROL_ENC:
00508 angleSet << "NaN";
00509 angleEncSet << encoderSetpoint.encoderTicks;
00510 velSet << targetVelocity.angularVelocity.value();
00511 velRPMSet << "NaN";
00512 currentSet << targetCurrent.current.value();
00513 pwmSet << "NaN";
00514 torqueSet << "NaN";
00515 break;
00516 case VELOCITY_CONTROL_RAD_SEC:
00517 angleSet << "NaN";
00518 angleEncSet << "NaN";
00519 velSet << velocitySetpoint.angularVelocity.value();
00520 velRPMSet << "NaN";
00521 currentSet << targetCurrent.current.value();
00522 pwmSet << "NaN";
00523 torqueSet << "NaN";
00524 break;
00525 case VELOCITY_CONTROL_RPM:
00526 angleSet << "NaN";
00527 angleEncSet << "NaN";
00528 velSet << "NaN";
00529 velRPMSet << roundsPerMinuteSetpoint.rpm;
00530 currentSet << targetCurrent.current.value();
00531 pwmSet << "NaN";
00532 torqueSet << "NaN";
00533 break;
00534 case CURRENT_CONTROL_MODE:
00535 angleSet << "NaN";
00536 angleEncSet << "NaN";
00537 velSet << "NaN";
00538 velRPMSet << "NaN";
00539 currentSet << currentSetpoint.current.value();
00540 pwmSet << "NaN";
00541 torqueSet << "NaN";
00542 break;
00543 case TORQUE_CONTROL_MODE:
00544 angleSet << "NaN";
00545 angleEncSet << "NaN";
00546 velSet << "NaN";
00547 velRPMSet << "NaN";
00548 currentSet << "NaN";
00549 pwmSet << "NaN";
00550 torqueSet << torqueSetpoint.torque.value();
00551 break;
00552 case NOT_DEFINED:
00553 angleSet << "NaN";
00554 angleEncSet << "NaN";
00555 velSet << "NaN";
00556 velRPMSet << "NaN";
00557 currentSet << "NaN";
00558 pwmSet << "NaN";
00559 torqueSet << "NaN";
00560 break;
00561 };
00562
00563 file << timeDurationMicroSec
00564 << " " << angleSet.str()
00565 << " " << velSet.str()
00566 << " " << velRPMSet.str()
00567 << " " << currentSet.str()
00568 << " " << torqueSet.str()
00569 << " " << rampGenSetpoint.angularVelocity.value()
00570 << " " << angleEncSet.str()
00571
00572 << " " << sensedAngle.angle.value()
00573 << " " << sensedEncoderTicks.encoderTicks
00574 << " " << sensedVelocity.angularVelocity.value()
00575 << " " << sensedRoundsPerMinute.rpm
00576 << " " << sensedCurrent.current.value()
00577 << " " << sensedTorque.torque.value()
00578 << " " << "0"
00579
00580 << " " << bool(statusFlags & OVER_CURRENT) << " "
00581 << bool(statusFlags & UNDER_VOLTAGE) << " "
00582 << bool(statusFlags & OVER_VOLTAGE) << " "
00583 << bool(statusFlags & OVER_TEMPERATURE) << " "
00584 << bool(statusFlags & MOTOR_HALTED) << " "
00585 << bool(statusFlags & HALL_SENSOR_ERROR) << " "
00586 << "0" << " "
00587 << bool(statusFlags & VELOCITY_MODE) << " "
00588 << bool(statusFlags & POSITION_MODE) << " "
00589 << bool(statusFlags & TORQUE_MODE) << " "
00590 << bool(statusFlags & POSITION_REACHED) << " "
00591 << bool(statusFlags & INITIALIZED) << " "
00592 << bool(statusFlags & TIMEOUT) << " "
00593 << bool(statusFlags & I2T_EXCEEDED)
00594 << std::endl;
00595
00596
00597 }
00598
00599 }