BotArmControlServer.C

Go to the documentation of this file.
00001 /*!@file Corba/Objects/BotArmControlServer.C control a robot via corba */
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: Michael Montalbo <montalbo@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Corba/Objects/BotArmControlServer.C $
00035 // $Id: BotArmControlServer.C 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 #include <stdlib.h>
00039 #include <time.h>
00040 #include <iostream>
00041 #include <unistd.h>
00042 #include <fcntl.h>
00043 #include <sys/types.h>
00044 #include <sys/stat.h>
00045 #include <signal.h>
00046 #include "Util/Assert.H"
00047 #include "Util/Timer.H"
00048 #include "Util/Types.H"
00049 #include "Component/ModelManager.H"
00050 #include "Corba/Objects/BotArmControlSK.hh"
00051 #include "Corba/Objects/BotArmControlServer.H"
00052 #include "Corba/CorbaUtil.H"
00053 
00054 CORBA::ORB_var orb;
00055 CosNaming::Name objectName;
00056 
00057 bool Debug = false;
00058 
00059 //! Signal handler (e.g., for control-C)
00060 void terminate(int s)
00061 {
00062         LERROR("*** INTERRUPT ***");
00063         unbindObject(orb, "saliency", "BotControllers", objectName);
00064         orb->shutdown(0);
00065 }
00066 
00067 void BotArmControlServer::shutdown() {
00068         // Shutdown the ORB
00069         unbindObject(orb, "saliency", "BotControllers", objectName);
00070         orb->shutdown(0);
00071 }
00072 
00073 
00074 BotArmControlServer::BotArmControlServer(OptionManager &mgr, bool debug) :
00075         Scorbot(mgr)
00076 {
00077 }
00078 
00079 
00080 BotArmControlServer::~BotArmControlServer()
00081 {
00082 
00083 }
00084 
00085 
00086 short BotArmControlServer::getEncoder(const short motor) {
00087 
00088   return motor+1;
00089 }
00090 
00091 void BotArmControlServer::setMotor(const short i, const float val) {
00092   LINFO("i: %i, val: %f",i,val);
00093 }
00094 
00095 
00096 //start the class server
00097 int main(int argc, char **argv){
00098 
00099         MYLOGVERB = LOG_INFO;
00100 
00101         // Instantiate a ModelManager:
00102         ModelManager manager("BotArmControlServer Corba Object");
00103 
00104         nub::ref<BotArmControlServer> botArmControlServer(new BotArmControlServer(manager, false));
00105         manager.addSubComponent(botArmControlServer);
00106 
00107         if (manager.parseCommandLine((const int)argc, (const char**)argv, "", 0, 0) == false)
00108                 return(1);
00109 
00110 //         if (manager.debugMode()){
00111 //                 Debug = true;
00112 //         } else {
00113 //                 LINFO("Running as a daemon. Set --debug to see any errors.");
00114 //                 //Become a daemon
00115 //                 // fork off the parent process
00116 //                 pid_t pid = fork();
00117 //                 if (pid < 0)
00118 //                         LFATAL("Can not fork");
00119 
00120 //                 if (pid > 0)
00121 //                         exit(0); //exit the parent process
00122 
00123 //                 // Change the file mask
00124 //                 umask(0);
00125 
00126 //                 //Create a new system id so that the kernel wont think we are an orphan.
00127 //                 pid_t sid = setsid();
00128 //                 if (sid < 0)
00129 //                         LFATAL("Can not become independent");
00130 
00131 //                 fclose(stdin);
00132 //                 fclose(stdout);
00133 //                 fclose(stderr);
00134 
00135 //         }
00136         // catch signals and redirect them to terminate for clean exit:
00137         signal(SIGHUP, terminate); signal(SIGINT, terminate);
00138         signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00139         signal(SIGALRM, terminate);
00140 
00141 
00142         //Create the object and run in
00143         orb = CORBA::ORB_init(argc, argv);
00144 
00145         CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
00146         PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
00147 
00148         BotArmControlServer* myobj = botArmControlServer.get();
00149 
00150 
00151         PortableServer::ObjectId_var objID = poa->activate_object(myobj);
00152 
00153         //get a ref string
00154 //         obj = myobj->_this();
00155 //         CORBA::String_var sior(orb->object_to_string(obj));
00156 //         std::cerr << "'" << (char*)sior << "'" << "\n";
00157 
00158         if( !bindObjectToName(orb, obj, "saliency", "BotControllers", "BotArmControlServer", objectName) )
00159                 return 1;
00160         myobj->_remove_ref();
00161 
00162         PortableServer::POAManager_var pman = poa->the_POAManager();
00163         pman->activate();
00164 
00165 
00166         try {
00167                 manager.start();
00168                 //run the object untill shutdown or killed
00169                 orb->run();
00170         } catch (...) {
00171                 LINFO("Error starting server");
00172         }
00173 
00174 
00175         LINFO("Shutting down");
00176         unbindObject(orb, "saliency", "BotControllers", objectName);
00177 
00178         manager.stop();
00179 
00180         return 0;
00181 }
Generated on Sun May 8 08:40:23 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3