test-Gumbot.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 <Ice/Ice.h>
00039 #include "Ice/Gumbot.ice.H"
00040 #include "Ice/ImageIce.ice.H"
00041 #include "Ice/IceImageUtils.H"
00042
00043 #include "Component/ModelManager.H"
00044 #include "Media/FrameSeries.H"
00045 #include "Transport/FrameInfo.H"
00046 #include "Raster/GenericFrame.H"
00047 #include "Image/Image.H"
00048 #include "GUI/XWinManaged.H"
00049 #include "GUI/ImageDisplayStream.H"
00050
00051 using namespace std;
00052 using namespace Robots;
00053
00054 #define KEY_UP 98
00055 #define KEY_DOWN 104
00056 #define KEY_LEFT 100
00057 #define KEY_RIGHT 102
00058
00059 int getKey(nub::ref<OutputFrameSeries> &ofs)
00060 {
00061 const nub::soft_ref<ImageDisplayStream> ids =
00062 ofs->findFrameDestType<ImageDisplayStream>();
00063
00064 const rutz::shared_ptr<XWinManaged> uiwin =
00065 ids.is_valid()
00066 ? ids->getWindow("Output")
00067 : rutz::shared_ptr<XWinManaged>();
00068 return uiwin->getLastKeyPress();
00069 }
00070
00071
00072 int main(int argc, char** argv)
00073 {
00074
00075 MYLOGVERB = LOG_INFO;
00076 ModelManager manager("test-Gumbot");
00077
00078 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00079 manager.addSubComponent(ofs);
00080
00081
00082 int status = 0;
00083 Ice::CommunicatorPtr ic;
00084 try {
00085 ic = Ice::initialize(argc, argv);
00086 Ice::ObjectPrx base = ic->stringToProxy(
00087 "GumbotService:default -p 10000 -h 192.168.1.15");
00088 GumbotPrx gumbot = GumbotPrx::checkedCast(base);
00089 if(!gumbot)
00090 throw "Invalid proxy";
00091
00092 manager.exportOptions(MC_RECURSE);
00093
00094 if (manager.parseCommandLine((const int)argc, (const char**)argv, "", 0, 0) == false)
00095 return 1;
00096 manager.start();
00097
00098 Image<PixRGB<byte> > gumbotImg = Ice2Image<PixRGB<byte> >(gumbot->getImageSensor(0));
00099 ofs->writeRGB(gumbotImg, "Output", FrameInfo("Output", SRC_POS));
00100
00101 gumbot->sendStart();
00102 gumbot->setMode(Robots::SafeMode);
00103 while(true)
00104 {
00105
00106
00107
00108 int key = getKey(ofs);
00109
00110
00111 if (key != -1)
00112 {
00113 switch(key)
00114 {
00115 case KEY_UP:
00116 gumbot->setSteering(0);
00117 gumbot->setSpeed(200);
00118 break;
00119 case KEY_DOWN:
00120 gumbot->setSteering(0);
00121 gumbot->setSpeed(-200);
00122 break;
00123 case KEY_LEFT:
00124 gumbot->setSteering(10);
00125 gumbot->setSpeed(100);
00126 break;
00127 case KEY_RIGHT:
00128 gumbot->setSteering(-10);
00129 gumbot->setSpeed(100);
00130 break;
00131 case 65:
00132 gumbot->setMode(Robots::SafeMode);
00133 gumbot->setSteering(0);
00134 gumbot->setSpeed(0);
00135 break;
00136 case 33:
00137 LINFO("Play song");
00138 gumbot->playSong(0);
00139 break;
00140 case 40:
00141 LINFO("Docking");
00142 gumbot->setMode(Robots::CoverAndDockMode);
00143 break;
00144 default:
00145 LINFO("Unknown key %i\n", key);
00146 break;
00147 }
00148 }
00149 }
00150
00151 }
00152 catch (const Ice::Exception& ex) {
00153 cerr << ex << endl;
00154 status = 1;
00155 }
00156 catch(const char* msg) {
00157 cerr << msg << endl;
00158 status = 1;
00159 }
00160 if (ic)
00161 ic->destroy();
00162 return status;
00163 }