demo-simple3.cpp
Go to the documentation of this file.
1 //======================================================================
42 //======================================================================
43 
44 #include <iostream>
45 #include <vector>
46 
47 
48 // Include the cSDH interface
49 #include "sdh/sdh.h"
50 #include "sdh/util.h"
52 #include "sdh/basisdef.h"
53 #include "sdhoptions.h"
54 
56 
63 char const* __help__ =
65  "Move axes 1,2 and 3 to a specific point.\n(C++ demo application using the SDHLibrary-CPP library.)\n"
66  "\n"
67  "- Example usage:\n"
68  " - Make SDH connected via Ethernet move.\n"
69  " The SDH has IP-Address 192.168.1.42 and is attached to TCP port 23.\n"
70  " (Requires at least SDH-firmware v0.0.3.1)\n"
71  " > demo-simple3 --tcp=192.168.1.42:23\n"
72  " \n"
73  " - Make SDH connected to port 2 = COM3 move:\n"
74  " > demo-simple3 -p 2\n"
75  " \n"
76  " - Make SDH connected to USB to RS232 converter 0 move:\n"
77  " > demo-simple3 --sdh_rs_device=/dev/ttyUSB0 \n"
78  " \n"
79  " - Get the version info of both the joint controllers and the tactile \n"
80  " sensor firmware from an SDH connected via Ethernet.\n"
81  " The joint controllers and the tactile sensors have a common IP-Address,\n"
82  " here 192.168.1.42. The SDH controller is attached to the \n"
83  " default TCP port 23 and the tactile sensors to the default TCP port 13000.\n"
84  " (Requires at least SDH-firmware v0.0.3.2)\n"
85  " > demo-simple3 --tcp=192.168.1.42 --dsa_tcp -v\n"
86  " \n"
87  " - Get the version info of an SDH connected to port 2 = COM3 \n"
88  " > demo-simple3 --port=2 -v\n";
89 char const* __author__ = "Dirk Osswald: dirk.osswald@de.schunk.com";
90 char const* __url__ = "http://www.schunk.com";
91 char const* __version__ = "$Id: demo-simple3.cpp 10351 2013-06-18 16:28:14Z Osswald2 $";
92 char const* __copyright__ = "Copyright (c) 2007 SCHUNK GmbH & Co. KG";
93 
94 // end of doxygen name group sdhlibrary_cpp_demo_simple3_cpp_vars
95 // @}
96 
97 
98 
99 int main( int argc, char** argv )
100 {
102 
103  //---------------------
104  // handle command line options: set defaults first then overwrite by parsing actual command line
105  cSDHOptions options;
106 
107  options.Parse( argc, argv, __help__, "demo-simple3", __version__, cSDH::GetLibraryName(), cSDH::GetLibraryRelease() );
108  //
109  //---------------------
110 
111  //---------------------
112  // initialize debug message printing:
113  cDBG cdbg( options.debug_level > 0, "red", options.debuglog );
114  g_sdh_debug_log = options.debuglog;
115 
116  cdbg << "Debug messages of " << argv[0] << " are printed like this.\n";
117 
118  // reduce debug level for subsystems
119  options.debug_level-=1;
120  //---------------------
121 
122  try
123  {
124  // Create an instance "hand" of the class cSDH:
125  cSDH hand( options.use_radians, options.use_fahrenheit, options.debug_level );
126  cdbg << "Successfully created cSDH instance\n";
127 
128  // Open configured communication to the SDH device
129  options.OpenCommunication( hand );
130  cdbg << "Successfully opened communication to SDH\n";
131 
132  // Switch to "pose" controller mode and set default velocities first:
133  hand.SetController( hand.eCT_POSE );
134  hand.SetAxisTargetVelocity( hand.All, 40.0 );
135 
136 
137  // Set a new target pose for axis 1,2 and 3
138  std::vector<int> axes123;
139  axes123.push_back( 1 );
140  axes123.push_back( 2 );
141  axes123.push_back( 3 );
142 
143  std::vector<double> angles123;
144  angles123.push_back( -20.0 );
145  angles123.push_back( -30.0 );
146  angles123.push_back( -40.0 );
147 
148  hand.SetAxisTargetAngle( axes123, angles123 );
149 
150  // Move axes there non sequentially:
151  hand.MoveAxis( axes123, false );
152 
153  // The last call returned immediately so we now have time to
154  // do something else while the hand is moving:
155 
156  // ... insert any calculation here ...
157 
158  std::cout << "waiting while moving to " << hand.GetAxisTargetAngle(hand.all_axes) << "\n"; std::cout.flush();
159  // Before doing something else with the hand make sure the
160  // selected axes have finished the last movement:
161  //
162  // \attention With SDH firmwares prior to 0.0.2.6 this did not work as expected!
163  // Hack: We have to wait a very short time to give the joint controller
164  // a chance to react and start moving.
165  // => Resolved with SDH firmware 0.0.2.6
166  //SleepSec(0.1); // no longer needed
167  hand.WaitAxis( axes123 );
168 
169 
170  // go back home (all angles to 0.0):
171  hand.SetAxisTargetAngle( hand.All, 0.0 );
172 
173  // Move all axes there non sequentially:
174  hand.MoveAxis( hand.All, false );
175 
176  // ... insert any other calculation here ...
177 
178  std::cout << "waiting while moving to " << hand.GetAxisTargetAngle(hand.all_axes) << "\n"; std::cout.flush();
179  // Wait until all axes are there, with a timeout of 10s:
180  //
181  // \attention With SDH firmwares prior to 0.0.2.6 this did not work as expected!
182  // Hack: We have to wait a very short time to give the joint controller
183  // a chance to react and start moving.
184  // => Resolved with SDH firmware 0.0.2.6
185  //SleepSec(0.1); // no longer needed
186  hand.WaitAxis( hand.All, 10.0 );
187 
188 
189  // Finally close connection to SDH again, this switches the axis controllers off
190  hand.Close();
191  }
192  catch (cSDHLibraryException* e)
193  {
194  std::cerr << "demo-simple3 main(): An exception was caught: " << e->what() << "\n";
195  delete e;
196  }
197 }
198 //----------------------------------------------------------------------
199 
200 
201 //======================================================================
202 /*
203  Here are some settings for the emacs/xemacs editor (and can be safely ignored)
204  (e.g. to explicitely set C++ mode for *.h header files)
205 
206  Local Variables:
207  mode:C++
208  mode:ELSE
209  End:
210 */
211 //======================================================================]
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
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
A class to print colored debug messages.
Definition: dbg.h:113
void WaitAxis(std::vector< int > const &axes, double timeout=-1.0)
Definition: sdh.cpp:1158
bool use_radians
Definition: sdhoptions.h:103
char const * __version__
virtual const char * what() const
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.
static char const * GetLibraryName(void)
Definition: sdh.cpp:633
coordinated position controller (position per axis => "pose controller"), all axes start and stop mov...
Definition: sdhbase.h:179
char const * __author__
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.
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
void SetAxisTargetAngle(std::vector< int > const &axes, std::vector< double > const &angles)
Definition: sdh.cpp:1209
#define USING_NAMESPACE_SDH
std::vector< double > GetAxisTargetAngle(std::vector< int > const &axes)
Definition: sdh.cpp:1251
char const * __copyright__
static char const * GetLibraryRelease(void)
Definition: sdh.cpp:626
double MoveAxis(std::vector< int >const &axes, bool sequ=true)
Definition: sdh.cpp:1898
This file contains settings to make the SDHLibrary compile on differen systems:
This file contains some basic definitions (defines, macros, datatypes)
int main(int argc, char **argv)
class for command line option parsing holding option parsing results
Definition: sdhoptions.h:78
char const * __url__
USING_NAMESPACE_SDH NAMESPACE_SDH_START std::ostream * g_sdh_debug_log
Definition: sdhbase.cpp:55
std::vector< int > all_axes
A vector with indices of all axes (in natural order), including the virtual axis. ...
Definition: sdh.h:517
char const * __help__
cDBG cdbg(false, "red")


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Mon Feb 28 2022 23:41:51