test-ScorbotServer.C

00001 #include <Ice/Ice.h>
00002 #include "Component/ModelManager.H"
00003 #include "Robots/Scorbot/Scorbot.ice.H"
00004 #include "Media/FrameSeries.H"
00005 #include "Raster/GenericFrame.H"
00006 #include "Transport/FrameInfo.H"
00007 #include "Image/Image.H"
00008 #include "Image/DrawOps.H"
00009 #include "GUI/PrefsWindow.H"
00010 #include "Devices/DeviceOpts.H"
00011 #include <vector>
00012 #include <pthread.h>
00013 
00014 
00015 
00016 nub::soft_ref<OutputFrameSeries> ofs;
00017 nub::soft_ref<InputFrameSeries> ifs;
00018 
00019 void *displayThread(void*)
00020 {
00021         PrefsWindow pWin("Camera Control", SimpleFont::FIXED(8));
00022         pWin.setValueNumChars(16);
00023         pWin.addPrefsForComponent(ifs.get(), true);
00024 
00025         while(1)
00026         {
00027                 pWin.update();
00028 
00029                 if(ifs->updateNext() == FRAME_COMPLETE) break;
00030                 GenericFrame input = ifs->readFrame();
00031                 if(!input.initialized()) break;
00032 
00033                 Image<PixRGB<byte> > img = input.asRgb();
00034                 Dims winSize(512, 512);
00035                 Point2D<int> center(img.getWidth()/2, img.getHeight()/2);
00036 
00037 
00038 //              drawCircle(img, center, 16, PixRGB<byte>(255, 0, 0), 2);
00039 //              drawCircle(img, center, 2, PixRGB<byte>(255, 0, 0), 2);
00040 
00041                 ofs->writeRGB(img, "Output", FrameInfo("output", SRC_POS));
00042                 ofs->updateNext();
00043 
00044         }
00045 
00046         pthread_exit(NULL);
00047 
00048 }
00049 
00050 int main(int argc, char* argv[])
00051 {
00052         ModelManager mgr("Test Scorbot Interface");
00053 
00054         ifs.reset(new InputFrameSeries(mgr));
00055         mgr.addSubComponent(ifs);
00056 
00057         ofs.reset(new OutputFrameSeries(mgr));
00058         mgr.addSubComponent(ofs);
00059 
00060         if(mgr.parseCommandLine(argc, argv, "RunPath [true|false]", 1, 1) == false) return -1;
00061         mgr.start();
00062         ifs->startStream();
00063 
00064         bool runPath = false;
00065 
00066         if(mgr.numExtraArgs() > 0)
00067         {
00068                 if(mgr.getExtraArg(0) == "true") runPath = true;
00069         }
00070 
00071 
00072         ScorbotIce::ScorbotPrx scorbot;
00073 
00074         bool IceError = false;
00075         Ice::CommunicatorPtr ic;
00076         try {
00077                 int argc_fake=1; char* argv_fake[argc_fake];
00078                 argv[0] = new char[128]; sprintf(argv[0], "test-ScorbotServer");
00079                 ic = Ice::initialize(argc_fake, argv_fake);
00080                 Ice::ObjectPrx base = ic->stringToProxy(
00081                                 "ScorbotServer:default -p 10000 -h ihead");
00082                 scorbot = ScorbotIce::ScorbotPrx::checkedCast(base);
00083                 if(!scorbot)
00084                         throw "Invalid Proxy";
00085         } catch (const Ice::Exception& ex) {
00086                 std::cerr << ex << std::endl;
00087                 IceError = true;
00088         } catch(const char* msg) {
00089                 std::cerr << msg << std::endl;
00090                 IceError = true;
00091         }
00092         if(IceError) {
00093                 std::cerr << "#################### ERROR - QUITTING ####################" << std::endl;
00094                 if(ic) ic->destroy();
00095                 exit(-1);
00096         }
00097 
00098         pthread_t videoThread;
00099         pthread_create(&videoThread, NULL, displayThread, NULL);
00100 
00101         scorbot->setEnabled(true);
00102 
00103         std::vector<int> focusVals;
00104         std::vector<ScorbotIce::encoderValsType> positions;
00105         ScorbotIce::encoderValsType encoderVals;
00106         int focus = 8;
00107 
00108         ////////////////////////////////////////
00109         focus = 8;
00110         encoderVals[ScorbotIce::Base] = -4286;
00111         encoderVals[ScorbotIce::Shoulder] = 8976;
00112         encoderVals[ScorbotIce::Elbow] = -3940;
00113         encoderVals[ScorbotIce::Wrist1] = 1884;
00114         encoderVals[ScorbotIce::Wrist2] = -2291;
00115         encoderVals[ScorbotIce::Gripper] = 0;
00116         encoderVals[ScorbotIce::Slider] = -42130;
00117         positions.push_back(encoderVals);
00118         focusVals.push_back(focus);
00119 
00120         ////////////////////////////////////////
00121         focus = 9;
00122         encoderVals[ScorbotIce::Base] = -3397;
00123         encoderVals[ScorbotIce::Shoulder] = 6985;
00124         encoderVals[ScorbotIce::Elbow] = 1502;
00125         encoderVals[ScorbotIce::Wrist1] = 1881;
00126         encoderVals[ScorbotIce::Wrist2] = -2288;
00127         encoderVals[ScorbotIce::Gripper] = 0;
00128         encoderVals[ScorbotIce::Slider] = -42130;
00129         positions.push_back(encoderVals);
00130         focusVals.push_back(focus);
00131 
00132         ////////////////////////////////////////
00133         focus = 13;
00134         encoderVals[ScorbotIce::Base] = 1805;
00135         encoderVals[ScorbotIce::Shoulder] = 2720;
00136         encoderVals[ScorbotIce::Elbow] = 4072;
00137         encoderVals[ScorbotIce::Wrist1] = 2140;
00138         encoderVals[ScorbotIce::Wrist2] = -2416;
00139         encoderVals[ScorbotIce::Gripper] = 0;
00140         encoderVals[ScorbotIce::Slider] = 34534;
00141         positions.push_back(encoderVals);
00142         focusVals.push_back(focus);
00143 
00144         ////////////////////////////////////////
00145         focus = 10;
00146         encoderVals[ScorbotIce::Base] = 2251;
00147         encoderVals[ScorbotIce::Shoulder] = 8416;
00148         encoderVals[ScorbotIce::Elbow] = 2537;
00149         encoderVals[ScorbotIce::Wrist1] = 1720;
00150         encoderVals[ScorbotIce::Wrist2] = -1793;
00151         encoderVals[ScorbotIce::Gripper] = 0;
00152         encoderVals[ScorbotIce::Slider] = 109292;
00153         positions.push_back(encoderVals);
00154         focusVals.push_back(focus);
00155 
00156         ////////////////////////////////////////
00157         focus = 11;
00158         encoderVals[ScorbotIce::Base] = -821;
00159         encoderVals[ScorbotIce::Shoulder] = 5717;
00160         encoderVals[ScorbotIce::Elbow] = 2081;
00161         encoderVals[ScorbotIce::Wrist1] = 1492;
00162         encoderVals[ScorbotIce::Wrist2] = -1631;
00163         encoderVals[ScorbotIce::Gripper] = 0;
00164         encoderVals[ScorbotIce::Slider] = 32629;
00165         positions.push_back(encoderVals);
00166         focusVals.push_back(focus);
00167         ////////////////////////////////////////
00168         focus = 10;
00169         encoderVals[ScorbotIce::Base] = -6493;
00170         encoderVals[ScorbotIce::Shoulder] = 6407;
00171         encoderVals[ScorbotIce::Elbow] = 1812;
00172         encoderVals[ScorbotIce::Wrist1] = 1831;
00173         encoderVals[ScorbotIce::Wrist2] = -1763;
00174         encoderVals[ScorbotIce::Gripper] = 0;
00175         encoderVals[ScorbotIce::Slider] = -3482;
00176         positions.push_back(encoderVals);
00177         focusVals.push_back(focus);
00178 
00179         mgr.setOptionValString(&OPT_FrameGrabberFocusAuto, "false");
00180         while(1)
00181         {
00182                 if(runPath)
00183                 {
00184                         for(size_t posIdx=0; posIdx<positions.size(); posIdx++)
00185                         {
00186                                 std::cout << "---------------------------------------" << std::endl;
00187                                 std::cout << "Going To Position " << posIdx << std::endl;
00188 
00189                                 // Set the focus
00190                                 char buffer[32];
00191                                 sprintf(buffer, "%d", focusVals[posIdx]);
00192                                 std::string focusString(buffer);
00193                                 mgr.setOptionValString(&OPT_FrameGrabberFocus, focusString);
00194 
00195                                 // Set the joints
00196                                 scorbot->setJoints(positions[posIdx], 2000);
00197 
00198                                 sleep(2);
00199 
00200                                 std::cout << "Done..." << std::endl;
00201 
00202                                 // Print the final positions
00203                                 ScorbotIce::encoderValsType currPos = scorbot->getEncoders();
00204                                 std::cout << "Base:     " << currPos[ScorbotIce::Base]     << " / " << positions[posIdx][ScorbotIce::Base]     << std::endl;
00205                                 std::cout << "Shoulder: " << currPos[ScorbotIce::Shoulder] << " / " << positions[posIdx][ScorbotIce::Shoulder] << std::endl;
00206                                 std::cout << "Elbow:    " << currPos[ScorbotIce::Elbow]    << " / " << positions[posIdx][ScorbotIce::Elbow]    << std::endl;
00207                                 std::cout << "Wrist1:   " << currPos[ScorbotIce::Wrist1]   << " / " << positions[posIdx][ScorbotIce::Wrist1]   << std::endl;
00208                                 std::cout << "Wrist2:   " << currPos[ScorbotIce::Wrist2]   << " / " << positions[posIdx][ScorbotIce::Wrist2]   << std::endl;
00209                                 std::cout << "Gripper:  " << currPos[ScorbotIce::Gripper]  << " / " << positions[posIdx][ScorbotIce::Gripper]  << std::endl;
00210                                 std::cout << "Slider:   " << currPos[ScorbotIce::Slider]   << " / " << positions[posIdx][ScorbotIce::Slider]   << std::endl;
00211                                 sleep(2);
00212                         } // for
00213                 } // if(runPath)
00214 
00215                 sleep(1);
00216 
00217         } // while(1)
00218 
00219 }
00220 
Generated on Sun May 8 08:41:32 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3