The class to communicate with a SDH via RS232. More...
#include <sdhserial.h>
Public Member Functions | |
Internal methods | |
cSDHSerial (int _debug_level=0) | |
Constructor of cSDHSerial. More... | |
virtual | ~cSDHSerial () |
void | Open (cSerialBase *_com) |
void | Close () |
virtual bool | IsOpen (void) |
void | Send (char const *s, int nb_lines=All, int nb_lines_total=All, int max_retries=3) |
void | ExtractFirmwareState () |
double | GetDuration (char *line) |
double | get_duration (void) |
void | Sync () |
void | BinarySync (double timeout_s=0.5) |
void | SyncUnknown () |
cSimpleVector | AxisCommand (char const *command, int axis=All, double *value=NULL) |
cSimpleVector | BinaryAxisCommand (eCommandCode command, int axis=All, double *value=NULL) |
Setup and configuration methods | |
cSimpleVector | pid (int axis, double *p=NULL, double *i=NULL, double *d=NULL) |
cSimpleVector | kv (int axis=All, double *kv=NULL) |
cSimpleVector | ilim (int axis=All, double *limit=NULL) |
cSimpleVector | power (int axis=All, double *flag=NULL) |
Misc. methods | |
void | demo (bool onoff) |
int | property (char const *propname, int value) |
int | user_errors (int value) |
int | terminal (int value) |
int | debug (int value) |
Movement methods | |
cSimpleVector | v (int axis=All, double *velocity=NULL) |
cSimpleVector | tvav (int axis=All, double *velocity=NULL) |
cSimpleVector | vlim (int axis=All, double *dummy=NULL) |
cSimpleVector | alim (int axis=All, double *dummy=NULL) |
cSimpleVector | a (int axis=All, double *acceleration=NULL) |
cSimpleVector | p (int axis=All, double *angle=NULL) |
cSimpleVector | tpap (int axis=All, double *angle=NULL) |
double | m (bool sequ) |
void | stop (void) |
eVelocityProfile | vp (eVelocityProfile velocity_profile=eVP_INVALID) |
eControllerType | con (eControllerType controller) |
Diagnostic and identification methods | |
cSimpleVector | pos (int axis=All, double *dummy=NULL) |
cSimpleVector | pos_save (int axis=All, double *value=NULL) |
cSimpleVector | ref (int axis=All, double *value=NULL) |
cSimpleVector | vel (int axis=All, double *dummy=NULL) |
cSimpleVector | rvel (int axis, double *dummy=NULL) |
cSimpleVector | state (int axis=All, double *dummy=NULL) |
cSimpleVector | temp (void) |
cSimpleVector | temp_electronics (void) |
char * | ver (void) |
char * | ver_date (void) |
char * | id (void) |
char * | sn (void) |
char * | soc (void) |
char * | soc_date (void) |
int | numaxis (void) |
Grip methods | |
cSimpleVector | igrip (int axis=All, double *limit=NULL) |
cSimpleVector | ihold (int axis=All, double *limit=NULL) |
double | selgrip (eGraspId grip, bool sequ) |
double | grip (double close, double velocity, bool sequ) |
Public Member Functions inherited from cSDHBase | |
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. More... | |
void | CheckRange (double value, double minvalue, double maxvalue, char const *name="") |
Check if value is in [minvalue .. maxvalue]. Throw a cSDHErrorInvalidParameter exception if not. More... | |
void | CheckRange (double *values, double *minvalues, double *maxvalues, char const *name="") |
Check if any value[i] in array values is in [minvalue[i] .. maxvalue[i]]. Throw a cSDHErrorInvalidParameter exception if not. More... | |
cSDHBase (int debug_level) | |
double | GetEps (void) |
Return the eps value. More... | |
cSimpleVector const & | GetEpsVector (void) |
Return simple vector of number of axes epsilon values. More... | |
eErrorCode | GetFirmwareState (void) |
Return the last known state of the SDH firmware. More... | |
int | GetNumberOfAxes (void) |
Return the number of axes of the SDH. More... | |
int | GetNumberOfFingers (void) |
Return the number of fingers of the SDH. More... | |
int | GetNumberOfTemperatureSensors (void) |
Return the number of temperature sensors of the SDH. More... | |
virtual void | SetDebugOutput (std::ostream *debuglog) |
change the stream to use for debug messages More... | |
virtual | ~cSDHBase () |
Protected Attributes | |
cSerialBase * | com |
The communication object to the serial device (RS232 port or ESD CAN net) More... | |
char const * | EOL |
String to use as "End Of Line" marker when sending to SDH. More... | |
double | m_sequtime |
additional time in seconds to wait for sequential execution of m command (as these are always executed non-sequentially by the SDH firmware More... | |
int | nb_lines_to_ignore |
number of remaining reply lines of a previous (non-sequential) command More... | |
cSimpleStringList | reply |
Space for the replies from the SDH. More... | |
Protected Attributes inherited from cSDHBase | |
int | all_axes_used |
Bit field with the bits for all axes set. More... | |
cDBG | cdbg |
debug stream to print colored debug messages More... | |
int | debug_level |
debug level of this object More... | |
double | eps |
epsilon value (max absolute deviation of reported values from actual hardware values) (needed since SDH firmware limits number of digits reported) More... | |
cSimpleVector | eps_v |
simple vector of 7 epsilon values More... | |
eErrorCode | firmware_state |
the last known state of the SDH firmware More... | |
cSimpleVector | max_angle_v |
Maximum allowed axis angles (in internal units (degrees)) More... | |
cSimpleVector | min_angle_v |
simple vector of 7 0 values ??? More... | |
int | NUMBER_OF_AXES |
The number of axes. More... | |
int | NUMBER_OF_FINGERS |
The number of fingers. More... | |
int | NUMBER_OF_TEMPERATURE_SENSORS |
The number of temperature sensors. More... | |
Friends | |
struct | sSDHBinaryRequest |
struct | sSDHBinaryResponse |
Additional Inherited Members | |
Public Types inherited from cSDHBase | |
enum | { All = -1 } |
Anonymous enum (instead of define like macros) More... | |
enum | eControllerType { eCT_INVALID = -1, eCT_POSE = 0, eCT_VELOCITY, eCT_VELOCITY_ACCELERATION, eCT_DIMENSION } |
An enum for all possible SDH internal controller types (order must match that in the SDH firmware in inc/sdh2.h) More... | |
enum | eErrorCode { eEC_SUCCESS = 0, eEC_NOT_AVAILABLE, eEC_NOT_INITIALIZED, eEC_ALREADY_RUNNING, eEC_FEATURE_NOT_SUPPORTED, eEC_INCONSISTENT_DATA, eEC_TIMEOUT, eEC_READ_ERROR, eEC_WRITE_ERROR, eEC_INSUFFICIENT_RESOURCES, eEC_CHECKSUM_ERROR, eEC_NOT_ENOUGH_PARAMS, eEC_NO_PARAMS_EXPECTED, eEC_CMD_UNKNOWN, eEC_CMD_FORMAT_ERROR, eEC_ACCESS_DENIED, eEC_ALREADY_OPEN, eEC_CMD_FAILED, eEC_CMD_ABORTED, eEC_INVALID_HANDLE, eEC_DEVICE_NOT_FOUND, eEC_DEVICE_NOT_OPENED, eEC_IO_ERROR, eEC_INVALID_PARAMETER, eEC_RANGE_ERROR, eEC_NO_DATAPIPE, eEC_INDEX_OUT_OF_BOUNDS, eEC_HOMING_ERROR, eEC_AXIS_DISABLED, eEC_OVER_TEMPERATURE, eEC_MAX_COMMANDS_EXCEEDED, eEC_INVALID_PASSWORD, eEC_MAX_COMMANDLINE_EXCEEDED, eEC_CRC_ERROR, eEC_NO_COMMAND, eEC_INTERNAL, eEC_UNKNOWN_ERROR, eEC_DIMENSION } |
enum | eGraspId { eGID_INVALID = -1, eGID_CENTRICAL = 0, eGID_PARALLEL = 1, eGID_CYLINDRICAL = 2, eGID_SPHERICAL = 3, eGID_DIMENSION } |
The enum values of the known grasps. More... | |
enum | eVelocityProfile { eVP_INVALID = -1, eVP_SIN_SQUARE, eVP_RAMP, eVP_DIMENSION } |
An enum for all possible SDH internal velocity profile types. More... | |
Static Public Member Functions inherited from cSDHBase | |
static char const * | GetStringFromControllerType (eControllerType controller_type) |
Return a ptr to a (static) string describing controller type controller_Type. More... | |
static char const * | GetStringFromErrorCode (eErrorCode error_code) |
Return a ptr to a (static) string describing error code error_code. More... | |
static char const * | GetStringFromGraspId (eGraspId grasp_id) |
Return a ptr to a (static) string describing grasp id grasp_id. More... | |
Static Protected Attributes inherited from cSDHBase | |
static char const * | controller_type_name [] |
A mapping from eControllerType controller type enums to strings with human readable controller type names. More... | |
static char const * | firmware_error_codes [] |
A mapping from eErrorCode error code enums to strings with human readable error messages. More... | |
static char const * | grasp_id_name [] |
A mapping from eGraspId grasp id enums to strings with human readable grasp id names. More... | |
The class to communicate with a SDH via RS232.
End-Users should NOT use this class directly! The interface of cSDHSerial is subject to change in future releases. End users should use the class cSDH instead, as that interface is considered more stable.
Definition at line 91 of file sdhserial.h.
cSDHSerial::cSDHSerial | ( | int | _debug_level = 0 | ) |
Constructor of cSDHSerial.
_debug_level | : debug level of the created object. If the debug_level of an object is > 0 then it will output debug messages. (forwared to constructor of base class) |
String to use as "End Of Line" marker when sending to SDH
Definition at line 238 of file sdhserial.cpp.
|
inlinevirtual |
virtual destructor to make compiler happy
Definition at line 143 of file sdhserial.h.
cSimpleVector cSDHSerial::a | ( | int | axis = All , |
double * | acceleration = NULL |
||
) |
Get/Set target acceleration for axis. (NOT the actual acceleration!)
Accelerations are set/reported in degrees per second squared.
Definition at line 952 of file sdhserial.cpp.
cSimpleVector cSDHSerial::alim | ( | int | axis = All , |
double * | dummy = NULL |
||
) |
Get acceleration limits.
dummy parameter is just needed to make this function have the same signature as e.g. v(), so it can be used as a function pointer.
Acceleration limits are reported in degrees per (second*second).
Definition at line 945 of file sdhserial.cpp.
cSimpleVector cSDHSerial::AxisCommand | ( | char const * | command, |
int | axis = All , |
||
double * | value = NULL |
||
) |
Get/Set values.
Definition at line 641 of file sdhserial.cpp.
cSimpleVector cSDHSerial::BinaryAxisCommand | ( | eCommandCode | command, |
int | axis = All , |
||
double * | value = NULL |
||
) |
Get/Set values using binary mode.
Definition at line 725 of file sdhserial.cpp.
void cSDHSerial::BinarySync | ( | double | timeout_s = 0.5 | ) |
Read all available bytes within timeout_s seconds to resync execution of PC and SDH.
Definition at line 607 of file sdhserial.cpp.
void cSDHSerial::Close | ( | void | ) |
Close connection to serial port.
Definition at line 374 of file sdhserial.cpp.
cSDHBase::eControllerType cSDHSerial::con | ( | eControllerType | controller | ) |
Get/set controller type.
If controller is < 0 then the actually set controller is read from the SDH firmware and returned. Else the given controller type is set in the SDH firmware if valid.
Definition at line 1049 of file sdhserial.cpp.
int cSDHSerial::debug | ( | int | value | ) |
Definition at line 909 of file sdhserial.cpp.
void cSDHSerial::demo | ( | bool | onoff | ) |
Enable/disable SCHUNK demo
Definition at line 878 of file sdhserial.cpp.
void cSDHSerial::ExtractFirmwareState | ( | ) |
Try to extract the state of the SDH firmware from the last reply
Definition at line 518 of file sdhserial.cpp.
double cSDHSerial::get_duration | ( | void | ) |
Send get_duration command. Returns the calculated duration of the currently configured movement (target positions, velocities, accelerations and velocity profile.
return the expected duration of the execution of the command in seconds
Definition at line 562 of file sdhserial.cpp.
double cSDHSerial::GetDuration | ( | char * | line | ) |
Return duration of the execution of a SDH command as reported by line
Definition at line 546 of file sdhserial.cpp.
double cSDHSerial::grip | ( | double | close, |
double | velocity, | ||
bool | sequ | ||
) |
send "grip=close,velocity" command to SDH close : [0.0 .. 1.0] where 0.0 is 'fully opened' and 1.0 is 'fully closed' velocity : ]0.0 .. 100.0] where 0.0 (not allowed) is very slow and 100.0 is very fast
If sequ is True then wait until SDH hardware fully executed the command. Else return immediately and do not wait until SDH hardware fully executed the command.
This seems to work with sin square velocity profile only, so the velocity profile is switched to that if necessary.
return the expected duration of the execution of the command in seconds
Definition at line 1277 of file sdhserial.cpp.
char * cSDHSerial::id | ( | void | ) |
Return id of SDH
Definition at line 1172 of file sdhserial.cpp.
cSimpleVector cSDHSerial::igrip | ( | int | axis = All , |
double * | limit = NULL |
||
) |
Get/Set motor current limits for grip commands
Definition at line 1215 of file sdhserial.cpp.
cSimpleVector cSDHSerial::ihold | ( | int | axis = All , |
double * | limit = NULL |
||
) |
Get/Set motor current limits for hold commands
Definition at line 1222 of file sdhserial.cpp.
cSimpleVector cSDHSerial::ilim | ( | int | axis = All , |
double * | limit = NULL |
||
) |
Get/Set actual motor current limit for m command
Definition at line 851 of file sdhserial.cpp.
|
virtual |
Return true if connection to SDH firmware/hardware is open
Implements cSDHBase.
Definition at line 381 of file sdhserial.cpp.
cSimpleVector cSDHSerial::kv | ( | int | axis = All , |
double * | kv = NULL |
||
) |
Get/Set kv parameter
Definition at line 820 of file sdhserial.cpp.
double cSDHSerial::m | ( | bool | sequ | ) |
Send move command. Moves all enabled axes to their previously set target angle. The movement duration is determined by that axis that takes longest with its actually set velocity. The actual velocity of all other axes is set so that all axes begin and end their movements synchronously.
If sequ is True then wait until SDH hardware fully executed the command. Else return immediately and do not wait until SDH hardware fully executed the command.
return the expected duration of the execution of the command in seconds
Definition at line 985 of file sdhserial.cpp.
int cSDHSerial::numaxis | ( | void | ) |
Return number of axis of SDH
Definition at line 1204 of file sdhserial.cpp.
void cSDHSerial::Open | ( | cSerialBase * | _com | ) |
Open the serial device and check connection to SDH by querying the SDH firmware version
_com | - ptr to the serial device to use |
This may throw an exception on failure.
The serial port on the PC-side can be opened successfully even if no SDH is attached. Therefore this routine tries to read the SDH firmware version with a 1s timeout after the port is opened. If the SDH does not reply in time then
Definition at line 293 of file sdhserial.cpp.
cSimpleVector cSDHSerial::p | ( | int | axis = All , |
double * | angle = NULL |
||
) |
Get/Set target angle for axis. (NOT the actual angle!)
Angles are set/reported in degrees.
Definition at line 963 of file sdhserial.cpp.
cSimpleVector cSDHSerial::pid | ( | int | axis, |
double * | p = NULL , |
||
double * | i = NULL , |
||
double * | d = NULL |
||
) |
Get/Set PID controller parameters
Definition at line 800 of file sdhserial.cpp.
cSimpleVector cSDHSerial::pos | ( | int | axis = All , |
double * | dummy = NULL |
||
) |
Get actual angle/s of axis/axes.
Angles are reported in degrees.
Definition at line 1068 of file sdhserial.cpp.
cSimpleVector cSDHSerial::pos_save | ( | int | axis = All , |
double * | value = NULL |
||
) |
Save actual angle/s to non volatile memory. (Usefull for axes that dont have an absolute encoder)
Definition at line 1078 of file sdhserial.cpp.
cSimpleVector cSDHSerial::power | ( | int | axis = All , |
double * | flag = NULL |
||
) |
Get/Set actual power state
Definition at line 862 of file sdhserial.cpp.
int cSDHSerial::property | ( | char const * | propname, |
int | value | ||
) |
Set named property
Valid propnames are:
Definition at line 885 of file sdhserial.cpp.
cSimpleVector cSDHSerial::ref | ( | int | axis = All , |
double * | value = NULL |
||
) |
Do reference movements with selected axes. (Usefull for axes that dont have an absolute encoder)
each value must be either
Definition at line 1085 of file sdhserial.cpp.
cSimpleVector cSDHSerial::rvel | ( | int | axis, |
double * | dummy = NULL |
||
) |
Get current reference angular velocity/s of axis/axes. The reference angular velocity is used by the eCT_VELOCITY_ACCELERATION controller type only.
Angular velocities are reported in degrees/second.
Definition at line 1107 of file sdhserial.cpp.
double cSDHSerial::selgrip | ( | eGraspId | grip, |
bool | sequ | ||
) |
Send "selgrip grip" command to SDH. Where grip is in [0..eGID_DIMENSION-1] or one of the eGraspId enums.
If sequ is True then wait until SDH hardware fully executed the command. Else return immediately and do not wait until SDH hardware fully executed the command.
This seems to work with sin square velocity profile only, so the velocity profile is switched to that if necessary.
return the expected duration of the execution of the command in seconds
Definition at line 1229 of file sdhserial.cpp.
void cSDHSerial::Send | ( | char const * | s, |
int | nb_lines = All , |
||
int | nb_lines_total = All , |
||
int | max_retries = 3 |
||
) |
Send command string s+EOL to com and read reply according to nb_lines.
If nb_lines == All then reply lines are read until a line without "@" prefix is found. If nb_lines != All it is the number of lines to read.
firmware_state is set according to reply (if read) nb_lines_total contains the total number of lines replied for the s command. If fewer lines are read then nb_lines_total-nb_lines will be remembered to be ignored before the next command can be sent.
Return a list of all read lines of the reply from the SDH hardware.
Definition at line 389 of file sdhserial.cpp.
char * cSDHSerial::sn | ( | void | ) |
Return sn of SDH
Definition at line 1180 of file sdhserial.cpp.
char * cSDHSerial::soc | ( | void | ) |
Return soc (System On Chip) ID of SDH
Definition at line 1188 of file sdhserial.cpp.
char * cSDHSerial::soc_date | ( | void | ) |
Return date of soc (System On Chip) ID of SDH
Definition at line 1196 of file sdhserial.cpp.
cSimpleVector cSDHSerial::state | ( | int | axis = All , |
double * | dummy = NULL |
||
) |
Get actual state/s of axis/axes.
A state of 0 means "not moving" while 1 means "moving".
Definition at line 1118 of file sdhserial.cpp.
void cSDHSerial::stop | ( | void | ) |
Stop sdh.
Will NOT interrupt a previous "selgrip" or "grip" command, only an "m" command!
Definition at line 1023 of file sdhserial.cpp.
void cSDHSerial::Sync | ( | ) |
Read all pending lines from SDH to resync execution of PC and SDH.
Definition at line 591 of file sdhserial.cpp.
void cSDHSerial::SyncUnknown | ( | ) |
Read an unknown number of lines from SDH to resync execution of PC and SDH.
Definition at line 616 of file sdhserial.cpp.
cSimpleVector cSDHSerial::temp | ( | void | ) |
Get actual temperatures of the axis motors
Returns a list of the actual controller and driver temperature in degrees celsius.
Definition at line 1129 of file sdhserial.cpp.
cSimpleVector cSDHSerial::temp_electronics | ( | void | ) |
Get actual temperatures of the electronics, i.e. teh FPGA and the PCB. (FPGA = Field Programmable Gate Array = the reprogrammable chip with the soft processors) (PCB = Printed Circuit Board)
Returns a list of the actual controller and driver temperature in degrees celsius.
Definition at line 1141 of file sdhserial.cpp.
int cSDHSerial::terminal | ( | int | value | ) |
Definition at line 902 of file sdhserial.cpp.
cSimpleVector cSDHSerial::tpap | ( | int | axis = All , |
double * | angle = NULL |
||
) |
Set target angle and get actual angle for axis.
Angles are set/reported in degrees.
Definition at line 974 of file sdhserial.cpp.
cSimpleVector cSDHSerial::tvav | ( | int | axis = All , |
double * | velocity = NULL |
||
) |
Set target velocity and get actual velocity!)
The default velocity is 40 deg/s for axes 0-6 in eCT_POSE controller type. The default velocity is 0.0 deg/s for axes 0-6 in eCT_VELOCITY and eCT_VELOCITY_ACCELERATION controller types.
Velocities are set/reported in degrees per second.
Definition at line 927 of file sdhserial.cpp.
int cSDHSerial::user_errors | ( | int | value | ) |
Definition at line 895 of file sdhserial.cpp.
cSimpleVector cSDHSerial::v | ( | int | axis = All , |
double * | velocity = NULL |
||
) |
Get/Set target velocity. (NOT the actual velocity!)
The default velocity is 40 deg/s for axes 0-6 in eCT_POSE controller type. The default velocity is 0.0 deg/s for axes 0-6 in eCT_VELOCITY and eCT_VELOCITY_ACCELERATION controller types.
Velocities are set/reported in degrees per second.
Definition at line 916 of file sdhserial.cpp.
cSimpleVector cSDHSerial::vel | ( | int | axis = All , |
double * | dummy = NULL |
||
) |
Get actual angular velocity/s of axis/axes.
Angular velocities are reported in degrees/second.
Definition at line 1096 of file sdhserial.cpp.
char * cSDHSerial::ver | ( | void | ) |
Return version of SDH firmware
Definition at line 1156 of file sdhserial.cpp.
char * cSDHSerial::ver_date | ( | void | ) |
Return date of SDH firmware
Definition at line 1164 of file sdhserial.cpp.
cSimpleVector cSDHSerial::vlim | ( | int | axis = All , |
double * | dummy = NULL |
||
) |
Get velocity limits.
dummy parameter is just needed to make this function have the same signature as e.g. v(), so it can be used as a function pointer.
Velocity limits are reported in degrees per second.
Definition at line 938 of file sdhserial.cpp.
cSDHBase::eVelocityProfile cSDHSerial::vp | ( | eVelocityProfile | velocity_profile = eVP_INVALID | ) |
Get/set velocity profile.
If velocity_profile is < 0 then the actually set velocity profile is read from the SDH firmware and returned. Else the given velocity_profile type is set in the SDH firmware if valid.
Definition at line 1030 of file sdhserial.cpp.
|
friend |
Definition at line 93 of file sdhserial.h.
|
friend |
Definition at line 94 of file sdhserial.h.
|
protected |
The communication object to the serial device (RS232 port or ESD CAN net)
Definition at line 108 of file sdhserial.h.
|
protected |
String to use as "End Of Line" marker when sending to SDH.
Definition at line 105 of file sdhserial.h.
|
protected |
additional time in seconds to wait for sequential execution of m command (as these are always executed non-sequentially by the SDH firmware
Definition at line 102 of file sdhserial.h.
|
protected |
number of remaining reply lines of a previous (non-sequential) command
Definition at line 115 of file sdhserial.h.
|
protected |
Space for the replies from the SDH.
Definition at line 112 of file sdhserial.h.