demo-GetFingerXYZ.cpp
Go to the documentation of this file.
1 //======================================================================
41 //======================================================================
42 
43 //----------------------------------------------------------------------
44 // System Includes - include with <>
45 //----------------------------------------------------------------------
46 
47 #include <getopt.h>
48 #include <assert.h>
49 
50 #include <iostream>
51 #include <vector>
52 
53 using namespace std;
54 
55 //----------------------------------------------------------------------
56 // Project Includes - include with ""
57 //---------------------------------------------------------------------
58 
59 #include "sdh/sdh.h"
60 #include "sdh/simpletime.h"
61 #include "sdh/util.h"
63 #include "sdh/basisdef.h"
64 #include "sdhoptions.h"
65 
66 //----------------------------------------------------------------------
67 // Defines, enums, unions, structs,
68 //----------------------------------------------------------------------
69 
71 
72 
73 //----------------------------------------------------------------------
74 // Global variables
75 //----------------------------------------------------------------------
76 
83 char const* __help__ =
85  "Print measured XYZ position of fingertips of SDH.\n"
86  "C++ demo application using the SDHLibrary-CPP library.)\n"
87  "\n"
88  "For every finger the actual axis angles and the finger tip coordinates\n"
89  "are printed.\n"
90  "\n"
91  "- Example usage:\n"
92  " - Print finger angles and finger tip xyz coordinates of an SDH connected\n"
93  " via Ethernet. The SDH has IP-Address 192.168.1.42 and is attached to TCP\n"
94  " port 23. \n"
95  " (Requires at least SDH-firmware v0.0.3.1)\n"
96  " > demo-GetFingerXYZ --tcp=192.168.1.42:23\n"
97  " \n"
98  " - Print finger angles and finger tip xyz coordinates of an SDH connected\n"
99  " to port 2 = COM3 once:\n"
100  " > demo-GetFingerXYZ -p 2\n"
101  " \n"
102  " - Print finger angles and finger tip xyz coordinates of an SDH connected\n"
103  " to port 2 = COM3 every 500ms:\n"
104  " > demo-GetFingerXYZ -p 2 -t 0.5\n"
105  " \n"
106  " - Print finger angles and finger tip xyz coordinates of an SDH connected\n"
107  " to USB to RS232 converter 0 once:\n"
108  " > demo-GetFingerXYZ --sdh_rs_device=/dev/ttyUSB0 \n"
109  " \n"
110  " - Get the version info of both the joint controllers and the tactile \n"
111  " sensor firmware from an SDH connected via Ethernet.\n"
112  " The joint controllers and the tactile sensors have a common IP-Address,\n"
113  " here 192.168.1.42. The SDH controller is attached to the \n"
114  " default TCP port 23 and the tactile sensors to the default TCP port 13000.\n"
115  " (Requires at least SDH-firmware v0.0.3.2)\n"
116  " > demo-GetFingerXYZ --tcp=192.168.1.42 --dsa_tcp -v\n"
117  " \n"
118  " - Get the version info of an SDH connected to port 2 = COM3 \n"
119  " > demo-GetFingerXYZ --port=2 -v\n"
120  "- Known bugs:\n"
121  " - Command line parameter \"-R\" does not work when compiled \n"
122  " with MS Visual Studio\n"
123  ;
124 char const* __author__ = "Dirk Osswald: dirk.osswald@de.schunk.com";
125 char const* __url__ = "http://www.schunk.com";
126 char const* __version__ = "$Id: demo-GetFingerXYZ.cpp 10351 2013-06-18 16:28:14Z Osswald2 $";
127 char const* __copyright__ = "Copyright (c) 2007 SCHUNK GmbH & Co. KG";
128 
129 // end of doxygen name group sdhlibrary_cpp_demo_getfingerxyz_cpp_vars
130 // @}
131 
132 char const* usage =
133  "usage: demo-GetFingerXYZ [options]\n"
134  ;
135 
136 
137 //----------------------------------------------------------------------
138 // Function and class member implementation (function definitions)
139 //----------------------------------------------------------------------
140 
141 
142 int main( int argc, char **argv )
143 {
145 
146  //---------------------
147  // handle command line options: set defaults first then overwrite by parsing actual command line
148  cSDHOptions options( SDHUSAGE_DEFAULT " sdhother" );
149 
150  options.Parse( argc, argv, __help__, "demo-GetFingerXYZ", __version__, cSDH::GetLibraryName(), cSDH::GetLibraryRelease() );
151 
152  //
153  //---------------------
154 
155  //---------------------
156  // initialize debug message printing:
157  cDBG cdbg( options.debug_level > 0, "red", options.debuglog );
158  g_sdh_debug_log = options.debuglog;
159 
160  cdbg << "Debug messages of " << argv[0] << " are printed like this.\n";
161 
162  // reduce debug level for subsystems
163  options.debug_level-=1;
164  //---------------------
165 
166  try
167  {
168  // cSDH instance "hand" of the class cSDH according to the given options:
169  cSDH hand( options.use_radians, options.use_fahrenheit, options.debug_level );
170  cdbg << "Successfully created cSDH instance\n";
171 
172  // Open configured communication to the SDH device
173  options.OpenCommunication( hand );
174  cdbg << "Successfully opened communication to SDH\n";
175 
176 
177  cdbg << "Caption:\n";
178  if (options.period)
179  cdbg << " times are reported in seconds\n";
180 
181  cdbg << " angles are reported in " << hand.uc_angle->GetName() << "[" << hand.uc_angle->GetSymbol() << "]\n";
182 
183 
184  //??? a second try block to catch keyboard interrupts
185  //try:
186  cSimpleTime start;
187 
188  vector<double> angles;
189  vector<double> xyz;
190  vector<double>::const_iterator i;
191  while (true)
192  {
193  for ( int fi = 0; fi < hand.GetNumberOfFingers(); fi++ )
194  {
195  angles = hand.GetFingerActualAngle( fi );
196  xyz = hand.GetFingerXYZ( fi, angles );
197 
198  if (options.period > 0)
199  {
200  // print time only if reporting periodically
201  cout << start.Elapsed() << " ";
202  }
203 
204  cout << "finger " << fi << ": ";
205  cout << "angles = ";
206  cout.setf(ios::fixed);
207  cout.precision(1);
208  for ( i = angles.begin(); i != angles.end(); i++ )
209  cout << setw(6) << *i << " ";
210 
211  cout << " XYZ = " ;
212  for ( i = xyz.begin(); i != xyz.end(); i++ )
213  cout << setw(6) << *i << " ";
214 
215  cout << "\n";
216  }
217  if (options.period <= 0)
218  break;
219 
220  cout << "\n";
221  cout.flush();
222  SleepSec( options.period );
223  }
224 
225  hand.Close();
226  cdbg << "Successfully disabled controllers of SDH and closed connection\n";
227  }
228  catch ( cSDHLibraryException* e )
229  {
230  cerr << "demo-GetFingerXYZ main(): Caught exception from SDHLibrary: " << e->what() << ". Giving up!\n";
231  delete e;
232  }
233  catch (...)
234  {
235  cerr << "caught unexpected exception!\n";
236  }
237 }
238 //----------------------------------------------------------------------
239 
240 
241 //======================================================================
242 /*
243  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
244  (e.g. to explicitely set C++ mode for *.h header files)
245 
246  Local Variables:
247  mode:C++
248  mode:ELSE
249  End:
250 */
251 //======================================================================
USING_NAMESPACE_SDH
#define USING_NAMESPACE_SDH
Definition: sdhlibrary_settings.h:81
__author__
char const * __author__
Definition: demo-GetFingerXYZ.cpp:124
cSDHLibraryException
Base class for exceptions in the SDHLibrary-CPP.
Definition: sdhexception.h:132
cSimpleTime
Very simple class to measure elapsed time.
Definition: simpletime.h:84
cUnitConverter::GetSymbol
char const * GetSymbol(void) const
Return the symbol of the external unit (something like "deg" or "ms")
Definition: unit_converter.cpp:168
getopt.h
cSDH::uc_angle
const cUnitConverter * uc_angle
unit convert for (axis) angles: default = #SDH::cSDH::uc_angle_degrees
Definition: sdh.h:558
cSimpleTime::Elapsed
double Elapsed(void) const
Return time in seconds elapsed between the time stored in the object and now.
Definition: simpletime.h:115
sdhoptions.h
Implementation of a class to parse common SDH related command line options.
cSDHOptions::use_fahrenheit
bool use_fahrenheit
Definition: sdhoptions.h:104
cSDHOptions::use_radians
bool use_radians
Definition: sdhoptions.h:103
cSDHBase::GetNumberOfFingers
int GetNumberOfFingers(void)
Return the number of fingers of the SDH.
Definition: sdhbase.cpp:233
cSDHOptions::debuglog
std::ostream * debuglog
Definition: sdhoptions.h:86
cSDHOptions::OpenCommunication
void OpenCommunication(NS_SDH cSDH &hand)
Definition: sdhoptions.cpp:865
cSDHOptions::debug_level
int debug_level
Definition: sdhoptions.h:85
cSDH::GetLibraryRelease
static char const * GetLibraryRelease(void)
Definition: sdh.cpp:626
SleepSec
void SleepSec(double t)
Definition: util.cpp:155
main
int main(int argc, char **argv)
Definition: demo-GetFingerXYZ.cpp:142
cSDH::GetFingerXYZ
std::vector< double > GetFingerXYZ(int iFinger, std::vector< double > const &angles)
Definition: sdh.cpp:1861
usage
char const * usage
Definition: demo-GetFingerXYZ.cpp:132
cSDHOptions::period
double period
Definition: sdhoptions.h:105
cSDHOptions
class for command line option parsing holding option parsing results
Definition: sdhoptions.h:78
__url__
char const * __url__
Definition: demo-GetFingerXYZ.cpp:125
cSDH
#SDH::cSDH is the end user interface class to control a SDH (SCHUNK Dexterous Hand).
Definition: sdh.h:172
cDBG
A class to print colored debug messages.
Definition: dbg.h:113
cdbg
cDBG cdbg(false, "red")
SDHUSAGE_DEFAULT
#define SDHUSAGE_DEFAULT
Definition: sdhoptions.h:64
cSDH::GetFingerActualAngle
std::vector< double > GetFingerActualAngle(int iFinger)
Definition: sdh.cpp:1798
__help__
char const * __help__
Definition: demo-GetFingerXYZ.cpp:84
basisdef.h
This file contains some basic definitions (defines, macros, datatypes)
__copyright__
char const * __copyright__
Definition: demo-GetFingerXYZ.cpp:127
simpletime.h
Interface of auxilliary utility functions for SDHLibrary-CPP.
sdhlibrary_settings.h
This file contains settings to make the SDHLibrary compile on differen systems:
cSDH::GetLibraryName
static char const * GetLibraryName(void)
Definition: sdh.cpp:633
cUnitConverter::GetName
char const * GetName(void) const
Return the name of the external unit (something like "degrees" or "milliseconds")
Definition: unit_converter.cpp:161
g_sdh_debug_log
USING_NAMESPACE_SDH NAMESPACE_SDH_START std::ostream * g_sdh_debug_log
Definition: sdhbase.cpp:55
sdh.h
This file contains the interface to class #SDH::cSDH, the end user class to access the SDH from a PC.
cSDHLibraryException::what
virtual const char * what() const
Definition: sdhexception.cpp:118
cSDHOptions::Parse
int Parse(int argc, char **argv, char const *helptext, char const *progname, char const *version, char const *libname, char const *librelease)
Definition: sdhoptions.cpp:464
__version__
char const * __version__
Definition: demo-GetFingerXYZ.cpp:126
cSDH::Close
void Close(bool leave_enabled=false)
Definition: sdh.cpp:888
util.h
Interface of auxilliary utility functions for SDHLibrary-CPP.
SDH_ASSERT_TYPESIZES
#define SDH_ASSERT_TYPESIZES()
macro to assert that the defined typedefs have the expected sizes
Definition: basisdef.h:73


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Wed Mar 2 2022 01:00:58