PIDTuner.C
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 #include "Controllers/PIDTuner.H"
00039 #include "Component/ModelOptionDef.H"
00040 #include "Component/ModelParam.H"
00041 #include "Image/CutPaste.H"
00042 #include "GUI/DebugWin.H"
00043 #include "Media/FrameSeries.H"
00044 #include "Transport/FrameInfo.H"
00045
00046 #include "Util/JobWithSemaphore.H"
00047 #include "Util/StringUtil.H"
00048 #include "Util/WorkThreadServer.H"
00049 #include "Util/sformat.H"
00050 #include "rutz/compat_snprintf.h"
00051
00052 #include <ctype.h>
00053 #include <deque>
00054 #include <iterator>
00055 #include <stdlib.h>
00056 #include <string.h>
00057 #include <sys/resource.h>
00058 #include <time.h>
00059 #include <vector>
00060
00061
00062 namespace
00063 {
00064 class PIDTunerLoop : public JobWithSemaphore
00065 {
00066 public:
00067 PIDTunerLoop(PIDTuner* pidGUI)
00068 :
00069 itsPIDTuner(pidGUI),
00070 itsPriority(1),
00071 itsJobType("GUI Loop")
00072 {}
00073
00074 virtual ~PIDTunerLoop() {}
00075
00076 virtual void run()
00077 {
00078 ASSERT(itsPIDTuner);
00079 while(1)
00080 {
00081 itsPIDTuner->update();
00082 usleep(10000);
00083 }
00084 }
00085
00086 virtual const char* jobType() const
00087 { return itsJobType.c_str(); }
00088
00089 virtual int priority() const
00090 { return itsPriority; }
00091
00092 private:
00093 PIDTuner* itsPIDTuner;
00094 const int itsPriority;
00095 const std::string itsJobType;
00096 };
00097 }
00098
00099
00100
00101 PIDTuner::PIDTuner(OptionManager& mgr,
00102 PID<float> &pid,
00103 Dims d,
00104 const std::string& descrName,
00105 const std::string& tagName) :
00106 ModelComponent(mgr, descrName, tagName),
00107 itsPID(pid),
00108 itsWinDims(d),
00109 itsLastLoc(0, d.h()/2),
00110 itsCurrentX(0)
00111 {
00112 itsPIDImg = Image<PixRGB<byte> >(d,ZEROS);
00113
00114 }
00115
00116
00117 PIDTuner::~PIDTuner()
00118 {
00119 }
00120
00121 void PIDTuner::start2()
00122 {
00123 }
00124
00125 void PIDTuner::startThread(nub::ref<OutputFrameSeries> &ofs)
00126 {
00127 LINFO("Starting Gui thread");
00128
00129 itsThreadServer.reset(new WorkThreadServer("GuiThread",1));
00130 itsThreadServer->setFlushBeforeStopping(false);
00131 rutz::shared_ptr<PIDTunerLoop> j(new PIDTunerLoop(this));
00132 itsThreadServer->enqueueJob(j);
00133 itsOfs = ofs;
00134 }
00135
00136 void PIDTuner::stopThread()
00137 {
00138
00139 }
00140
00141
00142
00143 void PIDTuner::update()
00144 {
00145
00146 float y = itsPID.getErr();
00147
00148 Point2D<int> loc((int)itsCurrentX, itsPIDImg.getWidth()/2 + (int)(y*itsPIDImg.getHeight()/2));
00149 if (itsPIDImg.coordsOk(loc))
00150 {
00151 drawLine(itsPIDImg, itsLastLoc, loc, PixRGB<byte>(0,255,0));
00152 itsLastLoc = loc;
00153 }
00154
00155
00156 itsCurrentX++;
00157 if (itsCurrentX > itsPIDImg.getWidth())
00158 {
00159 itsPIDImg.clear();
00160 itsLastLoc = Point2D<int>(0, itsPIDImg.getHeight()/2);
00161 itsCurrentX = 0;
00162 }
00163
00164 itsOfs->writeRGB(itsPIDImg, "PIDTuner GUI",
00165 FrameInfo("PIDTuner Display", SRC_POS));
00166
00167
00168 }
00169
00170
00171
00172
00173
00174
00175
00176