demo-GetAxisActualAngle.cpp
Go to the documentation of this file.
1 //======================================================================
37 //======================================================================
38 
39 //----------------------------------------------------------------------
40 // System Includes - include with <>
41 //----------------------------------------------------------------------
42 
43 #include <getopt.h>
44 #include <assert.h>
45 
46 #include <iostream>
47 #include <vector>
48 
49 using namespace std;
50 
51 //----------------------------------------------------------------------
52 // Project Includes - include with ""
53 //---------------------------------------------------------------------
54 
55 #include "sdh/sdh.h"
56 #include "sdh/simpletime.h"
57 #include "sdh/util.h"
59 #include "sdh/basisdef.h"
60 #include "sdhoptions.h"
61 
62 //----------------------------------------------------------------------
63 // Defines, enums, unions, structs,
64 //----------------------------------------------------------------------
65 
67 
68 
69 //----------------------------------------------------------------------
70 // Global variables
71 //----------------------------------------------------------------------
72 
79 char const* __help__ =
81  "Print measured actual axis angles of SDH.\n"
82  "(C++ demo application using the SDHLibrary-CPP library.)\n"
83  "\n"
84  "- Example usage:\n"
85  " - Print actual angles of an SDH connected via Ethernet.\n"
86  " The SDH has IP-Address 192.168.1.42 and is attached to TCP port 23.\n"
87  " (Requires at least SDH-firmware v0.0.3.1)\n"
88  " > demo-GetAxisActualAngle --tcp=192.168.1.42:23\n"
89  " \n"
90  " - Print actual angles of an SDH connected to port 2 = COM3 once:\n"
91  " > demo-GetAxisActualAngle -p 2\n"
92  " \n"
93  " - Print actual angles of an SDH connected to port 2 = COM3 every 500ms:\n"
94  " > demo-GetAxisActualAngle -p 2 -t 0.5\n"
95  " \n"
96  " - Print actual angles of an SDH connected to USB to RS232 converter 0 once:\n"
97  " > demo-GetAxisActualAngle --sdh_rs_device=/dev/ttyUSB0 \n"
98  " \n"
99  " - Get the version info of both the joint controllers and the tactile \n"
100  " sensor firmware from an SDH connected via Ethernet.\n"
101  " The joint controllers and the tactile sensors have a common IP-Address,\n"
102  " here 192.168.1.42. The SDH controller is attached to the \n"
103  " default TCP port 23 and the tactile sensors to the default TCP port 13000.\n"
104  " (Requires at least SDH-firmware v0.0.3.2)\n"
105  " > demo-GetAxisActualAngle --tcp=192.168.1.42 --dsa_tcp -v\n"
106  " \n"
107  " - Get the version info of an SDH connected to port 2 = COM3 \n"
108  " > demo-GetAxisActualAngle --port=2 -v\n";
109 char const* __author__ = "Dirk Osswald: dirk.osswald@de.schunk.com";
110 char const* __url__ = "http://www.schunk.com";
111 char const* __version__ = "$Id: demo-GetAxisActualAngle.cpp 10351 2013-06-18 16:28:14Z Osswald2 $";
112 char const* __copyright__ = "Copyright (c) 2007 SCHUNK GmbH & Co. KG";
113 
114 // end of doxygen name group sdhlibrary_cpp_demo_getaxisactualangle_cpp_vars
115 // @}
116 
117 char const* usage =
118  "usage: demo-GetAxisActualAngle [options]\n"
119  ;
120 
121 
122 //----------------------------------------------------------------------
123 // Function and class member implementation (function definitions)
124 //----------------------------------------------------------------------
125 
126 
127 int main( int argc, char **argv )
128 {
130 
131  //---------------------
132  // handle command line options: set defaults first then overwrite by parsing actual command line
133  cSDHOptions options( SDHUSAGE_DEFAULT " sdhother" );
134 
135  options.Parse( argc, argv, __help__, "demo-GetAxisActualAngle", __version__, cSDH::GetLibraryName(), cSDH::GetLibraryRelease() );
136  //
137  //---------------------
138 
139  //---------------------
140  // initialize debug message printing:
141  cDBG cdbg( options.debug_level > 0, "red", options.debuglog );
142  g_sdh_debug_log = options.debuglog;
143 
144  cdbg << "Debug messages of " << argv[0] << " are printed like this.\n";
145 
146  // reduce debug level for subsystems
147  options.debug_level-=1;
148  //---------------------
149 
150  try
151  {
152  // cSDH instance "hand" of the class cSDH according to the given options:
153  cSDH hand( options.use_radians, options.use_fahrenheit, options.debug_level );
154  cdbg << "Successfully created cSDH instance\n";
155 
156  // Open configured communication to the SDH device
157  options.OpenCommunication( hand );
158  cdbg << "Successfully opened communication to SDH\n";
159 
160 
161  cdbg << "Caption:\n";
162  if (options.period)
163  cdbg << " times are reported in seconds\n";
164 
165  cdbg << " angles are reported in " << hand.uc_angle->GetName() << "[" << hand.uc_angle->GetSymbol() << "]\n";
166 
167 
168  //??? a second try block to catch keyboard interrupts
169  //try:
170 #if SDH_USE_VCC
171  double elapsed = 0.0;
172 #else
173  cSimpleTime start;
174 #endif
175 
176  while (true)
177  {
178  vector<double> angles = hand.GetAxisActualAngle( hand.all_axes );
179 
180  if (options.period > 0)
181  {
182  // print time only if reporting periodically
183 #if SDH_USE_VCC
184  cout << elapsed << " ";
185  elapsed += options.period;
186 #else
187  cout << start.Elapsed() << " ";
188 #endif
189  }
190 
191  for ( vector<double>::const_iterator ai = angles.begin();
192  ai != angles.end();
193  ai++ )
194  cout << *ai << " ";
195 
196  cout << "\n";
197  cout.flush();
198 
199  if (options.period <= 0)
200  break;
201 
202  SleepSec( options.period );
203  }
204 
205  hand.Close();
206  cdbg << "Successfully disabled controllers of SDH and closed connection\n";
207  }
208  catch ( cSDHLibraryException* e )
209  {
210  cerr << "demo-GetAxisActualAngle main(): Caught exception from SDHLibrary: " << e->what() << ". Giving up!\n";
211  delete e;
212  }
213  catch (...)
214  {
215  cerr << "caught unexpected exception!\n";
216  }
217 }
218 //----------------------------------------------------------------------
219 
220 
221 //======================================================================
222 /*
223  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
224  (e.g. to explicitely set C++ mode for *.h header files)
225 
226  Local Variables:
227  mode:C++
228  mode:ELSE
229  End:
230 */
231 //======================================================================
__version__
char const * __version__
Definition: demo-GetAxisActualAngle.cpp:111
__url__
char const * __url__
Definition: demo-GetAxisActualAngle.cpp:110
USING_NAMESPACE_SDH
#define USING_NAMESPACE_SDH
Definition: sdhlibrary_settings.h:81
cSDHLibraryException
Base class for exceptions in the SDHLibrary-CPP.
Definition: sdhexception.h:132
usage
char const * usage
Definition: demo-GetAxisActualAngle.cpp:117
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
cSDH::GetAxisActualAngle
std::vector< double > GetAxisActualAngle(std::vector< int > const &axes)
Definition: sdh.cpp:1270
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
__copyright__
char const * __copyright__
Definition: demo-GetAxisActualAngle.cpp:112
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
__author__
char const * __author__
Definition: demo-GetAxisActualAngle.cpp:109
cSDHOptions::period
double period
Definition: sdhoptions.h:105
cSDHOptions
class for command line option parsing holding option parsing results
Definition: sdhoptions.h:78
cSDH::all_axes
std::vector< int > all_axes
A vector with indices of all axes (in natural order), including the virtual axis.
Definition: sdh.h:517
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
basisdef.h
This file contains some basic definitions (defines, macros, datatypes)
main
int main(int argc, char **argv)
Definition: demo-GetAxisActualAngle.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
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
__help__
char const * __help__
Definition: demo-GetAxisActualAngle.cpp:80


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