demo-temperature.cpp
Go to the documentation of this file.
1 //======================================================================
37 //======================================================================
38 
39 //----------------------------------------------------------------------
40 // System Includes - include with <>
41 //----------------------------------------------------------------------
42 
43 #include <getopt.h>
44 #include <assert.h>
45 
46 #include <iostream>
47 #include <vector>
48 
49 using namespace std;
50 
51 //----------------------------------------------------------------------
52 // Project Includes - include with ""
53 //---------------------------------------------------------------------
54 
55 #include "sdh/sdh.h"
56 #include "sdh/simpletime.h"
57 #include "sdh/util.h"
59 #include "sdh/basisdef.h"
60 #include "sdhoptions.h"
61 
63 
64 //----------------------------------------------------------------------
65 // Defines, enums, unions, structs,
66 //----------------------------------------------------------------------
67 
68 
69 //----------------------------------------------------------------------
70 // Global variables
71 //----------------------------------------------------------------------
72 
79 char const* __help__ =
81  "Print measured temperatures of SDH.\n"
82  "(C++ demo application using the SDHLibrary-CPP library.)\n"
83  "\n"
84  "A vector of temperatures is reported. The first 7 temperatures\n"
85  "are from sensors close to the corresponding axes motors.\n"
86  "The 8th value is the temperature of the FPGA, the controller chip (CPU).\n"
87  "The 9th value is the temperature of the PCB (Printed circuit board)\n"
88  "in the body of the SDH.\n"
89  ""
90  "- Example usage:\n"
91  " - Print temperatures of an SDH connected via Ethernet.\n"
92  " The SDH has IP-Address 192.168.1.42 and is attached to TCP port 23.\n"
93  " (Requires at least SDH-firmware v0.0.3.1)\n"
94  " > demo-GetAxisActualAngle --tcp=192.168.1.42:23\n"
95  " \n"
96  " - Print temperatures of an SDH connected to port 2 = COM3 once:\n"
97  " > demo-temperature -p 2\n"
98  "\n"
99  " - Print temperatures of an SDH connected to port 2 = COM3 every 500ms:\n"
100  " > demo-temperature -p 2 -t 0.5\n"
101  "\n"
102  " - Print temperatures of an SDH connected to USB to RS232 converter 0 move:\n"
103  " > demo-temperature --sdh_rs_device=/dev/ttyUSB0 \n"
104  " \n"
105  " - Get the version info of both the joint controllers and the tactile \n"
106  " sensor firmware from an SDH connected via Ethernet.\n"
107  " The joint controllers and the tactile sensors have a common IP-Address,\n"
108  " here 192.168.1.42. The SDH controller is attached to the \n"
109  " default TCP port 23 and the tactile sensors to the default TCP port 13000.\n"
110  " (Requires at least SDH-firmware v0.0.3.2)\n"
111  " > demo-GetAxisActualAngle --tcp=192.168.1.42 --dsa_tcp -v\n"
112  " \n"
113  " - Get the version info of an SDH connected to port 2 = COM3 \n"
114  " > demo-temperature --port=2 -v\n";
115 char const* __author__ = "Dirk Osswald: dirk.osswald@de.schunk.com";
116 char const* __url__ = "http://www.schunk.com";
117 char const* __version__ = "$Id: demo-temperature.cpp 10351 2013-06-18 16:28:14Z Osswald2 $";
118 char const* __copyright__ = "Copyright (c) 2007 SCHUNK GmbH & Co. KG";
119 
120 // end of doxygen name group sdhlibrary_cpp_demo_temperature_cpp_vars
121 // @}
122 
123 
124 
125 //----------------------------------------------------------------------
126 // Function and class member implementation (function definitions)
127 //----------------------------------------------------------------------
128 
129 
130 int main( int argc, char **argv )
131 {
133 
134  //---------------------
135  // handle command line options: set defaults first then overwrite by parsing actual command line
136  cSDHOptions options( SDHUSAGE_DEFAULT " sdhother" );
137 
138  options.Parse( argc, argv, __help__, "demo-temperature", __version__, cSDH::GetLibraryName(), cSDH::GetLibraryRelease() );
139  //
140  //----------------------------------------------------------------------
141 
142  //---------------------
143  // initialize debug message printing:
144  cDBG cdbg( options.debug_level > 0, "red", options.debuglog );
145  g_sdh_debug_log = options.debuglog;
146 
147  cdbg << "Debug messages of " << argv[0] << " are printed like this.\n";
148 
149  // reduce debug level for subsystems
150  options.debug_level-=1;
151  //---------------------
152 
153  try
154  {
155  // cSDH instance "hand" of the class cSDH according to the given options:
156  cSDH hand( options.use_radians, options.use_fahrenheit, options.debug_level );
157  cdbg << "Successfully created cSDH instance\n";
158 
159  // Open configured communication to the SDH device
160  options.OpenCommunication( hand );
161  cdbg << "Successfully opened communication to SDH\n";
162 
163 
164  cdbg << "Caption:\n";
165  if (options.period)
166  cdbg << " times are reported in seconds\n";
167 
168  cdbg << " temperatures are reported in " << hand.uc_temperature->GetName()
169  << " [" << hand.uc_temperature->GetSymbol() << "]\n";
170 
171 
172  //??? a second try block to catch keyboard interrupts
173  //try:
174 #if SDH_USE_VCC
175  double elapsed = 0.0;
176 #else
177  cSimpleTime start;
178 #endif
179 
180 
181  while (true)
182  {
183  vector<double> temps = hand.GetTemperature( hand.all_temperature_sensors );
184 
185  if (options.period > 0)
186  {
187  // print time only if reporting periodically
188 #if SDH_USE_VCC
189  cout << elapsed << " ";
190  elapsed += options.period;
191 #else
192  cout << start.Elapsed() << " ";
193 #endif
194  }
195 
196  for ( vector<double>::const_iterator vi = temps.begin();
197  vi != temps.end();
198  vi++ )
199  cout << *vi << " ";
200 
201  //print "%6.*f" % (hand.uc_temperature.decimal_places, v),
202 
203  cout << "\n";
204  cout.flush();
205 
206  if (options.period <= 0)
207  break;
208 
209  SleepSec( options.period );
210  }
211 
212  hand.Close();
213  cdbg << "Successfully disabled controllers of SDH and closed connection\n";
214  }
215  catch ( cSDHLibraryException* e )
216  {
217  cerr << "demo-temperature main(): Caught exception from SDHLibrary: " << e->what() << ". Giving up!\n";
218  delete e;
219  }
220 }
221 //----------------------------------------------------------------------
222 
223 
224 //======================================================================
225 /*
226  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
227  (e.g. to explicitely set C++ mode for *.h header files)
228 
229  Local Variables:
230  mode:C++
231  mode:ELSE
232  End:
233 */
234 //======================================================================
#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
std::vector< int > all_temperature_sensors
A vector with indices of all temperature sensors.
Definition: sdh.h:526
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.
A class to print colored debug messages.
Definition: dbg.h:113
int main(int argc, char **argv)
bool use_radians
Definition: sdhoptions.h:103
std::vector< double > GetTemperature(std::vector< int > const &sensors)
Definition: sdh.cpp:694
char const * __help__
double Elapsed(void) const
Return time in seconds elapsed between the time stored in the object and now.
Definition: simpletime.h:115
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.
#define SDHUSAGE_DEFAULT
Definition: sdhoptions.h:64
void SleepSec(double t)
Definition: util.cpp:155
char const * __version__
static char const * GetLibraryRelease(void)
Definition: sdh.cpp:626
double period
Definition: sdhoptions.h:105
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
char const * GetSymbol(void) const
Return the symbol of the external unit (something like "deg" or "ms")
Interface of auxilliary utility functions for SDHLibrary-CPP.
virtual const char * what() const
void Close(bool leave_enabled=false)
Definition: sdh.cpp:888
char const * __url__
char const * __copyright__
char const * __author__
#define USING_NAMESPACE_SDH
This file contains settings to make the SDHLibrary compile on differen systems:
Very simple class to measure elapsed time.
Definition: simpletime.h:84
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
USING_NAMESPACE_SDH NAMESPACE_SDH_START std::ostream * g_sdh_debug_log
Definition: sdhbase.cpp:55
char const * GetName(void) const
Return the name of the external unit (something like "degrees" or "milliseconds") ...
const cUnitConverter * uc_temperature
unit convert for temperatures: default = #SDH::cSDH::uc_temperature_celsius
Definition: sdh.h:574


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