demo-simple2.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 proximal and distal joints of finger 1 three times by 10 degrees, stop movement when halfway done.\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-simple2 --tcp=192.168.1.42:23\n"
72  " \n"
73  " - Make SDH connected to port 2 = COM3 move:\n"
74  " > demo-simple2 -p 2\n"
75  " \n"
76  " - Make SDH connected to USB to RS232 converter 0 move:\n"
77  " > demo-simple2 --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-simple2 --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-simple2 --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-simple2.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_simple2_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-simple2", __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  int iFinger = 0; // The index of the finger to move
123 
124  try
125  {
126  // Create an instance "hand" of the class cSDH:
127  cSDH hand( options.use_radians, options.use_fahrenheit, options.debug_level );
128  cdbg << "Successfully created cSDH instance\n";
129 
130  // Open configured communication to the SDH device
131  options.OpenCommunication( hand );
132  cdbg << "Successfully opened communication to SDH\n";
133 
134  // Switch to "pose" controller mode and set default velocities first:
135  hand.SetController( hand.eCT_POSE );
136  hand.SetAxisTargetVelocity( hand.All, 40.0 );
137 
138  // save current velocity profile and set velocity profile to ramp
139  cSDH::eVelocityProfile old_profile = hand.GetVelocityProfile();
141 
142  // Now perform some action:
143  // get the current actual axis angles of finger iFinger:
144  std::vector<double> faa = hand.GetFingerActualAngle( iFinger );
145 
146  // sometimes the actual angles are reported slightly out of range
147  // (Like -0.001 for axis 0 ). So limit the angles to the allowed range:
148  ToRange( faa, hand.GetFingerMinAngle( iFinger ), hand.GetFingerMaxAngle( iFinger ) );
149 
150 
151  // modify faa by decrementing the proximal and the distal axis angles
152  // (make a copy fta of faa and modify that to keep actual pose available)
153  std::vector<double> fta = faa;
154 
155  fta[1] -= 40.0;
156  fta[2] -= 40.0;
157 
158  // keep fta in range too:
159  ToRange( fta, hand.GetFingerMinAngle( iFinger ), hand.GetFingerMaxAngle( iFinger ) );
160 
161  std::cout << "Moving finger " << iFinger << " between faa=" << faa << " and fta=" << fta << "\n";
162 
163  // now move for 3 times between these two poses:
164  for (int i=0; i<3; i++ )
165  {
166  // set a new target angles
167  hand.SetFingerTargetAngle( iFinger, fta );
168 
169  // and make the finger move there, but call non-sequentially (i.e. return immediately):
170  double t = hand.MoveFinger( iFinger, false );
171  // The last call returned immediately, the finger is now moving for t seconds
172 
173  // So wait until that movement is half finished:
174  SleepSec( t/2 );
175 
176  // Then stop the finger in the middle of the movement:
177  // (necessary for velocity profile "sin square" not for "ramp"
178  hand.Stop();
179  std::cout << "Stopped at:" << hand.GetFingerActualAngle(iFinger) << "\n";
180 
181 
182  // set a new target angles
183  hand.SetFingerTargetAngle( iFinger, faa );
184 
185  // and make the finger move there:
186  hand.MoveFinger( iFinger );
187 
188  }
189 
190  // restore previous velocity profile
191  hand.SetVelocityProfile( old_profile );
192 
193  // Finally close connection to SDH again, this switches the axis controllers off
194  hand.Close();
195  }
196  catch (cSDHLibraryException* e)
197  {
198  std::cerr << "demo-simple2 main(): An exception was caught: " << e->what() << "\n";
199  delete e;
200  }
201 }
202 //----------------------------------------------------------------------
203 
204 
205 //======================================================================
206 /*
207  Here are some settings for the emacs/xemacs editor (and can be safely ignored)
208  (e.g. to explicitely set C++ mode for *.h header files)
209 
210  Local Variables:
211  mode:C++
212  mode:ELSE
213  End:
214 */
215 //======================================================================]
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
void SetVelocityProfile(eVelocityProfile velocity_profile)
Definition: sdh.cpp:986
void SetFingerTargetAngle(int iFinger, std::vector< double > const &angles)
Definition: sdh.cpp:1755
A class to print colored debug messages.
Definition: dbg.h:113
ramp velocity profile
Definition: sdhbase.h:195
std::vector< double > GetFingerActualAngle(int iFinger)
Definition: sdh.cpp:1798
bool use_radians
Definition: sdhoptions.h:103
void Stop(void)
Definition: sdh.cpp:939
std::ostream * debuglog
Definition: sdhoptions.h:86
char const * __version__
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
void SleepSec(double t)
Definition: util.cpp:155
eVelocityProfile
An enum for all possible SDH internal velocity profile types.
Definition: sdhbase.h:191
static char const * GetLibraryRelease(void)
Definition: sdh.cpp:626
std::vector< double > GetFingerMinAngle(int iFinger)
Definition: sdh.cpp:1819
eVelocityProfile GetVelocityProfile(void)
Definition: sdh.cpp:993
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
char const * __author__
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 * __copyright__
This file contains settings to make the SDHLibrary compile on differen systems:
static char const * GetLibraryName(void)
Definition: sdh.cpp:633
char const * __url__
This file contains some basic definitions (defines, macros, datatypes)
class for command line option parsing holding option parsing results
Definition: sdhoptions.h:78
int main(int argc, char **argv)
USING_NAMESPACE_SDH NAMESPACE_SDH_START std::ostream * g_sdh_debug_log
Definition: sdhbase.cpp:55
char const * __help__
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