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


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Oct 6 2014 09:08:01