GripperDataTrace.cpp

Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2011
00004  * All rights reserved.
00005  *
00006  * Hochschule Bonn-Rhein-Sieg
00007  * University of Applied Sciences
00008  * Computer Science Department
00009  *
00010  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00011  *
00012  * Author:
00013  * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
00014  * Supervised by:
00015  * Gerhard K. Kraetzschmar
00016  *
00017  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00018  *
00019  * This sofware is published under a dual-license: GNU Lesser General Public 
00020  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
00021  * code may choose which terms they prefer.
00022  *
00023  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00024  *
00025  * Redistribution and use in source and binary forms, with or without
00026  * modification, are permitted provided that the following conditions are met:
00027  *
00028  *     * Redistributions of source code must retain the above copyright
00029  *       notice, this list of conditions and the following disclaimer.
00030  *     * Redistributions in binary form must reproduce the above copyright
00031  *       notice, this list of conditions and the following disclaimer in the
00032  *       documentation and/or other materials provided with the distribution.
00033  *     * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
00034  *       contributors may be used to endorse or promote products derived from
00035  *       this software without specific prior written permission.
00036  *
00037  * This program is free software: you can redistribute it and/or modify
00038  * it under the terms of the GNU Lesser General Public License LGPL as
00039  * published by the Free Software Foundation, either version 2.1 of the
00040  * License, or (at your option) any later version or the BSD license.
00041  *
00042  * This program is distributed in the hope that it will be useful,
00043  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00044  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00045  * GNU Lesser General Public License LGPL and the BSD license for more details.
00046  *
00047  * You should have received a copy of the GNU Lesser General Public
00048  * License LGPL and BSD license along with this program.
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   // Bouml preserved body begin 00101BF1
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   // Bouml preserved body end 00101BF1
00087 }
00088 
00089 GripperDataTrace::~GripperDataTrace() {
00090   // Bouml preserved body begin 00101C71
00091   // Bouml preserved body end 00101C71
00092 }
00093 
00094 void GripperDataTrace::startTrace(const std::string parameterName, const std::string unit) {
00095   // Bouml preserved body begin 00101CF1
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  //   parameterVector.push_back(new GripperFirmwareVersion);
00119  //   parameterVector.push_back(new BarSpacingOffset);
00120  //   parameterVector.push_back(new MaxEncoderValue);
00121 //    parameterVector.push_back(new MaxTravelDistance);
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       //   std::cout << parameterString << std::endl;
00171       parametersBeginTraceFile << parameterString << std::endl;
00172     }
00173     parametersBeginTraceFile.close();
00174 
00175 
00176     traceStartTime = microsec_clock::local_time();
00177   // Bouml preserved body end 00101CF1
00178 }
00179 
00180 void GripperDataTrace::stopTrace() {
00181   // Bouml preserved body begin 00101D71
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   // Bouml preserved body end 00101D71
00203 }
00204 
00205 void GripperDataTrace::plotTrace() {
00206   // Bouml preserved body begin 00101DF1
00207   
00208     std::string executeString = "cd ";
00209     executeString.append(path);
00210     executeString.append("; gnuplot ../../GripperGnuPlotConfig");
00211     // > /dev/null 2>&1");
00212     std::system(executeString.c_str());
00213   // Bouml preserved body end 00101DF1
00214 }
00215 
00216 void GripperDataTrace::updateTrace(const double parameterValue) {
00217   // Bouml preserved body begin 001021F1
00218     timeDuration = microsec_clock::local_time() - traceStartTime;
00219     timeDurationMicroSec = timeDuration.total_milliseconds();
00220     file << timeDurationMicroSec << " " << parameterValue << std::endl;
00221   // Bouml preserved body end 001021F1
00222 }
00223 
00224 unsigned long GripperDataTrace::getTimeDurationMilliSec() {
00225   // Bouml preserved body begin 00102271
00226   return timeDurationMicroSec;
00227   // Bouml preserved body end 00102271
00228 }
00229 
00230 
00231 } // namespace youbot
Generated by  doxygen 1.6.3