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 //======================================================================
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
cSimpleTime
Very simple class to measure elapsed time.
Definition: simpletime.h:84
cUnitConverter::GetSymbol
char const * GetSymbol(void) const
Return the symbol of the external unit (something like "deg" or "ms")
Definition: unit_converter.cpp:168
getopt.h
cSimpleTime::Elapsed
double Elapsed(void) const
Return time in seconds elapsed between the time stored in the object and now.
Definition: simpletime.h:115
__author__
char const * __author__
Definition: demo-temperature.cpp:115
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
__url__
char const * __url__
Definition: demo-temperature.cpp:116
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
SleepSec
void SleepSec(double t)
Definition: util.cpp:155
cSDHOptions::period
double period
Definition: sdhoptions.h:105
cSDHOptions
class for command line option parsing holding option parsing results
Definition: sdhoptions.h:78
cSDH::uc_temperature
const cUnitConverter * uc_temperature
unit convert for temperatures: default = #SDH::cSDH::uc_temperature_celsius
Definition: sdh.h:574
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
cSDH::GetTemperature
std::vector< double > GetTemperature(std::vector< int > const &sensors)
Definition: sdh.cpp:694
cdbg
cDBG cdbg(false, "red")
SDHUSAGE_DEFAULT
#define SDHUSAGE_DEFAULT
Definition: sdhoptions.h:64
cSDH::all_temperature_sensors
std::vector< int > all_temperature_sensors
A vector with indices of all temperature sensors.
Definition: sdh.h:526
__version__
char const * __version__
Definition: demo-temperature.cpp:117
basisdef.h
This file contains some basic definitions (defines, macros, datatypes)
main
int main(int argc, char **argv)
Definition: demo-temperature.cpp:130
simpletime.h
Interface of auxilliary utility functions for SDHLibrary-CPP.
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
cUnitConverter::GetName
char const * GetName(void) const
Return the name of the external unit (something like "degrees" or "milliseconds")
Definition: unit_converter.cpp:161
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.
__help__
char const * __help__
Definition: demo-temperature.cpp:80
cSDHLibraryException::what
virtual const char * what() const
Definition: sdhexception.cpp:118
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
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
__copyright__
char const * __copyright__
Definition: demo-temperature.cpp:118


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