demo-simple.cpp
Go to the documentation of this file.
1 //======================================================================
45 //======================================================================
46 
47 #include <iostream>
48 #include <vector>
49 
50 
51 // Include the cSDH interface
52 #include "sdh/sdh.h"
53 #include "sdh/util.h"
55 #include "sdh/basisdef.h"
56 #include "sdhoptions.h"
57 
59 
66 char const* __help__ =
68  "Move proximal and distal joints of finger 1 three times by 10 degrees.\n"
69  "(C++ demo application using the SDHLibrary-CPP library.)\n"
70  "\n"
71  "- Example usage:\n"
72  " - Make SDH connected via Ethernet move.\n"
73  " The SDH has IP-Address 192.168.1.42 and is attached to TCP port 23.\n"
74  " (Requires at least SDH-firmware v0.0.3.1)\n"
75  " > demo-simple --tcp=192.168.1.42:23\n"
76  " \n"
77  " - Make SDH connected to port 2 = COM3 move:\n"
78  " > demo-simple -p 2\n"
79  " \n"
80  " - Make SDH connected to USB to RS232 converter 0 move:\n"
81  " > demo-simple --sdh_rs_device=/dev/ttyUSB0 \n"
82  " \n"
83  " - Get the version info of both the joint controllers and the tactile \n"
84  " sensor firmware from an SDH connected via Ethernet.\n"
85  " The joint controllers and the tactile sensors have a common IP-Address,\n"
86  " here 192.168.1.42. The SDH controller is attached to the \n"
87  " default TCP port 23 and the tactile sensors to the default TCP port 13000.\n"
88  " (Requires at least SDH-firmware v0.0.3.2)\n"
89  " > demo-simple --tcp=192.168.1.42 --dsa_tcp -v\n"
90  " \n"
91  " - Get the version info of an SDH connected to port 2 = COM3 \n"
92  " > demo-simple --port=2 -v\n";
93 char const* __author__ = "Dirk Osswald: dirk.osswald@de.schunk.com";
94 char const* __url__ = "http://www.schunk.com";
95 char const* __version__ = "$Id: demo-simple.cpp 11045 2013-11-27 15:12:49Z Osswald2 $";
96 char const* __copyright__ = "Copyright (c) 2007 SCHUNK GmbH & Co. KG";
97 
98 // end of doxygen name group sdhlibrary_cpp_demo_simple_cpp_vars
99 // @}
100 
101 char const* usage =
102  "usage: demo-simple [options]\n"
103  ;
104 
105 
106 int main( int argc, char** argv )
107 {
109 
110  //---------------------
111  // handle command line options: set defaults first then overwrite by parsing actual command line
112  cSDHOptions options;
113 
114  options.Parse( argc, argv, __help__, "demo-simple", __version__, cSDH::GetLibraryName(), cSDH::GetLibraryRelease() );
115  //
116  //---------------------
117 
118  //---------------------
119  // initialize debug message printing:
120  cDBG cdbg( options.debug_level > 0, "red", options.debuglog );
121  g_sdh_debug_log = options.debuglog;
122 
123  cdbg << "Debug messages of " << argv[0] << " are printed like this.\n";
124 
125  // reduce debug level for subsystems
126  options.debug_level-=1;
127  //---------------------
128 
129  int iFinger = 0; // The index of the finger to move
130 
131  try
132  {
133  // Create an instance "hand" of the class cSDH:
134  cSDH hand( false, options.use_fahrenheit, options.debug_level );
135  cdbg << "Successfully created cSDH instance\n";
136 
137  // Open configured communication to the SDH device
138  options.OpenCommunication( hand );
139  cdbg << "Successfully opened communication to SDH\n";
140 
141  // Switch to "pose" controller mode and set default velocities first:
142  hand.SetController( hand.eCT_POSE );
143  hand.SetAxisTargetVelocity( hand.All, 40.0 );
144 
145  // Now perform some action:
146  // get the current actual axis angles of finger iFinger:
147  std::vector<double> faa = hand.GetFingerActualAngle( iFinger );
148 
149  // sometimes the actual angles are reported slightly out of range
150  // (Like -0.001 for axis 0 ). So limit the angles to the allowed range:
151  ToRange( faa, hand.GetFingerMinAngle( iFinger ), hand.GetFingerMaxAngle( iFinger ) );
152 
153  // modify faa by decrementing the proximal and the distal axis angles
154  // (make a copy fta of faa and modify that to keep actual pose available)
155  std::vector<double> fta = faa;
156 
157  fta[1] -= 10.0;
158  fta[2] -= 10.0;
159 
160  // keep fta in range too:
161  ToRange( fta, hand.GetFingerMinAngle( iFinger ), hand.GetFingerMaxAngle( iFinger ) );
162 
163  std::cout << "Moving finger " << iFinger << " between faa=" << faa << " and fta=" << fta << "\n";
164 
165  // now move for 3 times between these two poses:
166  for (int i=0; i<3; i++ )
167  {
168  // set a new target angles
169  hand.SetFingerTargetAngle( iFinger, fta );
170 
171  // and make the finger move there:
172  hand.MoveFinger( iFinger );
173 
174 
175  // set a new target angles
176  hand.SetFingerTargetAngle( iFinger, faa );
177 
178  // and make the finger move there:
179  hand.MoveFinger( iFinger );
180 
181  }
182 
183 
184  // Finally close connection to SDH again, this switches the axis controllers off
185  hand.Close();
186  }
187  catch (cSDHLibraryException* e)
188  {
189  std::cerr << "demo-simple main(): An exception was caught: " << e->what() << "\n";
190  delete e;
191  }
192 }
193 //----------------------------------------------------------------------
194 
195 
196 //======================================================================
197 /*
198  Here are some settings for the emacs/xemacs editor (and can be safely ignored)
199  (e.g. to explicitely set C++ mode for *.h header files)
200 
201  Local Variables:
202  mode:C++
203  mode:ELSE
204  End:
205 */
206 //======================================================================]
A meta-value that means "access all possible values".
Definition: sdhbase.h:103
#SDH::cSDH is the end user interface class to control a SDH (SCHUNK Dexterous Hand).
Definition: sdh.h:172
char const * __copyright__
Definition: demo-simple.cpp:96
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
char const * __help__
Definition: demo-simple.cpp:67
void SetFingerTargetAngle(int iFinger, std::vector< double > const &angles)
Definition: sdh.cpp:1755
A class to print colored debug messages.
Definition: dbg.h:113
int main(int argc, char **argv)
std::vector< double > GetFingerActualAngle(int iFinger)
Definition: sdh.cpp:1798
char const * usage
char const * __url__
Definition: demo-simple.cpp:94
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.
double MoveFinger(std::vector< int >const &fingers, bool sequ=true)
Definition: sdh.cpp:1967
static char const * GetLibraryRelease(void)
Definition: sdh.cpp:626
std::vector< double > GetFingerMinAngle(int iFinger)
Definition: sdh.cpp:1819
coordinated position controller (position per axis => "pose controller"), all axes start and stop mov...
Definition: sdhbase.h:179
cDBG cdbg(false,"red")
void OpenCommunication(NS_SDH cSDH &hand)
Definition: sdhoptions.cpp:865
Base class for exceptions in the SDHLibrary-CPP.
Definition: sdhexception.h:132
void SetController(cSDHBase::eControllerType controller)
Definition: sdh.cpp:946
Interface of auxilliary utility functions for SDHLibrary-CPP.
virtual const char * what() const
void Close(bool leave_enabled=false)
Definition: sdh.cpp:888
void SetAxisTargetVelocity(std::vector< int > const &axes, std::vector< double > const &velocities)
Definition: sdh.cpp:1289
double ToRange(double v, double min, double max)
Definition: util.cpp:97
#define USING_NAMESPACE_SDH
char const * __author__
Definition: demo-simple.cpp:93
This file contains settings to make the SDHLibrary compile on differen systems:
static char const * GetLibraryName(void)
Definition: sdh.cpp:633
This file contains some basic definitions (defines, macros, datatypes)
class for command line option parsing holding option parsing results
Definition: sdhoptions.h:78
char const * __version__
Definition: demo-simple.cpp:95
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