demo-simple-withtiming.cpp
Go to the documentation of this file.
1 //======================================================================
34 //======================================================================
35 
36 #include <iostream>
37 #include <vector>
38 
39 
40 // Include the cSDH interface
41 #include "sdh/sdh.h"
42 #include "sdh/util.h"
44 #include "sdh/basisdef.h"
45 #include "sdhoptions.h"
46 #include "sdh/simpletime.h"
47 #include "sdh/dbg.h"
48 
50 
57 char const* __help__ = "Move proximal and distal joints of finger 1 three times by 10 degrees and measure time for these actions.\n(C++ demo application using the SDHLibrary-CPP library.)";
58 char const* __author__ = "Dirk Osswald: dirk.osswald@de.schunk.com";
59 char const* __url__ = "http://www.schunk.com";
60 char const* __version__ = "$Id: demo-simple-withtiming.cpp 6265 2010-12-02 13:59:45Z Osswald2 $";
61 char const* __copyright__ = "Copyright (c) 2007 SCHUNK GmbH & Co. KG";
62 
63 // end of doxygen name group sdhlibrary_cpp_demo_simple_withtiming_cpp_vars
64 // @}
65 
66 char const* usage =
67  "usage: demo-simple-withtiming [options]\n"
68  ;
69 
70 
71 int main( int argc, char** argv )
72 {
74 
75  //---------------------
76  // handle command line options: set defaults first then overwrite by parsing actual command line
77  cSDHOptions options;
78 
79  options.Parse( argc, argv, __help__, "demo-simple-withtiming", __version__, cSDH::GetLibraryName(), cSDH::GetLibraryRelease() );
80  //
81  //---------------------
82 
83  //---------------------
84  // initialize debug message printing:
85  cDBG cdbg( options.debug_level > 0, "red", options.debuglog );
86  g_sdh_debug_log = options.debuglog;
87 
88  cdbg << "Debug messages of " << argv[0] << " are printed like this.\n";
89 
90  // reduce debug level for subsystems
91  options.debug_level-=1;
92  //---------------------
93 
94  int iFinger = 0; // The index of the finger to move
95 
96  try
97  {
98  // Create an instance "hand" of the class cSDH:
99  cSDH hand( options.use_radians, options.use_fahrenheit, options.debug_level );
100  cdbg << "Successfully created cSDH instance\n";
101 
102  // Open configured communication to the SDH device
103  options.OpenCommunication( hand );
104  cdbg << "Successfully opened communication to SDH\n";
105 
106  // Now perform some action:
107  // get the current actual axis angles of finger iFinger:
108  std::vector<double> faa = hand.GetFingerActualAngle( iFinger );
109 
110  // sometimes the actual angles are reported slightly out of range
111  // (Like -0.001 for axis 0 ). So limit the angles to the allowed range:
112  ToRange( faa, hand.GetFingerMinAngle( iFinger ), hand.GetFingerMaxAngle( iFinger ) );
113 
114  // modify faa by decrementing the proximal and the distal axis angles
115  // (make a copy fta of faa and modify that to keep actual pose available)
116  std::vector<double> fta = faa;
117 
118  std::vector<double> faa2;
119 
120  fta[1] -= 10.0;
121  fta[2] -= 10.0;
122 
123  // keep fta in range too:
124  ToRange( fta, hand.GetFingerMinAngle( iFinger ), hand.GetFingerMaxAngle( iFinger ) );
125 
126  std::cout << "Moving finger " << iFinger << " between faa=" << faa << " and fta=" << fta << "\n";
127 
128  cSimpleTime start;
129  double dt1, dt2, dt3, T;
130  // now move for 3 times between these two poses:
131  std::cout << "SetFingerTargetAngle\t";
132  std::cout << "GetFingerActualAngle\t";
133  std::cout << "MoveHand\t";
134  std::cout << "\n";
135  for (int i=0; i<20; i++ )
136  {
137  // set a new target angles
138  start.StoreNow();
139  hand.SetFingerTargetAngle( iFinger, fta );
140  hand.SetFingerTargetAngle( iFinger, fta );
141  hand.SetFingerTargetAngle( iFinger, fta );
142  hand.SetFingerTargetAngle( iFinger, fta );
143  hand.SetFingerTargetAngle( iFinger, fta );
144  dt1 = start.Elapsed() / 5.0;
145 
146  // get actual angles
147  start.StoreNow();
148  faa2 = hand.GetFingerActualAngle( iFinger );
149  faa2 = hand.GetFingerActualAngle( iFinger );
150  faa2 = hand.GetFingerActualAngle( iFinger );
151  faa2 = hand.GetFingerActualAngle( iFinger );
152  faa2 = hand.GetFingerActualAngle( iFinger );
153  dt2 = start.Elapsed() / 5.0;
154 
155  // and make the finger move there:
156  start.StoreNow();
157  T = hand.MoveHand( false );
158  dt3 = start.Elapsed();
159 
160  SleepSec( T );
161 
162  std::cout << dt1 << "\t" << dt2 << "\t" << dt3 << "\n";
163 
164  // set a new target angles
165  start.StoreNow();
166  hand.SetFingerTargetAngle( iFinger, faa );
167  hand.SetFingerTargetAngle( iFinger, faa );
168  hand.SetFingerTargetAngle( iFinger, faa );
169  hand.SetFingerTargetAngle( iFinger, faa );
170  hand.SetFingerTargetAngle( iFinger, faa );
171  dt1 = start.Elapsed() / 5.0;
172 
173  // get actual angles
174  start.StoreNow();
175  faa2 = hand.GetFingerActualAngle( iFinger );
176  faa2 = hand.GetFingerActualAngle( iFinger );
177  faa2 = hand.GetFingerActualAngle( iFinger );
178  faa2 = hand.GetFingerActualAngle( iFinger );
179  faa2 = hand.GetFingerActualAngle( iFinger );
180  dt2 = start.Elapsed() / 5.0;
181 
182  // and make the finger move there:
183  start.StoreNow();
184  T = hand.MoveHand( false );
185  dt3 = start.Elapsed();
186 
187  SleepSec( T );
188 
189  std::cout << dt1 << "\t" << dt2 << "\t" << dt3 << "\n";
190 
191  }
192 
193 
194  // Finally close connection to SDH again, this switches the axis controllers off
195  hand.Close();
196  }
197  catch (cSDHLibraryException* e)
198  {
199  std::cerr << "demo-simple-withtiming main(): An exception was caught: " << e->what() << "\n";
200  delete e;
201  }
202 }
203 //----------------------------------------------------------------------
204 
205 
206 //======================================================================
207 /*
208  Here are some settings for the emacs/xemacs editor (and can be safely ignored)
209  (e.g. to explicitely set C++ mode for *.h header files)
210 
211  Local Variables:
212  mode:C++
213  mode:ELSE
214  End:
215 */
216 //======================================================================]
#SDH::cSDH is the end user interface class to control a SDH (SCHUNK Dexterous Hand).
Definition: sdh.h:172
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
This file contains the interface to class #SDH::cSDH, the end user class to access the SDH from a PC...
bool use_fahrenheit
Definition: sdhoptions.h:104
#define SDH_ASSERT_TYPESIZES()
macro to assert that the defined typedefs have the expected sizes
Definition: basisdef.h:73
Interface of auxilliary utility functions for SDHLibrary-CPP.
void StoreNow(void)
Store current time internally.
Definition: simpletime.h:103
char const * __author__
void SetFingerTargetAngle(int iFinger, std::vector< double > const &angles)
Definition: sdh.cpp:1755
A class to print colored debug messages.
Definition: dbg.h:113
std::vector< double > GetFingerActualAngle(int iFinger)
Definition: sdh.cpp:1798
bool use_radians
Definition: sdhoptions.h:103
int main(int argc, char **argv)
double Elapsed(void) const
Return time in seconds elapsed between the time stored in the object and now.
Definition: simpletime.h:115
char const * __url__
std::ostream * debuglog
Definition: sdhoptions.h:86
int debug_level
Definition: sdhoptions.h:85
Implementation of a class to parse common SDH related command line options.
void SleepSec(double t)
Definition: util.cpp:155
static char const * GetLibraryRelease(void)
Definition: sdh.cpp:626
This file contains interface and implementation of class #SDH::cDBG, a class for colorfull debug mess...
std::vector< double > GetFingerMinAngle(int iFinger)
Definition: sdh.cpp:1819
cDBG cdbg(false,"red")
void OpenCommunication(NS_SDH cSDH &hand)
Definition: sdhoptions.cpp:865
char const * usage
Base class for exceptions in the SDHLibrary-CPP.
Definition: sdhexception.h:132
char const * __copyright__
Interface of auxilliary utility functions for SDHLibrary-CPP.
virtual const char * what() const
void Close(bool leave_enabled=false)
Definition: sdh.cpp:888
double ToRange(double v, double min, double max)
Definition: util.cpp:97
#define USING_NAMESPACE_SDH
char const * __version__
This file contains settings to make the SDHLibrary compile on differen systems:
Very simple class to measure elapsed time.
Definition: simpletime.h:84
char const * __help__
static char const * GetLibraryName(void)
Definition: sdh.cpp:633
double MoveHand(bool sequ=true)
Definition: sdh.cpp:2039
This file contains some basic definitions (defines, macros, datatypes)
class for command line option parsing holding option parsing results
Definition: sdhoptions.h:78
USING_NAMESPACE_SDH NAMESPACE_SDH_START std::ostream * g_sdh_debug_log
Definition: sdhbase.cpp:55
std::vector< double > GetFingerMaxAngle(int iFinger)
Definition: sdh.cpp:1840


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Sun Aug 18 2019 03:42:20