demo-griphand.cpp
Go to the documentation of this file.
1 //======================================================================
39 //======================================================================
40 
41 #include <iostream>
42 #include <vector>
43 
44 
45 // Include the cSDH interface
46 #include "sdh/sdh.h"
47 #include "sdh/util.h"
49 #include "sdh/basisdef.h"
50 #include "sdhoptions.h"
51 
53 
60 char const* __help__ =
62  "Demonstrate the use of the GripHand command.\n"
63  "(C++ demo application using the SDHLibrary-CPP library.)\n"
64  "\n"
65  "- Example usage:\n"
66  " - Make SDH connected via Ethernet move.\n"
67  " The SDH has IP-Address 192.168.1.42 and is attached to TCP port 23.\n"
68  " (Requires at least SDH-firmware v0.0.3.1)\n"
69  " > demo-griphand --tcp=192.168.1.42:23\n"
70  " \n"
71  " - Make SDH connected to port 2 = COM3 move:\n"
72  " > demo-griphand -p 2\n"
73  " \n"
74  " - Make SDH connected to USB to RS232 converter 0 move:\n"
75  " > demo-griphand --sdh_rs_device=/dev/ttyUSB0 \n"
76  " \n"
77  " - Get the version info of both the joint controllers and the tactile \n"
78  " sensor firmware from an SDH connected via Ethernet.\n"
79  " The joint controllers and the tactile sensors have a common IP-Address,\n"
80  " here 192.168.1.42. The SDH controller is attached to the \n"
81  " default TCP port 23 and the tactile sensors to the default TCP port 13000.\n"
82  " (Requires at least SDH-firmware v0.0.3.2)\n"
83  " > demo-griphand --tcp=192.168.1.42 --dsa_tcp -v\n"
84  " \n"
85  " - Get the version info of an SDH connected to port 2 = COM3 \n"
86  " > demo-griphand --port=2 -v\n";
87 char const* __author__ = "Dirk Osswald: dirk.osswald@de.schunk.com";
88 char const* __url__ = "http://www.schunk.com";
89 char const* __version__ = "$Id: demo-griphand.cpp 10351 2013-06-18 16:28:14Z Osswald2 $";
90 char const* __copyright__ = "Copyright (c) 2007 SCHUNK GmbH & Co. KG";
91 
92 // end of doxygen name group sdhlibrary_cpp_demo_griphand_cpp_vars
93 // @}
94 
95 char const* usage =
96  "usage: demo-griphand [options]\n"
97  ;
98 
99 
100 int main( int argc, char** argv )
101 {
103 
104  //---------------------
105  // handle command line options: set defaults first then overwrite by parsing actual command line
106  cSDHOptions options;
107 
108  options.Parse( argc, argv, __help__, "demo-griphand", __version__, cSDH::GetLibraryName(), cSDH::GetLibraryRelease() );
109  //
110  //---------------------
111 
112  //---------------------
113  // initialize debug message printing:
114  cDBG cdbg( options.debug_level > 0, "red", options.debuglog );
115  g_sdh_debug_log = options.debuglog;
116 
117  cdbg << "Debug messages of " << argv[0] << " are printed like this.\n";
118 
119  // reduce debug level for subsystems
120  options.debug_level-=1;
121  //---------------------
122 
123  try
124  {
125  // Create an instance "hand" of the class cSDH:
126  cSDH hand( options.use_radians, options.use_fahrenheit, options.debug_level );
127  cdbg << "Successfully created cSDH instance\n";
128 
129  // Open configured communication to the SDH device
130  options.OpenCommunication( hand );
131  cdbg << "Successfully opened communication to SDH\n";
132 
133  // Switch to "pose" controller mode and set default velocities first:
134  hand.SetController( hand.eCT_POSE );
135 
136  cSDH::eGraspId grasp_id = cSDH::eGID_CENTRICAL; // start with first valid grasp
137  double close_ratio;
138  double velocity = 40.0;
139 
140  while ( grasp_id < cSDH::eGID_DIMENSION )
141  {
142  // remark: the std::cout.flush() is needed to make the output appear in time
143  // when compiled with VCC
144  std::cout << "Performing GripHand() for grasp " << int(grasp_id) << "=\"" << hand.GetStringFromGraspId( grasp_id ) << "\"\n"; std::cout.flush();
145 
146  close_ratio = 0.0;
147  std::cout << " close_ratio = 0.0 (fully open)..."; std::cout.flush();
148  hand.GripHand( grasp_id, close_ratio, velocity, true );
149  std::cout << " finished\n"; std::cout.flush();
150  SleepSec( 1.0 );
151 
152  close_ratio = 0.5;
153  std::cout << " close_ratio = 0.5 (half closed)..."; std::cout.flush();
154  hand.GripHand( grasp_id, close_ratio, velocity, true );
155  std::cout << " finished\n"; std::cout.flush();
156  SleepSec( 1.0 );
157 
158  close_ratio = 1.0;
159  std::cout << " close_ratio = 1.0 (fully closed)..."; std::cout.flush();
160  hand.GripHand( grasp_id, close_ratio, velocity, true );
161  std::cout << " finished\n"; std::cout.flush();
162  SleepSec( 1.0 );
163 
164 
165  close_ratio = 0.0;
166  std::cout << " reopening..."; std::cout.flush();
167  hand.GripHand( grasp_id, close_ratio, velocity, true );
168  std::cout << " finished\n"; std::cout.flush();
169 
170  grasp_id = (cSDH::eGraspId)( grasp_id + 1 );
171  }
172 
173  // Finally close connection to SDH again, this switches the axis controllers off
174  hand.Close();
175  }
176  catch (cSDHLibraryException* e)
177  {
178  std::cerr << "demo-griphand main(): An exception was caught: " << e->what() << "\n";
179  delete e;
180  }
181 }
182 //----------------------------------------------------------------------
183 
184 
185 //======================================================================
186 /*
187  Here are some settings for the emacs/xemacs editor (and can be safely ignored)
188  (e.g. to explicitely set C++ mode for *.h header files)
189 
190  Local Variables:
191  mode:C++
192  mode:ELSE
193  End:
194 */
195 //======================================================================]
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
cSDHBase::eGID_DIMENSION
@ eGID_DIMENSION
Endmarker and dimension.
Definition: sdhbase.h:171
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
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
cSDHBase::eCT_POSE
@ eCT_POSE
coordinated position controller (position per axis => "pose controller"), all axes start and stop mov...
Definition: sdhbase.h:179
SleepSec
void SleepSec(double t)
Definition: util.cpp:155
__url__
char const * __url__
Definition: demo-griphand.cpp:88
cSDHOptions
class for command line option parsing holding option parsing results
Definition: sdhoptions.h:78
__help__
char const * __help__
Definition: demo-griphand.cpp:61
__author__
char const * __author__
Definition: demo-griphand.cpp:87
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")
basisdef.h
This file contains some basic definitions (defines, macros, datatypes)
__copyright__
char const * __copyright__
Definition: demo-griphand.cpp:90
cSDHBase::eGID_CENTRICAL
@ eGID_CENTRICAL
centrical grasp: ???
Definition: sdhbase.h:166
usage
char const * usage
Definition: demo-griphand.cpp:95
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
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
__version__
char const * __version__
Definition: demo-griphand.cpp:89
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
main
int main(int argc, char **argv)
Definition: demo-griphand.cpp:100
cSDH::SetController
void SetController(cSDHBase::eControllerType controller)
Definition: sdh.cpp:946
cSDHBase::eGraspId
eGraspId
The enum values of the known grasps.
Definition: sdhbase.h:162
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
cSDH::GripHand
double GripHand(eGraspId grip, double close, double velocity, bool sequ=true)
Definition: sdh.cpp:2053
cSDHBase::GetStringFromGraspId
static char const * GetStringFromGraspId(eGraspId grasp_id)
Return a ptr to a (static) string describing grasp id grasp_id.
Definition: sdhbase.cpp:206


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