test-pidTuner.C
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 #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
00115 ModelManager manager("Test wiimote");
00116
00117 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00118 manager.addSubComponent(ofs);
00119
00120
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
00131
00132 float x = 0;
00133 Point2D<int> lastLoc(0,simImg.getWidth()/2);
00134 simMassSpring(1.0F);
00135 while(1)
00136 {
00137
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
00157 manager.stop();
00158
00159
00160 return 0;
00161 }
00162
00163
00164
00165
00166
00167