GripperDataTrace.cpp
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/GripperDataTrace.hpp"
00052 namespace youbot {
00053
00054 GripperDataTrace::GripperDataTrace(YouBotGripperBar& youBotGripperBar, const std::string Name, const bool overwriteFiles):gripperBar(youBotGripperBar) {
00055
00056
00057 roundsPerMinuteSetpoint.rpm = 0;
00058 PWMSetpoint.pwm = 0;
00059 encoderSetpoint.encoderTicks = 0;
00060 this->name = Name;
00061 if(Name != ""){
00062 this->path = Name;
00063 this->path.append("/");
00064 }
00065 char input = 0;
00066
00067 if(boost::filesystem::exists((path+"gripperDataTrace").c_str())){
00068 while(input != 'y' && input != 'n' && overwriteFiles == false){
00069 std::cout << "Do you want to overwrite the existing files? [n/y]" << std::endl;
00070
00071 input = getchar();
00072
00073 if(input == 'n'){
00074 throw std::runtime_error("Will not overwrite files!");
00075 }
00076 }
00077
00078 }else{
00079 boost::filesystem::path rootPath (this->path);
00080
00081 if ( !boost::filesystem::create_directories( rootPath ))
00082 throw std::runtime_error("could not create folder!");
00083
00084 }
00085
00086
00087 }
00088
00089 GripperDataTrace::~GripperDataTrace() {
00090
00091
00092 }
00093
00094 void GripperDataTrace::startTrace(const std::string parameterName, const std::string unit) {
00095
00096
00097 std::string parameterString;
00098 timeDurationMicroSec = 0;
00099
00100
00101 file.open((path+"gripperDataTrace").c_str(), std::fstream::out | std::fstream::trunc);
00102
00103 ptime today;
00104 today = second_clock::local_time();
00105
00106 file << "# Name: " << this->name << std::endl;
00107
00108 file << "# Date: " << boost::posix_time::to_simple_string(today) << std::endl;
00109
00110 file << "# time [milliseconds]"
00111 << " " << parameterName
00112 << std::endl;
00113
00114 parametersBeginTraceFile.open((path+"ParametersAtBegin").c_str(), std::fstream::out | std::fstream::trunc);
00115
00116
00117
00118
00119
00120
00121
00122 parameterVector.push_back(new ActualPosition);
00123 parameterVector.push_back(new ActualVelocity);
00124 parameterVector.push_back(new ActualAcceleration);
00125 parameterVector.push_back(new ActualLoadValue);
00126 parameterVector.push_back(new ChopperBlankTime);
00127 parameterVector.push_back(new ChopperHysteresisDecrement);
00128 parameterVector.push_back(new ChopperHysteresisStart);
00129 parameterVector.push_back(new ChopperHysteresisEnd);
00130 parameterVector.push_back(new ChopperMode);
00131 parameterVector.push_back(new ChopperOffTime);
00132 parameterVector.push_back(new DoubleStepEnable);
00133 parameterVector.push_back(new ErrorFlags);
00134 parameterVector.push_back(new Freewheeling);
00135 parameterVector.push_back(new MaximumAcceleration);
00136 parameterVector.push_back(new MaximumCurrent);
00137 parameterVector.push_back(new MaximumPositioningSpeed);
00138 parameterVector.push_back(new MicrostepResolution);
00139 parameterVector.push_back(new PowerDownDelay);
00140 parameterVector.push_back(new PulseDivisor);
00141 parameterVector.push_back(new RampDivisor);
00142 parameterVector.push_back(new RampMode);
00143 parameterVector.push_back(new ShortDetectionTimer);
00144 parameterVector.push_back(new ShortProtectionDisable);
00145 parameterVector.push_back(new SlopeControlHighSide);
00146 parameterVector.push_back(new SlopeControlLowSide);
00147 parameterVector.push_back(new SmartEnergyActualCurrent);
00148 parameterVector.push_back(new SmartEnergyCurrentDownStep);
00149 parameterVector.push_back(new SmartEnergyCurrentMinimum);
00150 parameterVector.push_back(new SmartEnergyCurrentUpStep);
00151 parameterVector.push_back(new SmartEnergyHysteresis);
00152 parameterVector.push_back(new SmartEnergyHysteresisStart);
00153 parameterVector.push_back(new SmartEnergySlowRunCurrent);
00154 parameterVector.push_back(new SmartEnergyThresholdSpeed);
00155 parameterVector.push_back(new StallGuard2FilterEnable);
00156 parameterVector.push_back(new StallGuard2Threshold);
00157 parameterVector.push_back(new StandbyCurrent);
00158 parameterVector.push_back(new StepInterpolationEnable);
00159 parameterVector.push_back(new StopOnStall);
00160 parameterVector.push_back(new Vsense);
00161 parameterVector.push_back(new MinimumSpeed);
00162
00163 parametersBeginTraceFile << "Name: " << this->name << std::endl;
00164 parametersBeginTraceFile << "Date: " << boost::posix_time::to_simple_string(today) << std::endl;
00165
00166
00167 for (unsigned int i = 0; i < parameterVector.size(); i++) {
00168 gripperBar.getConfigurationParameter(*(parameterVector[i]));
00169 parameterVector[i]->toString(parameterString);
00170
00171 parametersBeginTraceFile << parameterString << std::endl;
00172 }
00173 parametersBeginTraceFile.close();
00174
00175
00176 traceStartTime = microsec_clock::local_time();
00177
00178 }
00179
00180 void GripperDataTrace::stopTrace() {
00181
00182 file.close();
00183
00184 parametersEndTraceFile.open((path+"ParametersAfterTrace").c_str(), std::fstream::out | std::fstream::trunc);
00185 std::string parameterString;
00186
00187 parametersEndTraceFile << "Name: " << this->name << std::endl;
00188 ptime today;
00189 today = second_clock::local_time();
00190 parametersEndTraceFile << "Date: " << boost::posix_time::to_simple_string(today) << std::endl;
00191
00192
00193 for (unsigned int i = 0; i < parameterVector.size(); i++) {
00194 gripperBar.getConfigurationParameter(*(parameterVector[i]));
00195 parameterVector[i]->toString(parameterString);
00196 parametersEndTraceFile << parameterString << std::endl;
00197 delete parameterVector[i];
00198 }
00199
00200
00201 parametersEndTraceFile.close();
00202
00203 }
00204
00205 void GripperDataTrace::plotTrace() {
00206
00207
00208 std::string executeString = "cd ";
00209 executeString.append(path);
00210 executeString.append("; gnuplot ../../GripperGnuPlotConfig");
00211
00212 std::system(executeString.c_str());
00213
00214 }
00215
00216 void GripperDataTrace::updateTrace(const double parameterValue) {
00217
00218 timeDuration = microsec_clock::local_time() - traceStartTime;
00219 timeDurationMicroSec = timeDuration.total_milliseconds();
00220 file << timeDurationMicroSec << " " << parameterValue << std::endl;
00221
00222 }
00223
00224 unsigned long GripperDataTrace::getTimeDurationMilliSec() {
00225
00226 return timeDurationMicroSec;
00227
00228 }
00229
00230
00231 }