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)
478 nb_lines_to_ignore = nb_lines_total;
480 cdbg << nb_lines_to_ignore <<
" lines remain to be ignored\n";
485 if (nb_lines_to_ignore == 0)
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";
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;
1209 sscanf(
reply[0]+8,
"%d", &numaxis );
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 );
data structure with binary data for response from SDH to PC
A meta-value that means "access all possible values".
float parameter[eNUMBER_OF_ELEMENTS]
sin square velocity profile
The base class to control the SCHUNK Dexterous Hand.
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...
unsigned char nb_data_bytes
void SetColor(char const *color)
eGraspId
The enum values of the known grasps.
char * CurrentLine()
Return the current line.
virtual double GetTimeout()
get the timeout for next readline() calls (negative value means: no timeout, wait for ever) ...
enum eReturnCodeEnum eReturnCode
typedef for eCommandCodeEnum, see there
int nb_lines_to_ignore
number of remaining reply lines of a previous (non-sequential) command
cSimpleVector pos(int axis=All, double *dummy=NULL)
cSimpleVector v(int axis=All, double *velocity=NULL)
USING_NAMESPACE_SDH char const *NS_SDH SDHCommandCodeToString(eCommandCode cc)
A simple vector implementation.
cSimpleVector BinaryAxisCommand(eCommandCode command, int axis=All, double *value=NULL)
unsigned char nb_valid_parameters
NAMESPACE_SDH_START typedef UInt16 tCRCValue
the data type used to calculate and exchange CRC values with DSACON32m (16 bit integer) ...
cSimpleVector vel(int axis=All, double *dummy=NULL)
cSimpleVector ref(int axis=All, double *value=NULL)
char const * EOL
String to use as "End Of Line" marker when sending to SDH.
This file contains interface to cCRC, a class to handle CRC calculation.
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...
cSimpleVector tvav(int axis=All, double *velocity=NULL)
virtual bool IsOpen(void)=0
Return true if communication channel is open.
void Open(cSerialBase *_com)
cSimpleVector ihold(int axis=All, double *limit=NULL)
void CheckCRC16() const
check the CRC value in parameter_bytes. Throw an exception if check fails
This file contains function to convert the binary command codes of the SDH. To use this from a non gc...
cSimpleVector temp_electronics(void)
cSimpleVector a(int axis=All, double *acceleration=NULL)
float parameter[eNUMBER_OF_ELEMENTS]
cSimpleVector vlim(int axis=All, double *dummy=NULL)
void BinarySync(double timeout_s=0.5)
eVelocityProfile
An enum for all possible SDH internal velocity profile types.
int Length() const
Return number of lines stored.
double selgrip(eGraspId grip, bool sequ)
eErrorCode firmware_state
the last known state of the SDH firmware
eControllerType con(eControllerType controller)
cSimpleVector rvel(int axis, double *dummy=NULL)
cSimpleVector ilim(int axis=All, double *limit=NULL)
helper class to set timeout of _serial_base on construction and reset to previous value on destructio...
cSimpleVector AxisCommand(char const *command, int axis=All, double *value=NULL)
cSimpleVector pos_save(int axis=All, double *value=NULL)
Low-level communication class to access a serial port.
cSimpleVector tpap(int axis=All, double *angle=NULL)
cSimpleVector p(int axis=All, double *angle=NULL)
#define NAMESPACE_SDH_START
int NUMBER_OF_AXES
The number of axes.
data structure with binary data for request from PC to SDH
Base class for exceptions in the SDHLibrary-CPP.
virtual bool IsOpen(void)
Interface of auxilliary utility functions for SDHLibrary-CPP.
invalid controller_type (needed for cSDHSerial::con() to indicate "read current controller type") ...
char * NextLine()
Return the next line, this increases current_line.
union sSDHBinaryRequest::@3 SDH__attribute__
double GetDuration(char *line)
enum eCommandCodeEnum eCommandCode
typedef for eCommandCodeEnum, see there
void CheckRange(double value, double minvalue, double maxvalue, char const *name="")
Check if value is in [minvalue .. maxvalue]. Throw a cSDHErrorInvalidParameter exception if not...
tCRCValue * CRC16() const
return a ptr to the CRC value in parameter_bytes, assuming that nb_data_bytes is correct (including t...
eControllerType
An enum for all possible SDH internal controller types (order must match that in the SDH firmware in ...
cSimpleVector pid(int axis, double *p=NULL, double *i=NULL, double *d=NULL)
cDBG cdbg
debug stream to print colored debug messages
cSimpleVector state(int axis=All, double *dummy=NULL)
double get_duration(void)
cSimpleStringList reply
Space for the replies from the SDH.
#define USING_NAMESPACE_SDH
virtual int write(char const *ptr, int len=0)=0
Write data to a previously opened port.
Interface of class #SDH::cSDHSerial.
double grip(double close, double velocity, bool sequ)
int user_errors(int value)
cSimpleVector alim(int axis=All, double *dummy=NULL)
tCRCValue AddBytes(unsigned char *bytes, int nb_bytes)
insert nb_bytes from bytes into CRC calculation and return the new current CRC checksum ...
unsigned char status_code
A derived CRC class that uses a CRC table and initial value suitable for protecing the binary communi...
#define NAMESPACE_SDH_END
Derived exception class for exceptions related to communication between the SDHLibrary and the SDH...
void ExtractFirmwareState()
cSimpleVector igrip(int axis=All, double *limit=NULL)
This file contains settings to make the SDHLibrary compile on differen systems:
unsigned char parameter_bytes[sizeof(float)*eNUMBER_OF_ELEMENTS+sizeof(tCRCValue)]
static char const * firmware_error_codes[]
A mapping from eErrorCode error code enums to strings with human readable error messages.
virtual void Open(void)=0
Open rs232 port port.
eVelocityProfile vp(eVelocityProfile velocity_profile=eVP_INVALID)
sSDHBinaryRequest(eCommandCode command, double *value, bool use_crc16)
Derived exception class for low-level serial communication related exceptions.
cSDHSerial(int _debug_level=0)
Constructor of cSDHSerial.
void CheckCRC16() const
check the CRC value in parameter_bytes. Throw an exception if check fails
virtual void Close(void)=0
Close the previously opened communication channel.
Class for short, fixed maximum length text messages.
Derived exception class for exceptions related to invalid parameters.
virtual ssize_t Read(void *data, ssize_t size, long timeout_us, bool return_on_less_data)=0
virtual char * readline(char *line, int size, char const *eol="\n", bool return_on_less_data=false)
Read a line from the device.
void Send(char const *s, int nb_lines=All, int nb_lines_total=All, int max_retries=3)
cSimpleVector power(int axis=All, double *flag=NULL)
cSerialBase * com
The communication object to the serial device (RS232 port or ESD CAN net)
double eps
epsilon value (max absolute deviation of reported values from actual hardware values) (needed since S...
unsigned char nb_valid_parameters
int property(char const *propname, int value)
double m_sequtime
additional time in seconds to wait for sequential execution of m command (as these are always execute...
number of elements in vector
unsigned char nb_data_bytes
int GetNbBytesToSend() const
return the total number of bytes to send
cSimpleVector kv(int axis=All, double *kv=NULL)
std::ostream & operator<<(std::ostream &stream, sSDHBinaryRequest const &request)
helper functions to insert a human readable form of the request into stream