test-pidTuner.C

Go to the documentation of this file.
00001 /*!@file Controllers/test-pidTuner.C Test the pid tuner */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Controllers/test-pidTuner.C $
00035 // $Id: test-pidTuner.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #include "Component/ModelManager.H"
00039 #include "Image/Image.H"
00040 #include "Image/DrawOps.H"
00041 #include "Image/ColorOps.H"
00042 #include "Image/VisualTracker.H"
00043 #include "GUI/ImageDisplayStream.H"
00044 #include "GUI/XWinManaged.H"
00045 #include "Devices/Serial.H"
00046 #include "Devices/WiiMote.H"
00047 #include "Util/CpuTimer.H"
00048 #include "Image/MathOps.H"
00049 #include "Image/Layout.H"
00050 #include "Media/FrameSeries.H"
00051 #include "Transport/FrameInfo.H"
00052 #include "Raster/GenericFrame.H"
00053 #include "Raster/Raster.H"
00054 #include "GUI/XWinManaged.H"
00055 #include "GUI/DebugWin.H"
00056 
00057 #define KEY_UP 98
00058 #define KEY_DOWN 104
00059 #define KEY_LEFT 100
00060 #define KEY_RIGHT 102
00061 
00062 
00063 int getKey(nub::ref<OutputFrameSeries> &ofs)
00064 {
00065   const nub::soft_ref<ImageDisplayStream> ids =
00066     ofs->findFrameDestType<ImageDisplayStream>();
00067 
00068   const rutz::shared_ptr<XWinManaged> uiwin =
00069     ids.is_valid()
00070     ? ids->getWindow("Output")
00071     : rutz::shared_ptr<XWinManaged>();
00072   return uiwin->getLastKeyPress();
00073 }
00074 
00075 Point2D<int> getMouseClick(nub::ref<OutputFrameSeries> &ofs, const char* wname)
00076 {
00077   const nub::soft_ref<ImageDisplayStream> ids =
00078     ofs->findFrameDestType<ImageDisplayStream>();
00079 
00080   const rutz::shared_ptr<XWinManaged> uiwin =
00081     ids.is_valid()
00082     ? ids->getWindow(wname)
00083     : rutz::shared_ptr<XWinManaged>();
00084 
00085   if (uiwin.is_valid())
00086     return uiwin->getLastMouseClick();
00087   else
00088     return Point2D<int>(-1,-1);
00089 }
00090 
00091 float simMassSpring(float force)
00092 {
00093 
00094   static float acc = 0;
00095   static float vel = 0;
00096   static float pos = 0;
00097 
00098   float dt = 0.6;
00099 
00100   float pPos = pos;
00101   float pVel = vel;
00102   pos = (force - 10*vel - 1 * acc)/20;
00103 
00104   vel = (pPos-pos)/dt;
00105   acc = (pVel-vel)/dt;
00106 
00107   return pos;
00108 
00109 }
00110 
00111 
00112 int main(int argc, const char **argv)
00113 {
00114   // Instantiate a ModelManager:
00115   ModelManager manager("Test wiimote");
00116 
00117   nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00118   manager.addSubComponent(ofs);
00119 
00120   // Parse command-line:
00121   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00122 
00123   manager.start();
00124 
00125   CpuTimer timer;
00126 
00127   timer.reset();
00128   Image<PixRGB<byte> > simImg(512,512,ZEROS);
00129 
00130   //Simulate a mass,spring,damper
00131 
00132   float x = 0;
00133   Point2D<int> lastLoc(0,simImg.getWidth()/2);
00134   simMassSpring(1.0F);
00135   while(1)
00136   {
00137     //Point2D<int> trackLoc = getMouseClick(ofs, "Output");
00138 
00139     float y = simMassSpring(0.0F);
00140     LINFO("y=%f", y);
00141     Point2D<int> loc((int)x*7,simImg.getWidth()/2 + (int)(y*1000));
00142 
00143     if (simImg.coordsOk(loc))
00144     {
00145       drawLine(simImg, lastLoc, loc, PixRGB<byte>(255,0,0));
00146       lastLoc = loc;
00147     }
00148 
00149     ofs->writeRGB(simImg, "Output", FrameInfo("output", SRC_POS));
00150     ofs->updateNext();
00151     usleep(10000);
00152 
00153     x++;
00154   }
00155 
00156   // stop all our ModelComponents
00157   manager.stop();
00158 
00159   // all done!
00160   return 0;
00161 }
00162 
00163 // ######################################################################
00164 /* So things look consistent in everyone's emacs... */
00165 /* Local Variables: */
00166 /* indent-tabs-mode: nil */
00167 /* End: */
Generated on Sun May 8 08:40:23 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3