Go to the documentation of this file.
69 #define XSTRINGIFY(_x) STRINGIFY(_x)
72 #define STRINGIFY(_s) #_s
83 "\nGeneral options:\n"
85 " Show this help message and exit.\n"
88 " Print the version (revision/release names) and dates of application,\n"
89 " library (and the attached SDH firmware, if found), then exit.\n"
91 " -V, --version_check\n"
92 " Check the firmware release of the connected SDH if it is the one\n"
93 " recommended by this library. A message will be printed accordingly.\n"
95 " -d LEVEL, --debug=LEVEL\n"
96 " Print debug messages of level LEVEL or lower while executing the program.\n"
97 " Level 0 (default): No messages, 1: application-level messages, \n"
98 " 2: cSDH-level messages, 3: cSDHSerial-level messages\n"
100 " -l LOGFILE, --debuglog=LOGFILE\n"
101 " Redirect the printed debug messages to LOGFILE instead of default \n"
102 " standard error. If LOGFILE starts with '+' then the output will be \n"
103 " appended to the file (without the leading '+'), else the file will be\n"
110 "\nCommunication options:\n"
111 " -p PORT, --port=PORT, --sdhport=PORT\n"
112 " Use RS232 communication PORT to connect to the SDH instead of the default\n"
113 " 0='COM1'='/dev/ttyS0'.\n"
116 " --sdh_rs_device=DEVICE_FORMAT_STRING\n"
117 " Use DEVICE_FORMAT_STRING instead of the default \"/dev/ttyS%d\". Useful\n"
118 " e.g. to use USB to RS232 converters available via \"/dev/ttyUSB%d\". \n"
119 " If the DEVICE_FORMAT_STRING contains '%d' then the PORT must also be \n"
120 " provided. If not then the DEVICE_FORMAT_STRING is the full device name. \n"
127 " -T TIMEOUT, --timeout=TIMEOUT Timeout in seconds when waiting for data from\n"
128 " SDH. The default -1 means: wait forever.\n"
130 " -b BAUDRATE, --baud=BAUDRATE\n"
131 " Use BAUDRATE in bit/s for communication. Default=115200 Bit/s for RS232\n"
132 #if WITH_ESD_CAN || WITH_PEAK_CAN
133 " and 1000000 Bit/s (1MBit/s) for CAN\n"
140 " -c, --can, --canesd\n"
141 " Use CAN bus via an ESD adapter to connect to the SDH instead of RS232.\n"
143 " -n NET, --net=NET\n"
144 " Use ESD CAN NET for CAN communication, default=0.\n"
154 " Use CAN bus via a PEAK adapter to connect to the SDH instead of RS232.\n"
159 #if WITH_PEAK_CAN && defined( OSNAME_LINUX )
160 " --sdh_canpeak_device=DEVICE_NAME\n"
161 " Use DEVICE_NAME instead of the default \"/dev/pcanusb0\"."
167 #if WITH_ESD_CAN || WITH_PEAK_CAN
168 " -e ID_READ, --id_read=ID_READ\n"
169 " Use CAN ID ID_READ for receiving CAN messages (default: 43=0x2B).\n"
171 " -w ID_WRITE, --id_write=ID_WRITE\n"
172 " Use CAN ID ID_WRITE for writing CAN messages (default: 42=0x2A).\n"
181 " --tcp[=[IP_OR_HOSTNAME][:PORT]]\n"
182 " Use TCP for communication with the SDH. The SDH can be reached via\n"
183 " TCP/IP on port PORT at IP_OR_HOSTNAME, which can be a numeric IPv4\n"
185 " When using --tcp and --dsa_tcp then only the last set IP_OR_HOSTNAME\n"
186 " is used for both.\n"
187 " (This feature requires at least SDH firmware 0.0.3.1)\n"
196 " Use radians and radians per second for angles and angular velocities\n"
197 " instead of default degrees and degrees per second.\n"
198 " (The demo programs provided might not evaluate this parameter\n"
199 " correctly. Thus they might fail if this parameter is used.)\n"
201 " -F, --fahrenheit\n"
202 " Use degrees fahrenheit to report temperatures instead of default degrees\n"
205 " -t PERIOD, --period=PERIOD\n"
206 " For periodic commands only: Time period of measurements in seconds. The\n"
207 " default of '0' means: report once only. If set then the time since start\n"
208 " of measurement is printed at the beginning of every line.\n"
213 "\nDSA options (tactile sensor):\n"
214 " -q PORT, --dsaport=PORT\n"
215 " use RS232 communication PORT to connect to to tactile sensor controller\n"
216 " of SDH instead of default 1='COM2'='/dev/ttyS1'.\n"
218 " --dsa_tcp[=[IP_OR_HOSTNAME][:PORT]]\n"
219 " use TCP for communication with the tactile sensor controller.\n"
220 " The tactile sensor can be reached via TCP/IP on port PORT at\n"
221 " IP_OR_HOSTNAME, which can be a numeric IPv4 address or a hostname.\n"
223 " When using --tcp and --dsa_tcp then only the last set IP_OR_HOSTNAME\n"
224 " is used for both.\n"
225 " (This feature requires at least SDH firmware 0.0.3.2)\n"
228 " --dsa_rs_device=DEVICE_FORMAT_STRING\n"
229 " Use DEVICE_FORMAT_STRING instead of the default \"/dev/ttyS%d\". Useful\n"
230 " e.g. to use USB to RS232 converters available via \"/dev/ttyUSB%d\". If \n"
231 " the DEVICE_FORMAT_STRING contains '%d' then the dsa PORT must also be \n"
232 " provided. If not then the DEVICE_FORMAT_STRING is the full device name.\n"
236 " Do not use the RunLengthEncoding\n"
241 " -r, --framerate=FRAMERATE\n"
242 " Framerate for acquiring full tactile sensor frames. Default value 0\n"
243 " means 'acquire a single frame only'. Any value > 0 will make the\n"
244 " DSACON32m controller in the SDH send data at the highest possible rate \n"
245 " (ca. 30 FPS (frames per second)).\n"
248 " Print acquired full frames numerically.\n"
250 " -S, --sensorinfo\n"
251 " Print sensor info from DSA (texel dimensions, number of texels...).\n"
253 " -C, --controllerinfo\n"
254 " Print controller info from DSA (version...).\n"
256 " -M, --matrixinfo=MATRIX_INDEX\n"
257 " Print matrix info for matrix with index MATRIX_INDEX from DSA.\n"
258 " This includes the current setting for sensitivity and threshold\n"
259 " of the addressed matrix (if supported by the tactile sensor firmware)."
260 " This option can be used multiple times.\n"
265 " --sensitivity=SENSITIVITY\n"
266 " Set the sensor sensitivity for all tactile sensor pads to the given\n"
267 " value. The value SENSITIVITY must be in range [0.0 .. 1.0], where\n"
268 " 0.0 is minimum and 1.0 is maximum sensitivity.\n"
269 " If --reset is given as well then SENSITIVITY is ignored and\n"
270 " the sensitivity is reset to the factory default.\n"
271 " To see the current setting for sensitivity use -M --matrixinfo\n"
272 " For setting sensitivities individually for a specific sensor X [0..5]\n"
273 " use --sensitivityX=SENSITIVITY\n"
275 " --sensitivityX=SENSITIVITY\n"
276 " X is a sensor index in range [0..5]. Set sensor sensitivity for a\n"
277 " a specific sensor X. See also --sensitivity. \n"
278 " This option can be used multiple times (with different X).\n"
280 " --threshold=THRESHOLD\n"
281 " Set the sensor threshold for all tactile sensor pads to the given \n"
282 " value. The value THRESHOLD must be in range [0 .. 4095], where\n"
283 " (0 is minimum, 4095 is maximum threshold).\n"
284 " If --reset is given as well then THRESHOLD is ignored and\n"
285 " the threshold is reset to the factory default."
287 " --thresholdX=THRESHOLD\n"
288 " Set sensor threshold for a specific sensor X.\n"
289 " X is a sensor index in range [0..5]. See also option --threshold.\n"
290 " This option can be used multiple times (with different X).\n"
293 " If given, then the values given with --sensitivity(X) \n"
294 " and/or --threshold(X) are reset to their factory default.\n"
297 " If given, then all the currently set values for sensitivity\n"
298 " and threshold are saved persistently in the configuration\n"
299 " memory of the DSACON32m controller in the SDH.\n"
300 " PLEASE NOTE: the maximum write endurance of the configuration memory\n"
301 " is about 100.000 times!\n"
303 " --showdsasettings\n"
304 " If given, then current settings for sensitivity and\n"
305 " threshold will be printed on stdout first.\n"
315 {
"help" , 0 , 0 ,
'h' },
316 {
"version" , 0 , 0 ,
'v' },
317 {
"version_check" , 0 , 0 ,
'V' },
318 {
"debug" , 1 , 0 ,
'd' },
319 {
"debuglog" , 1 , 0 ,
'l' },
321 {
"port" , 1 , 0 ,
'p' },
322 {
"sdhport" , 1 , 0 ,
'p' },
323 {
"sdh_rs_device" , 1 , 0 ,
'S' + 256},
324 {
"timeout" , 1 , 0 ,
'T' },
325 {
"baud" , 1 , 0 ,
'b' },
327 {
"can" , 0 , 0 ,
'c' },
328 {
"canesd" , 0 , 0 ,
'c' },
329 {
"net" , 1 , 0 ,
'n' },
331 {
"canpeak" , 0 , 0 ,
'p' + 256},
332 {
"sdh_canpeak_device", 1 , 0 ,
'P' + 256},
334 {
"id_read" , 1 , 0 ,
'e' },
335 {
"id_write" , 1 , 0 ,
'w' },
337 {
"tcp" , 2 , 0 ,
'T' + 256 },
339 {
"radians" , 0 , 0 ,
'R' },
340 {
"fahrenheit" , 0 , 0 ,
'F' },
341 {
"period" , 1 , 0 ,
't' },
343 {
"dsaport" , 1 , 0 ,
'q' },
344 {
"dsa_tcp" , 2 , 0 ,
'T' + 512 },
345 {
"dsa_rs_device" , 1 , 0 ,
'D' + 256},
346 {
"no_rle" , 0 , 0 ,
'r' + 256},
347 {
"framerate" , 1 , 0 ,
'r' },
348 {
"fullframe" , 0 , 0 ,
'f' },
349 {
"sensorinfo" , 0 , 0 ,
'S' },
350 {
"controllerinfo" , 0 , 0 ,
'C' },
351 {
"matrixinfo" , 1 , 0 ,
'M' },
353 {
"sensitivity" , 1 , 0 , 999 },
354 {
"sensitivity0" , 1 , 0 , 1000 },
355 {
"sensitivity1" , 1 , 0 , 1001 },
356 {
"sensitivity2" , 1 , 0 , 1002 },
357 {
"sensitivity3" , 1 , 0 , 1003 },
358 {
"sensitivity4" , 1 , 0 , 1004 },
359 {
"sensitivity5" , 1 , 0 , 1005 },
360 {
"threshold" , 1 , 0 , 1009 },
361 {
"threshold0" , 1 , 0 , 1010 },
362 {
"threshold1" , 1 , 0 , 1011 },
363 {
"threshold2" , 1 , 0 , 1011 },
364 {
"threshold3" , 1 , 0 , 1013 },
365 {
"threshold4" , 1 , 0 , 1014 },
366 {
"threshold5" , 1 , 0 , 1015 },
367 {
"reset" , 0 , 0 ,
'R' + 512},
368 {
"persistent" , 0 , 0 ,
'P' + 512},
369 {
"showdsasettings" , 0 , 0 ,
'S' + 512},
382 std::string os( option_selection );
384 if ( os.find(
"general" ) != string::npos )
386 if ( os.find(
"sdhcom_serial" ) != string::npos )
388 if ( os.find(
"sdhcom_common" ) != string::npos )
390 if ( os.find(
"sdhcom_esdcan" ) != string::npos )
392 if ( os.find(
"sdhcom_peakcan" ) != string::npos )
394 if ( os.find(
"sdhcom_cancommon" ) != string::npos )
396 if ( os.find(
"sdhcom_tcp" ) != string::npos )
398 if ( os.find(
"sdhother" ) != string::npos )
400 if ( os.find(
"dsacom" ) != string::npos )
402 if ( os.find(
"dsaother" ) != string::npos )
404 if ( os.find(
"dsaadjust" ) != string::npos )
412 strncpy( sdh_rs_device,
"/dev/ttyS%d", MAX_DEV_LENGTH );
414 rs232_baudrate = 115200;
419 use_can_peak =
false;
420 strncpy( sdh_canpeak_device,
"/dev/pcanusb0", MAX_DEV_LENGTH );
431 use_fahrenheit =
false;
435 strncpy( dsa_rs_device,
"/dev/ttyS%d", MAX_DEV_LENGTH );
443 controllerinfo =
false;
445 for (
int i=0; i<6; i++ )
448 sensitivity[i] = -1.0;
449 threshold[i] = 65535;
451 reset_to_default =
false;
453 showdsasettings =
false;
459 if ( debuglog && debuglog != &cerr )
465 char const* helptext,
char const* progname,
char const* version,
char const* libname,
char const* librelease )
468 unsigned long baudrate = 0;
469 bool do_print_version =
false;
470 bool do_check_version =
false;
471 int option_index = 0;
474 int nb_matrixinfos = 0;
488 cout << helptext <<
"\n\nusage: " << progname <<
" [options]\n" <<
usage <<
"\n";
492 do_print_version =
true;
496 do_check_version =
true;
500 rc = sscanf(
optarg,
"%d", &debug_level );
506 ios_base::openmode mode = ios_base::out | ios_base::trunc;
509 mode = ios_base::app;
512 debuglog =
new ofstream(
optarg, mode );
513 assert( debuglog !=
NULL );
514 assert( ! debuglog->fail() );
519 rc = sscanf(
optarg,
"%d", &sdhport );
524 strncpy( sdh_rs_device,
optarg, MAX_DEV_LENGTH );
528 rc = sscanf(
optarg,
"%lf", &timeout );
533 rc = sscanf(
optarg,
"%lu", &baudrate );
543 rc = sscanf(
optarg,
"%d", &net );
553 strncpy( sdh_canpeak_device,
optarg, MAX_DEV_LENGTH );
559 if ( !strncmp(
optarg,
"0x", 2 ) || !strncmp(
optarg,
"0X", 2 ) )
560 rc = sscanf(
optarg,
"0x%x", &id_read );
562 rc = sscanf(
optarg,
"%u", &id_read );
567 if ( !strncmp(
optarg,
"0x", 2 ) || !strncmp(
optarg,
"0X", 2 ) )
568 rc = sscanf(
optarg,
"0x%x", &id_write );
570 rc = sscanf(
optarg,
"%u", &id_write );
580 use_fahrenheit =
true;
584 rc = sscanf(
optarg,
"%lf", &period );
590 rc = sscanf(
optarg,
"%d", &dsaport );
595 strncpy( dsa_rs_device,
optarg, MAX_DEV_LENGTH );
604 rc = sscanf(
optarg,
"%d", &framerate );
614 controllerinfo =
true;
617 if ( nb_matrixinfos > 5 )
619 cerr <<
"Error: matrixinfo requested more than 6 times!";
622 rc = sscanf(
optarg,
"%d", &(matrixinfo[nb_matrixinfos++]) );
628 rc = sscanf(
optarg,
"%lf", &(sensitivity[0]) );
630 assert( 0.0 <= sensitivity[0] );
631 assert( sensitivity[0] <= 1.0 );
633 sensitivity[i] = sensitivity[0];
642 rc = sscanf(
optarg,
"%lf", &(sensitivity[i]) );
644 assert( 0.0 <= sensitivity[i] );
645 assert( sensitivity[i] <= 1.0 );
649 rc = sscanf(
optarg,
"%d", &(threshold[0]) );
651 assert( 0 <= threshold[0] );
652 assert( threshold[0] <= 4095 );
654 threshold[i] = threshold[0];
663 rc = sscanf(
optarg,
"%d", &(threshold[i]) );
665 assert( 0 <= threshold[i] );
666 assert( threshold[i] <= 4095 );
674 reset_to_default =
true;
678 showdsasettings =
true;
686 char* colon = strchr(
optarg, (
int)
':' );
694 tcp_port = atoi( colon+1 );
696 else if ( strlen(
optarg ) > 0 )
706 char* colon = strchr(
optarg, (
int)
':' );
714 dsa_tcp_port = atoi( colon+1 );
716 else if ( strlen(
optarg ) > 0 )
724 cerr <<
"Error: getopt returned invalid character code '" << char(c) <<
"' = " << int(c) <<
", giving up!\n";
732 if ( use_can_esd || use_can_peak )
735 rs232_baudrate = baudrate;
739 if ( do_check_version )
744 cSDH hand(
false,
false, debug_level-1 );
747 OpenCommunication( hand );
752 cout <<
"The firmware release of the connected SDH is the one recommended by\n";
753 cout <<
"this SDHLibrary. Good.\n";
757 cout <<
"The firmware release of the connected SDH is NOT the one recommended\n";
758 cout <<
"by this SDHLibrary:\n";
761 cout <<
" => Communication with the SDH might not work as expected!\n";
767 cerr <<
"Could not check firmware release from SDH: " << e->
what() <<
"\n";
777 if ( do_print_version )
779 cout <<
"PC-side:\n";
780 cout <<
" Demo-program name: " << argv[0] <<
"\n";
781 cout <<
" Demo-program revision: " << version <<
"\n";
782 cout <<
" " << libname <<
" release: " << librelease <<
"\n";
783 cout <<
" " << libname <<
" date: " << libdate <<
"\n";
790 cSDH hand(
false,
false, debug_level-1 );
793 OpenCommunication( hand );
795 cout <<
"SDH-side:\n";
796 cout <<
" SDH firmware release: " << hand.
GetInfo(
"release-firmware" ) <<
"\n";
797 cout <<
" SDH firmware date: " << hand.
GetInfo(
"date-firmware" ) <<
"\n";
798 cout <<
" SDH SoC ID: " << hand.
GetInfo(
"release-soc" ) <<
"\n";
799 cout <<
" SDH SoC date: " << hand.
GetInfo(
"date-soc" ) <<
"\n";
800 cout <<
" SDH ID: " << hand.
GetInfo(
"id-sdh" ) <<
"\n";
801 cout <<
" SDH Serial Number: " << hand.
GetInfo(
"sn-sdh" ) <<
"\n";
806 cerr <<
"Could not get all version info from SDH: " << e->
what() <<
"\n";
815 ts =
new cDSA( 0, tcp_adr.c_str(), dsa_tcp_port );
819 ts =
new cDSA( 0, dsaport );
822 cout <<
"DSA-side:\n";
829 std::string dsa_controller_sw_version( buffer );
833 std::string new_version_string(
"" );
834 std::string sep(
"" );
835 for (
int i=0; i < 4; i++ )
837 snprintf( buffer, 8,
"%hu", (
sw_version >> (i*4)) & 0x0f );
838 new_version_string = buffer + sep + new_version_string;
841 dsa_controller_sw_version +=
" (" + (new_version_string) +
")";
843 cout <<
" DSA controller info sw_version: " << dsa_controller_sw_version <<
"\n";
849 cerr <<
"Could not get sensor controller firmware release from DSA: " << e->
what() <<
"\n";
874 else if ( use_can_peak )
880 sdh_canpeak_device );
static char const * sdhusage_dsacom
DSA (tactile sensor) communication options.
void OpenTCP(char const *_tcp_adr="192.168.1.1", int _tcp_port=23, double _timeout=0.0)
SDH::cDSA is the end user interface class to access the DSACON32m, the tactile sensor controller of t...
#define PROJECT_DATE
Date of the release of the software project.
#define USING_NAMESPACE_SDH
Base class for exceptions in the SDHLibrary-CPP.
static char const * sdhusage_sdhcom_serial
RS232 communication options.
This file contains nothing but C/C++ defines with the name of the project itself (PROJECT_NAME) and t...
static char const * sdhusage_sdhcom_cancommon
Common CAN communication options.
void OpenRS232(int _port=0, unsigned long _baudrate=115200, double _timeout=-1, char const *_device_format_string="/dev/ttyS%d")
Implementation of a class to parse common SDH related command line options.
static char const * sdhoptions_short_options
short command line options accepted by the cSDHOptions class
const sControllerInfo & GetControllerInfo(void) const
Return a reference to the sControllerInfo read from the remote DSACON32m controller.
void OpenCAN_ESD(int _net=0, unsigned long _baudrate=1000000, double _timeout=0.0, Int32 _id_read=43, Int32 _id_write=42)
#define SDH_DEFAULT_TCP_ADR
char const * GetFirmwareRelease(void)
static char const * sdhusage_dsaother
DSA (tactile sensor) other options.
void OpenCAN_PEAK(unsigned long _baudrate=1000000, double _timeout=0.0, Int32 _id_read=43, Int32 _id_write=42, const char *_device="/dev/pcanusb0")
static char const * sdhusage_general
general options
static char const * sdhusage_sdhcom_common
Common communication options.
void OpenCommunication(NS_SDH cSDH &hand)
cSDHOptions(char const *option_selection=SDHUSAGE_DEFAULT)
uint16_t UInt16
unsigned integer, size 2 Byte (16 Bit)
static char const * sdhusage_dsaadjust
DSA (tactile sensor) adjustment options.
static struct option sdhoptions_long_options[]
long command line options accepted by the cSDHOptions class
This file contains interface to #SDH::cDSA, a class to communicate with the tactile sensors of the SD...
Derived exception class for low-level DSA related exceptions.
#define SDH_DEFAULT_TCP_PORT
#SDH::cSDH is the end user interface class to control a SDH (SCHUNK Dexterous Hand).
~cSDHOptions()
destructor, clean up
static char const * sdhusage_sdhcom_peakcan
PEAK CAN communication options.
static char const * GetFirmwareReleaseRecommended(void)
bool CheckFirmwareRelease(void)
const sSensorInfo & GetSensorInfo(void) const
Return a reference to the sSensorInfo read from the remote DSACON32m controller.
static char const * sdhusage_sdhother
Other options.
static char const * sdhusage_sdhcom_esdcan
ESD CAN communication options.
static char const * sdhusage_sdhcom_tcp
TCP communication options.
This file contains settings to make the SDHLibrary compile on differen systems:
#define DSA_DEFAULT_TCP_PORT
USING_NAMESPACE_SDH NAMESPACE_SDH_START std::ostream * g_sdh_debug_log
This file contains the interface to class #SDH::cSDH, the end user class to access the SDH from a PC.
virtual const char * what() const
int Parse(int argc, char **argv, char const *helptext, char const *progname, char const *version, char const *libname, char const *librelease)
void Close(bool leave_enabled=false)
void Close(void)
Set the framerate of the remote DSACON32m controller to 0 and close connection to it.
char const * GetInfo(char const *what)
int getopt_long(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind)
sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Wed Mar 2 2022 01:00:58