gloveServerRun.cc
Go to the documentation of this file.
1 
18 /* system includes */
19 #include <stdio.h>
20 #define BOOST_FILESYSTEM_VERSION 2
21 #include <boost/program_options.hpp>
22 #include <iostream>
23 #include <signal.h>
24 
25 /* my includes */
26 #include "gloveServer_impl.h"
27 
28 /* ros */
29 #include "ros/ros.h"
30 #include "std_msgs/String.h"
31 #include <sstream>
32 
33 /*
34  \brief The program's main function.
35 
36 
37  */
38 
39 const static char* DEFAULT_CALIBRATION_LEFT = "cfg/GloveCalibrationRight.cal";
40 const static char* DEFAULT_CALIBRATION_RIGHT = "cfg/GloveCalibrationRight.cal";
41 const static char* DEFAULT_PUBLISH_NAME_RIGHT = "GloveRight";
42 const static char* DEFAULT_PUBLISH_NAME_LEFT = "GloveLeft";
43 const static char* DEFAULT_TTY_RIGHT = "/dev/ttyUSB0";
44 const static char* DEFAULT_TTY_LEFT = "/dev/ttyUSB1";
45 
46 namespace po = boost::program_options;
47 using namespace std;
48 unsigned int debugLevel;
49 
50 po::variables_map vm;
52 bool do_loop;
53 
55 startGlove(gloveID id, std::string serialPort, std::string gloveName, std::string calibFileName) {
56  // create glove
57  gloveServer_impl * glove = new gloveServer_impl(id, gloveName);
58  if (glove->init(serialPort)) {
59  printf("glove %s started\n", (id == rightGlove) ? "right" : "left");
60  if (id == rightGlove) {
61  gloveRight = glove;
62  } else {
63  gloveLeft = glove;
64  }
65  }
66 
67  if (!glove->loadCalibFile(calibFileName.c_str())) {
68  printf("Error while loading calibration. Bailing out!\n");
69  exit(-1);
70  } else
71  printf("Calibration loaded successfully.\n");
72 
73  // start glove
74 // glove->start();
75 
77  if (!glove->threadRunning) {
78  glove->threadRunning = true;
79  glove->boostWorkerThread = new boost::thread(&gloveServer_impl::workerThread, glove);
80  } else
81  printf("Thread started, but was already running.\n");
82  printf("Thread running.\n");
83 
84  return glove;
85 }
86 
87 int main(int argc, char **argv) {
88  std::string ttyright;
89  std::string ttyleft;
90  std::string calibfileLeft;
91  std::string calibfileRight;
92  std::string pubNameRight = DEFAULT_PUBLISH_NAME_RIGHT;
93  std::string pubNameLeft;
94 
95  po::options_description desc("Usage : cyberGloveServer [options]", 120);
96  desc.add_options()("help,h", "show help screen")("glove-right,r", "use right glove")("glove-left,l",
97  "use left glove")("calibration-file-left",
98  po::value<std::string>(&calibfileLeft)->default_value(DEFAULT_CALIBRATION_LEFT),
99  "left glove calibration file")("calibration-file-right",
100  po::value<std::string>(&calibfileRight)->default_value(DEFAULT_CALIBRATION_RIGHT),
101  "right glove calibration file")("tty-right",
102  po::value<std::string>(&ttyright)->default_value(DEFAULT_TTY_RIGHT), "right glove tty (e.g. /dev/ttyS0")(
103  "tty-left", po::value<std::string>(&ttyleft)->default_value(DEFAULT_TTY_LEFT),
104  "left glove tty (e.g. /dev/ttyS1")("register-as-right",
105  po::value<std::string>(&pubNameRight)->default_value(DEFAULT_PUBLISH_NAME_RIGHT), "right glove Name")(
106  "register-as-left", po::value<std::string>(&pubNameLeft)->default_value(DEFAULT_PUBLISH_NAME_LEFT),
107  "left glove Name")("debug-level,d", po::value<unsigned int>(&debugLevel)->default_value(0),
108  "the more, the higher ;)");
109 
110  po::store(po::parse_command_line(argc, argv, desc), vm);
111  po::notify(vm);
112 
113  if (vm.count("help")) {
114  cout << desc << endl;
115  return 0;
116  }
117 
118  ros::init(argc, argv, "gloveServer_node");
119 
120  if (!vm.count("glove-right") && !vm.count("glove-left")) {
121  printf("No glove selected! Exit.\n");
122  exit(0);
123  }
124 
125  // start glove right
126  if (vm.count("glove-right")) {
127  printf("starting right glove on %s\n", ttyright.c_str());
128  startGlove(rightGlove, ttyright, pubNameRight, calibfileRight);
129  }
130  // start glove left
131  if (vm.count("glove-left")) {
132  printf("starting left glove on %s\n", ttyleft.c_str());
133  startGlove(leftGlove, ttyleft, pubNameLeft, calibfileLeft);
134  }
135 
136  // start corba replacement loop
137  do_loop = true;
138  std::string calibFile;
139  while (do_loop & ros::ok()) {
140  sleep(1);
141  }
142 
143  // delete objects
144  if (vm.count("glove-right")) {
145  gloveRight->stop();
146  gloveRight->join();
147  delete gloveRight;
148  }
149  if (vm.count("glove-left")) {
150  gloveLeft->stop();
151  gloveLeft->join();
152  delete gloveLeft;
153  }
154  ROS_INFO("%s", "gloveServer exited normally. Gloves deleted.\n");
155 
156  return 0;
157 }
158 
boost::thread * boostWorkerThread
Thread for delivering tracker data to nCenter.
static const char * DEFAULT_PUBLISH_NAME_RIGHT
unsigned int debugLevel
bool loadCalibFile(const char *srcFileName)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
gloveServer_impl * gloveLeft
bool init(std::string serialPort)
void workerThread()
this method is called by static method s_workerthread
static const char * DEFAULT_TTY_RIGHT
po::variables_map vm
bool threadRunning
flag switching on/off thread
int main(int argc, char **argv)
#define ROS_INFO(...)
static const char * DEFAULT_CALIBRATION_RIGHT
gloveServer_impl * gloveRight
ROSCPP_DECL bool ok()
static const char * DEFAULT_CALIBRATION_LEFT
static const char * DEFAULT_TTY_LEFT
static const char * DEFAULT_PUBLISH_NAME_LEFT
gloveServer_impl * startGlove(gloveID id, std::string serialPort, std::string gloveName, std::string calibFileName)
gloveID
bool do_loop


asr_cyberglove_lib
Author(s): Heller Florian, Mei├čner Pascal, Nguyen Trung, Yi Xie
autogenerated on Mon Jun 10 2019 12:40:38