drive2f.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 #include "Image/OpenCVUtil.H"
00038 #include "Image/Image.H"
00039 #include "Image/Pixels.H"
00040 #include "Component/ModelManager.H"
00041 #include "Image/CutPaste.H"
00042 #include "Util/Timer.H"
00043 #include "Controllers/PID.H"
00044 #include "Image/PyrBuilder.H"
00045 #include "RCBot/TrackFeature.H"
00046
00047 #include <signal.h>
00048 #include <unistd.h>
00049 #include <netdb.h>
00050 #include <fcntl.h>
00051 #include <arpa/inet.h>
00052 #include <stdlib.h>
00053
00054 #include "Corba/Objects/BotControlServerSK.hh"
00055 #include "Corba/Objects/SceneRecServerSK.hh"
00056 #include "Corba/ImageOrbUtil.H"
00057 #include "Corba/CorbaUtil.H"
00058
00059 #define LAND_WINSIZE 50
00060
00061 char info[255];
00062 Point2D<int> trackLoc(-1,-1);
00063
00064 static bool goforever = true;
00065
00066
00067 void terminate(int s)
00068 { LERROR("*** INTERRUPT ***"); goforever = false; exit(1); }
00069
00070 int main(int argc, char **argv)
00071 {
00072 MYLOGVERB = LOG_INFO;
00073
00074
00075 signal(SIGHUP, terminate); signal(SIGINT, terminate);
00076 signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00077 signal(SIGALRM, terminate);
00078
00079 CORBA::ORB_ptr orb = CORBA::ORB_init(argc,argv,"omniORB4");
00080
00081
00082 ModelManager manager("SaliencyMT Tester");
00083
00084 nub::ref<SaliencyMT> smt(new SaliencyMT(manager, orb, 0));
00085 manager.addSubComponent(smt);
00086
00087
00088 CORBA::Object_ptr objBotControlRef[1]; int nBotControlObj;
00089 if (!getMultiObjectRef(orb, "saliency.BotControllers",
00090 objBotControlRef, nBotControlObj))
00091 {
00092 LFATAL("Can not find any object to bind with");
00093 }
00094
00095 BotControlServer_var robotController =
00096 BotControlServer::_narrow(objBotControlRef[0]);
00097
00098
00099 if (manager.parseCommandLine((const int)argc, (const char**)argv, "", 0, 1) == false)
00100 return(1);
00101
00102 manager.start();
00103
00104 PID<float> steer_pid(0.03, 0, 0, -1, 1);
00105
00106
00107 robotController->init();
00108
00109 short w, h;
00110 robotController->getImageSensorDims(w,h,0);
00111 LINFO("Dim %i %i", w, h);
00112
00113 sprintf(info, "Testing...");
00114
00115
00116 TrackFeature trackFeature(smt);
00117
00118 int leg = 0;
00119
00120
00121 robotController->setSpeed(0);
00122 robotController->setSteering(0);
00123
00124
00125 while(goforever)
00126 {
00127
00128 ImageOrb *imgOrb = robotController->getImageSensor(0);
00129 Image< PixRGB<byte> > ima;
00130 orb2Image(*imgOrb, ima);
00131
00132
00133 trackFeature.setImg(ima);
00134
00135
00136 trackLoc = trackFeature.getTrackLoc();
00137
00138 Point2DOrb locOrb;
00139 int key = robotController->getUserInput(locOrb);
00140
00141 if (locOrb.i > 1 && locOrb.j > 1)
00142 {
00143 trackLoc.i = locOrb.i; trackLoc.j = locOrb.j;
00144 if (key != -1 || trackLoc.isValid())
00145 {
00146 LINFO("Key %i loc (%i,%i)", key, trackLoc.i, trackLoc.j);
00147 }
00148
00149
00150 trackFeature.setTrackLoc(trackLoc, ima);
00151 }
00152
00153
00154 if (trackLoc.isValid())
00155 {
00156 double steer_cor = steer_pid.update(w/2, trackLoc.i);
00157
00158 if (steer_cor > 1) steer_cor = 1;
00159 else if (steer_cor < -1) steer_cor = -1;
00160
00161 LINFO("Steer %i %i %f\n", w/2, trackLoc.i, steer_cor);
00162 robotController->setSteering(steer_cor);
00163
00164 }
00165 else
00166 {
00167 robotController->setSpeed(0);
00168 }
00169
00170 sprintf(info, "%.1ffps l=%i", trackFeature.getFps(), leg);
00171 robotController->setInfo(info, toOrb(trackLoc), toOrb(trackLoc));
00172 }
00173
00174 manager.stop();
00175 return 0;
00176 }
00177
00178
00179
00180
00181
00182