gloveServerRun.cc
Go to the documentation of this file.
00001 
00018 /* system includes */
00019 #include <stdio.h>
00020 #define BOOST_FILESYSTEM_VERSION 2
00021 #include <boost/program_options.hpp>
00022 #include <iostream>
00023 #include <signal.h>
00024 
00025 /* my includes */
00026 #include "gloveServer_impl.h"
00027 
00028 /* ros */
00029 #include "ros/ros.h"
00030 #include "std_msgs/String.h"
00031 #include <sstream>
00032 
00033 /*
00034  \brief The program's main function.
00035 
00036 
00037  */
00038 
00039 const static char* DEFAULT_CALIBRATION_LEFT = "cfg/GloveCalibrationRight.cal";
00040 const static char* DEFAULT_CALIBRATION_RIGHT = "cfg/GloveCalibrationRight.cal";
00041 const static char* DEFAULT_PUBLISH_NAME_RIGHT = "GloveRight";
00042 const static char* DEFAULT_PUBLISH_NAME_LEFT = "GloveLeft";
00043 const static char* DEFAULT_TTY_RIGHT = "/dev/ttyUSB0";
00044 const static char* DEFAULT_TTY_LEFT = "/dev/ttyUSB1";
00045 
00046 namespace po = boost::program_options;
00047 using namespace std;
00048 unsigned int debugLevel;
00049 
00050 po::variables_map vm;
00051 gloveServer_impl *gloveRight, *gloveLeft;
00052 bool do_loop;
00053 
00054 gloveServer_impl *
00055 startGlove(gloveID id, std::string serialPort, std::string gloveName, std::string calibFileName) {
00056         // create glove
00057         gloveServer_impl * glove = new gloveServer_impl(id, gloveName);
00058         if (glove->init(serialPort)) {
00059                 printf("glove %s started\n", (id == rightGlove) ? "right" : "left");
00060                 if (id == rightGlove) {
00061                         gloveRight = glove;
00062                 } else {
00063                         gloveLeft = glove;
00064                 }
00065         }
00066 
00067         if (!glove->loadCalibFile(calibFileName.c_str())) {
00068                 printf("Error while loading calibration. Bailing out!\n");
00069                 exit(-1);
00070         } else
00071                 printf("Calibration loaded successfully.\n");
00072 
00073         // start glove
00074 //      glove->start();
00075 
00077         if (!glove->threadRunning) {
00078                 glove->threadRunning = true;
00079                 glove->boostWorkerThread = new boost::thread(&gloveServer_impl::workerThread, glove);
00080         } else
00081                 printf("Thread started, but was already running.\n");
00082         printf("Thread running.\n");
00083 
00084         return glove;
00085 }
00086 
00087 int main(int argc, char **argv) {
00088         std::string ttyright;
00089         std::string ttyleft;
00090         std::string calibfileLeft;
00091         std::string calibfileRight;
00092         std::string pubNameRight = DEFAULT_PUBLISH_NAME_RIGHT;
00093         std::string pubNameLeft;
00094 
00095         po::options_description desc("Usage : cyberGloveServer [options]", 120);
00096         desc.add_options()("help,h", "show help screen")("glove-right,r", "use right glove")("glove-left,l",
00097                         "use left glove")("calibration-file-left",
00098                         po::value<std::string>(&calibfileLeft)->default_value(DEFAULT_CALIBRATION_LEFT),
00099                         "left glove calibration file")("calibration-file-right",
00100                         po::value<std::string>(&calibfileRight)->default_value(DEFAULT_CALIBRATION_RIGHT),
00101                         "right glove calibration file")("tty-right",
00102                         po::value<std::string>(&ttyright)->default_value(DEFAULT_TTY_RIGHT), "right glove tty (e.g. /dev/ttyS0")(
00103                         "tty-left", po::value<std::string>(&ttyleft)->default_value(DEFAULT_TTY_LEFT),
00104                         "left glove tty (e.g. /dev/ttyS1")("register-as-right",
00105                         po::value<std::string>(&pubNameRight)->default_value(DEFAULT_PUBLISH_NAME_RIGHT), "right glove Name")(
00106                         "register-as-left", po::value<std::string>(&pubNameLeft)->default_value(DEFAULT_PUBLISH_NAME_LEFT),
00107                         "left glove Name")("debug-level,d", po::value<unsigned int>(&debugLevel)->default_value(0),
00108                         "the more, the higher ;)");
00109 
00110         po::store(po::parse_command_line(argc, argv, desc), vm);
00111         po::notify(vm);
00112 
00113         if (vm.count("help")) {
00114                 cout << desc << endl;
00115                 return 0;
00116         }
00117 
00118         ros::init(argc, argv, "gloveServer_node");
00119 
00120         if (!vm.count("glove-right") && !vm.count("glove-left")) {
00121                 printf("No glove selected! Exit.\n");
00122                 exit(0);
00123         }
00124 
00125         // start glove right
00126         if (vm.count("glove-right")) {
00127                 printf("starting right glove on %s\n", ttyright.c_str());
00128                 startGlove(rightGlove, ttyright, pubNameRight, calibfileRight);
00129         }
00130         // start glove left
00131         if (vm.count("glove-left")) {
00132                 printf("starting left glove on %s\n", ttyleft.c_str());
00133                 startGlove(leftGlove, ttyleft, pubNameLeft, calibfileLeft);
00134         }
00135 
00136         // start corba replacement loop
00137         do_loop = true;
00138         std::string calibFile;
00139         while (do_loop & ros::ok()) {
00140                 sleep(1);
00141         }
00142 
00143         // delete objects
00144         if (vm.count("glove-right")) {
00145                 gloveRight->stop();
00146                 gloveRight->join();
00147                 delete gloveRight;
00148         }
00149         if (vm.count("glove-left")) {
00150                 gloveLeft->stop();
00151                 gloveLeft->join();
00152                 delete gloveLeft;
00153         }
00154         ROS_INFO("%s", "gloveServer exited normally. Gloves deleted.\n");
00155 
00156         return 0;
00157 }
00158 


asr_cyberglove_lib
Author(s): Heller Florian, Meißner Pascal, Nguyen Trung, Yi Xie
autogenerated on Thu Jun 6 2019 22:02:33