Go to the documentation of this file.
   62 #pragma pack(push,1)  // for VCC (MS Visual Studio) we have to set the necessary 1 byte packing with this pragma 
  126 #pragma pack(pop)   // for VCC (MS Visual Studio) restore normal packing 
  157     cmd_code( (unsigned char) command ),
 
  184     if ( crc_calculated != *
CRC16() )
 
  192     stream << 
"sSDHBinaryRequest:\n" 
  194     << 
"  nb_data_bytes=" << std::dec << int(request.
nb_data_bytes) << 
"\n" 
  197     char const* sep = 
"";
 
  204         stream << sep << 
"... something is fishy here!";
 
  207         stream << 
"\n  crc=0x" << std::hex << std::setfill(
'0') << std::setw(4) <<  *(request.
CRC16()) << std::dec;
 
  215     stream << 
"sSDHBinaryResponse:\n" 
  217     << 
"  nb_data_bytes=" << std::dec << int(response.
nb_data_bytes) << 
"\n" 
  221     char const* sep = 
"";
 
  228         stream << sep << 
"... something is fishy here!";
 
  231         stream << 
"\n  crc=0x" << std::hex << std::setfill(
'0') << std::setw(4) <<  *(response.
CRC16()) << std::dec;
 
  256     assert( 
sizeof( request.
cmd_code ) == 1 );
 
  259     assert( ((
unsigned char*) &(request.
cmd_code) ) +1             == ((
unsigned char*) &(request.
nb_data_bytes) ) );
 
  262     assert( 
sizeof( response.
cmd_code ) == 1 );
 
  266     assert( ((
unsigned char*) &(response.
cmd_code) ) +1            == ((
unsigned char*) &(response.
nb_data_bytes) ) );
 
  269     assert( ((
unsigned char*) &(response.
status_code) ) +1         == ((
unsigned char*) &(response.
parameter) )  );
 
  278     cdbg << 
"Debug messages of cSDHSerial are printed like this.\n";
 
  325         cdbg << 
"caught <" << *e << 
"> (ignored while cleaning up communication 1)\n";
 
  339         int n = 
com->
Read( dummy, 1024, 100000, 
true );
 
  340         cdbg << 
"Read and ignored " << n << 
" bytes \"" << dummy << 
"\"\n"; 
cdbg.
flush();
 
  344         cdbg << 
"caught <" << *e << 
"> (ignored while cleaning up communication 2)\n";
 
  359         cdbg << 
"caught <" << *e << 
">\n";
 
  392     int retries = max_retries; 
 
  415             cdbg << 
"cSDHSerial::Send: sending command '" << s << 
"' to SDH\n";
 
  416             cdbg << 
"  nb_lines=" << nb_lines << 
"  nb_lines_total=" << nb_lines_total << 
"  nb_lines_to_ignore=" << 
nb_lines_to_ignore << 
"\n";
 
  421             cdbg << 
"sent command\n";
 
  426             while (nb_lines == 
All || nb_lines > 0)
 
  437                 if (nb_lines_total != 
All)
 
  449                 while ( *startp != 
'\0' && strchr( 
"\r\n", *startp ) != 
NULL )
 
  476             if (nb_lines_total != 
All)
 
  501                 cdbg << 
"Retried sending, but still got errors from SDH!\n";
 
  505             cdbg << 
"ignoring cSDHErrorCommunication: " << *e << 
"\n";
 
  523     if   (
reply[-1][0] == 
'E')
 
  531     else if (
reply[-1][0] == 
'@')
 
  548     char* pattern_at = strstr( line, 
"=" );
 
  550     if (pattern_at == 
NULL)
 
  554     sscanf( pattern_at, 
"=%lf", &duration );
 
  556     cdbg << 
"extracted duration " << duration << 
"\n";
 
  576     int nb_lines_total = 1;
 
  577     int nb_lines = nb_lines_total;
 
  582     Send( 
"get_duration", nb_lines, nb_lines_total );
 
  611     int nb_bytes_received = 
com->
Read( buffer, 256, 
long(timeout_s*1E6), 
false );
 
  612     cdbg << 
"cSDHSerial::BinarySync: ignoring " << nb_bytes_received << 
" bytes\n";
 
  630             cdbg << __FILE__ << 
":" << __LINE__ << 
" ignoring cSerialBaseException: " << *e << 
"\n";
 
  644     int cutoff  = 
static_cast<int>(strlen(command)) + 1;
 
  646     int cutoff  = strlen( command ) + 1;
 
  648     int cutoff1 = cutoff +3;
 
  655             if (axis == 
All && value == 
NULL)
 
  686                 Send( 
cMsg( 
"%s=%f,%f,%f,%f,%f,%f,%f", command, value[0], value[1], value[2], value[3], value[4], value[5], value[6] ).c_str() );
 
  702                 cdbg << __FILE__ << 
":" << __LINE__ << 
" ignoring cSDHLibraryException: " << *e << 
" (retrying)\n";
 
  705                 cdbg << __FILE__ << 
":" << __LINE__ << 
" retried but giving up now\n";
 
  720     cdbg << 
"Retried sending, but still didnt work!\n";
 
  731     int nb_bytes_to_receive =
 
  737         + ((use_crc16)? 
sizeof( 
tCRCValue ) : 0); 
 
  745                 cdbg << 
"cSDHSerial::BinaryAxisCommand: sending '" << request << 
"' to SDH\n";
 
  749             int nb_bytes_received = 
com->
Read( &response, nb_bytes_to_receive, 
long( 
com->
GetTimeout() * 1E6 ), 
false );
 
  751             if ( nb_bytes_received != nb_bytes_to_receive )
 
  755                 cdbg << 
"cSDHSerial::BinaryAxisCommand: received '" << response << 
"' from SDH\n";
 
  761             if ( response.status_code != 
RC_OK )
 
  767                 return cSimpleVector( 1, axis, &(response.parameter[ axis ]) );
 
  777                 cdbg << __FILE__ << 
":" << __LINE__ << 
" ignoring cSDHLibraryException: " << *e << 
" (retrying)\n";
 
  780                 cdbg << __FILE__ << 
":" << __LINE__ << 
" retried but giving up now\n";
 
  795     cdbg << 
"Retried sending, but still didnt work!\n";
 
  806         Send( 
cMsg( 
"pid(%d)", axis ).c_str() );
 
  811         Send( 
cMsg( 
"pid(%d)=%f,%f,%f", axis, *
p, *i, *d ).c_str() );
 
  853 #if SDH_USE_BINARY_COMMUNICATION 
  869 #if SDH_USE_BINARY_COMMUNICATION 
  880     Send( 
cMsg( 
"demo=%d", 
int( onoff ) ).c_str() );
 
  887     Send( 
cMsg( 
"%s=%d", propname, value ).c_str() );
 
  889     sscanf( 
reply[0] + strlen(propname), 
"%d", &
v );
 
  897     return property( 
"user_errors", value );
 
  904     return property( 
"terminal", value );
 
  918 #if SDH_USE_BINARY_COMMUNICATION 
  929 #if SDH_USE_BINARY_COMMUNICATION 
  954 #if SDH_USE_BINARY_COMMUNICATION 
  965 #if SDH_USE_BINARY_COMMUNICATION 
  976 #if SDH_USE_BINARY_COMMUNICATION 
 1001     int nb_lines_total = 1;
 
 1002     int nb_lines = nb_lines_total;
 
 1007     Send( 
"m", nb_lines, nb_lines_total );
 
 1033     if ( velocity_profile < 0 )
 
 1034         sprintf( cmd, 
"vp" );
 
 1036         sprintf( cmd, 
"vp=%d", velocity_profile );
 
 1043     sscanf( 
reply[0]+3, 
"%d", &new_vp );
 
 1053         sprintf( cmd, 
"con" );
 
 1055         sprintf( cmd, 
"con=%d", controller );
 
 1062     sscanf( 
reply[0]+4, 
"%d", &new_con );
 
 1070 #if SDH_USE_BINARY_COMMUNICATION 
 1098 #if SDH_USE_BINARY_COMMUNICATION 
 1109 #if SDH_USE_BINARY_COMMUNICATION 
 1120 #if SDH_USE_BINARY_COMMUNICATION 
 1135     sscanf( 
reply[0] + 5, 
"%lf,%lf,%lf,%lf,%lf,%lf,%lf", &(rv[0]), &(rv[1]), &(rv[2]), &(rv[3]), &(rv[4]), &(rv[5]), &(rv[6]) );
 
 1148     sscanf( 
reply[0] + 5, 
"%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
 
 1149             &(dummy[0]), &(dummy[1]), &(dummy[2]), &(dummy[3]), &(dummy[4]), &(dummy[5]), &(dummy[6]),
 
 1150             &(rv[0]), &(rv[1]) );
 
 1159     return reply[0] + 4;
 
 1167     return reply[0] + 9;
 
 1175     return reply[0] + 3;
 
 1183     return reply[0] + 3;
 
 1191     return reply[0] + 4;
 
 1199     return reply[0] + 9;
 
 1260     int nb_lines_total = 1;
 
 1261     int nb_lines = nb_lines_total;
 
 1266     Send( 
cMsg( 
"selgrip=%d", 
grip).c_str(), nb_lines, nb_lines_total );
 
 1294     CheckRange( close, 0.0, 1.0, 
"close ratio" );
 
 1304     int nb_lines_total = 1;
 
 1305     int nb_lines = nb_lines_total;
 
 1310     char cmd[] = 
"grip=CCCCCCCCCCCCCCC,VVVVVVVVVVVVVVV";
 
 1311     sprintf( cmd, 
"grip=%f,%f", close, velocity );
 
 1312     Send( cmd, nb_lines, nb_lines_total );
 
  
unsigned char nb_data_bytes
eControllerType con(eControllerType controller)
double GetDuration(char *line)
virtual void Close(void)=0
Close the previously opened communication channel.
int user_errors(int value)
cSimpleVector rvel(int axis, double *dummy=NULL)
cSimpleVector alim(int axis=All, double *dummy=NULL)
#define USING_NAMESPACE_SDH
int GetNbBytesToSend() const
return the total number of bytes to send
Base class for exceptions in the SDHLibrary-CPP.
cSimpleVector pid(int axis, double *p=NULL, double *i=NULL, double *d=NULL)
@ eGID_DIMENSION
Endmarker and dimension.
cSimpleVector state(int axis=All, double *dummy=NULL)
float parameter[eNUMBER_OF_ELEMENTS]
virtual bool IsOpen(void)
#define NAMESPACE_SDH_END
cSimpleVector tpap(int axis=All, double *angle=NULL)
@ eVP_SIN_SQUARE
sin square velocity profile
data structure with binary data for request from PC to SDH
Low-level communication class to access a serial port.
cDBG cdbg
debug stream to print colored debug messages
data structure with binary data for response from SDH to PC
unsigned char nb_valid_parameters
virtual double GetTimeout()
get the timeout for next readline() calls (negative value means: no timeout, wait for ever)
eVelocityProfile vp(eVelocityProfile velocity_profile=eVP_INVALID)
Derived exception class for exceptions related to communication between the SDHLibrary and the SDH.
sSDHBinaryRequest(eCommandCode command, double *value, bool use_crc16)
cSimpleStringList reply
Space for the replies from the SDH.
void ExtractFirmwareState()
This file contains interface to cCRC, a class to handle CRC calculation.
@ eCT_DIMENSION
Endmarker and dimension.
helper class to set timeout of _serial_base on construction and reset to previous value on destructio...
virtual bool IsOpen(void)=0
Return true if communication channel is open.
void SetColor(char const *color)
void Send(char const *s, int nb_lines=All, int nb_lines_total=All, int max_retries=3)
eControllerType
An enum for all possible SDH internal controller types (order must match that in the SDH firmware in ...
float parameter[eNUMBER_OF_ELEMENTS]
char * CurrentLine()
Return the current line.
Derived exception class for low-level serial communication related exceptions.
double eps
epsilon value (max absolute deviation of reported values from actual hardware values) (needed since S...
cSDHSerial(int _debug_level=0)
Constructor of cSDHSerial.
A simple vector implementation.
char const  *NS_SDH SDHReturnCodeToString(eReturnCode rc)
tCRCValue * CRC16() const
return a ptr to the CRC value in parameter_bytes, assuming that nb_data_bytes is correct (including t...
double grip(double close, double velocity, bool sequ)
cSimpleVector igrip(int axis=All, double *limit=NULL)
This file contains function to convert the binary command codes of the SDH. To use this from a non gc...
NAMESPACE_SDH_START typedef UInt16 tCRCValue
the data type used to calculate and exchange CRC values with DSACON32m (16 bit integer)
char * NextLine()
Return the next line, this increases current_line.
Interface of class #SDH::cSDHSerial.
enum eReturnCodeEnum eReturnCode
typedef for eCommandCodeEnum, see there
unsigned char nb_data_bytes
eVelocityProfile
An enum for all possible SDH internal velocity profile types.
int property(char const *propname, int value)
@ eCT_INVALID
invalid controller_type (needed for cSDHSerial::con() to indicate "read current controller type")
cSimpleVector kv(int axis=All, double *kv=NULL)
unsigned char parameter_bytes[sizeof(float) *eNUMBER_OF_ELEMENTS+sizeof(tCRCValue)]
struct sSDHBinaryRequest SDH__attribute__((packed))
cSerialBase * com
The communication object to the serial device (RS232 port or ESD CAN net)
unsigned char status_code
cSimpleVector pos(int axis=All, double *dummy=NULL)
Class for short, fixed maximum length text messages.
double m_sequtime
additional time in seconds to wait for sequential execution of m command (as these are always execute...
@ eNUMBER_OF_ELEMENTS
number of elements in vector
int Length() const
Return number of lines stored.
tCRCValue AddBytes(unsigned char *bytes, int nb_bytes)
insert nb_bytes from bytes into CRC calculation and return the new current CRC checksum
The base class to control the SCHUNK Dexterous Hand.
void CheckRange(double value, double minvalue, double maxvalue, char const *name="")
Check if value is in [minvalue .. maxvalue]. Throw a cSDHErrorInvalidParameter exception if not.
static char const  * firmware_error_codes[]
A mapping from eErrorCode error code enums to strings with human readable error messages.
cSimpleVector v(int axis=All, double *velocity=NULL)
std::ostream & operator<<(std::ostream &stream, sSDHBinaryRequest const &request)
helper functions to insert a human readable form of the request into stream
cSimpleVector power(int axis=All, double *flag=NULL)
void CheckIndex(int index, int maxindex, char const *name="")
Check if index is in [0 .. maxindex-1] or All. Throw a cSDHErrorInvalidParameter exception if not.
enum eCommandCodeEnum eCommandCode
typedef for eCommandCodeEnum, see there
A derived CRC class that uses a CRC table and initial value suitable for protecing the binary communi...
int nb_lines_to_ignore
number of remaining reply lines of a previous (non-sequential) command
unsigned char nb_valid_parameters
#define NAMESPACE_SDH_START
virtual void Open(void)=0
Open rs232 port port.
Derived exception class for exceptions related to invalid parameters.
unsigned char nb_data_bytes
void BinarySync(double timeout_s=0.5)
void CheckCRC16() const
check the CRC value in parameter_bytes. Throw an exception if check fails
cSimpleVector vel(int axis=All, double *dummy=NULL)
cSimpleVector ref(int axis=All, double *value=NULL)
cSimpleVector BinaryAxisCommand(eCommandCode command, int axis=All, double *value=NULL)
@ eVP_DIMENSION
endmarker and dimension
virtual ssize_t Read(void *data, ssize_t size, long timeout_us, bool return_on_less_data)=0
void Open(cSerialBase *_com)
cSimpleVector a(int axis=All, double *acceleration=NULL)
cSimpleVector ihold(int axis=All, double *limit=NULL)
eErrorCode firmware_state
the last known state of the SDH firmware
unsigned char nb_valid_parameters
cSimpleVector temp_electronics(void)
virtual int write(char const *ptr, int len=0)=0
Write data to a previously opened port.
double selgrip(eGraspId grip, bool sequ)
This file contains settings to make the SDHLibrary compile on differen systems:
cSimpleVector ilim(int axis=All, double *limit=NULL)
virtual char * readline(char *line, int size, char const *eol="\n", bool return_on_less_data=false)
Read a line from the device.
cSimpleVector tvav(int axis=All, double *velocity=NULL)
tCRCValue * CRC16() const
return a ptr to the CRC value in parameter_bytes, assuming that nb_data_bytes is correct (including t...
cSimpleVector pos_save(int axis=All, double *value=NULL)
cSimpleVector vlim(int axis=All, double *dummy=NULL)
cSimpleVector p(int axis=All, double *angle=NULL)
eGraspId
The enum values of the known grasps.
unsigned char parameter_bytes[sizeof(float) *eNUMBER_OF_ELEMENTS+sizeof(tCRCValue)]
Interface of auxilliary utility functions for SDHLibrary-CPP.
USING_NAMESPACE_SDH char const  *NS_SDH SDHCommandCodeToString(eCommandCode cc)
char const  * EOL
String to use as "End Of Line" marker when sending to SDH.
cSimpleVector AxisCommand(char const *command, int axis=All, double *value=NULL)
@ All
A meta-value that means "access all possible values".
int NUMBER_OF_AXES
The number of axes.
double get_duration(void)
sdhlibrary_cpp
Author(s): Dirk Osswald 
autogenerated on Wed Mar 2 2022 01:00:58