sdhbase.cpp
Go to the documentation of this file.
1 //======================================================================
28 //======================================================================
29 
30 //----------------------------------------------------------------------
31 // System Includes - include with <>
32 //----------------------------------------------------------------------
33 
34 
35 //----------------------------------------------------------------------
36 // Project Includes - include with ""
37 //----------------------------------------------------------------------
38 
39 #include "sdhbase.h"
40 #include "util.h"
41 
43 
44 //----------------------------------------------------------------------
45 // Defines, enums, unions, structs,
46 //----------------------------------------------------------------------
47 
48 
49 //----------------------------------------------------------------------
50 // Global variables
51 //----------------------------------------------------------------------
52 
54 
55 std::ostream* g_sdh_debug_log = &std::cerr;
56 
58 
59 //----------------------------------------------------------------------
60 // Function implementation (function definitions)
61 //----------------------------------------------------------------------
62 
63 //----------------------------------------------------------------------
64 // Class member definitions
65 //----------------------------------------------------------------------
66 
67 char const* cSDHBase::firmware_error_codes[] =
68  {
69  // Order DOES matter here. The order must match that of the eErrorCode enums.
70  "eEC_SUCCESS: No error",
71  "eEC_NOT_AVAILABLE: Service or data is not available",
72  "eEC_NOT_INITIALIZED: The device is not initialized",
73  "eEC_ALREADY_RUNNING: Data acquisition: the acquisition loop is already running",
74  "eEC_FEATUReEC_NOT_SUPPORTED: The asked feature is not supported",
75  "eEC_INCONSISTENT_DATA: One or more dependent parameters mismatch",
76  "eEC_TIMEOUT: Timeout error",
77  "eEC_READ_ERROR: Error while reading from a device",
78  "eEC_WRITE_ERROR: Error while writing to a device",
79  "eEC_INSUFFICIENT_RESOURCES: No memory available",
80  "eEC_CHECKSUM_ERROR: Checksum error",
81  "eEC_NOT_ENOUGH_PARAMS: Not enough parameters",
82  "eEC_NO_PARAMS_EXPECTED: No parameters expected",
83  "eEC_CMD_UNKNOWN: Unknown command",
84  "eEC_CMD_FORMAT_ERROR: Command format error",
85  "eEC_ACCESS_DENIED: Access denied",
86  "eEC_ALREADY_OPEN: Interface already open",
87  "eEC_CMD_FAILED: Command failed",
88  "eEC_CMD_ABORTED: Command aborted",
89  "eEC_INVALID_HANDLE: Invalid handle",
90  "eEC_DEVICE_NOT_FOUND: Device not found",
91  "eEC_DEVICE_NOT_OPENED: Device not open",
92  "eEC_IO_ERROR: General I/O-Error",
93  "eEC_INVALID_PARAMETER: Invalid parameter",
94  "eEC_RANGE_ERROR: Range error",
95  "eEC_NO_DATAPIPE: No datapipe was found to open the specified device path",
96  "eEC_INDEX_OUT_OF_BOUNDS: The passed index is out of bounds",
97  "eEC_HOMING_ERROR: Error while homing",
98  "eEC_AXIS_DISABLED: The selected axis is disabled",
99  "eEC_OVER_TEMPERATURE: Over-temperature",
100  "eEC_MAX_COMMANDS_EXCEEDED: E_MAX_COMMANDS_EXCEEDED: cannot add more than CI_MAX_COMMANDS to interpreter / POSCON_MAX_OSCILLOSCOPE parameters to oscilloscope",
101  "eEC_INVALID_PASSWORD: E_INVALID_PASSWORD: invalid password given for change user command",
102  "eEC_MAX_COMMANDLINE_EXCEEDEDE_COMMANDLINE_EXCEEDED: the command line given is too long",
103  "eEC_CRC_ERROR: Cyclic Redundancy Code error",
104  "eEC_NO_COMMAND: No command available",
105 
106  "eEC_INTERNAL: internal error",
107  "eEC_UNKNOWN_ERROR: unknown error",
108 
109  "eEC_DIMENSION: Number of error codes"
110  };
111 
112 char const* cSDHBase::grasp_id_name[] =
113  {
114  // Order DOES matter here. The order must match that of the eGraspId enums.
115  "eGID_CENTRICAL: centrical grasp",
116  "eGID_PARALLEL: parallel grasp",
117  "eGID_CYLINDRICAL: cylindrical grasp",
118  "eGID_SPHERICAL: spherecial grasp",
119 
120  "eGID_DIMENSION: number of predefined grasp ids"
121  };
122 
123 
124 char const* cSDHBase::controller_type_name[] =
125  {
126  // Order DOES matter here. The order must match that of the eErrorCode enums.
127  "eCT_POSE: position/pose controller coordinated",
128  "eCT_VELOCITY: velocity controller",
129  "eCT_VELOCITY_ACCELERATION: velocity with acceleration ramp controller",
130 
131  //"eCT_POSITION: position controller, all axes independent",
132 
133  "eCT_DIMENSION: number of controller types"
134  };
135 //-----------------------------------------------------------------
136 
137 cSDHBase::cSDHBase( int _debug_level ) :
138 
139  // init members:
140  cdbg( (_debug_level > 0), "magenta", g_sdh_debug_log ),
141  debug_level(_debug_level),
142  NUMBER_OF_AXES( 7 ),
143  NUMBER_OF_FINGERS( 3 ),
144  NUMBER_OF_TEMPERATURE_SENSORS( 9 )
145 {
146  cdbg << "Constructing cSDHBASE object\n";
147 
148 
149  all_axes_used = (1<<NUMBER_OF_AXES)-1;
150 
152 
153  eps = 0.5; // !!!
154 
155  for ( int i=0; i < NUMBER_OF_AXES; i++ )
156  {
157  eps_v[i] = eps;
158 
159  //zeros_v[i] = 0.0;
160  //ones_v[i] = 1.0;
161 
162  min_angle_v[i] = (i==0)? 0.0 : -90.0;
163  max_angle_v[i] = 90.0;
164  }
165 }
166 //-----------------------------------------------------------------
167 
168 
169 void cSDHBase::CheckIndex( int index, int maxindex, char const* name )
170 {
171  if (index < 0 || maxindex <= index)
172  throw new cSDHErrorInvalidParameter( cMsg( "Invalid %s index %d (not in range [0..%d[)", name, index, maxindex ) );
173 }
174 //-----------------------------------------------------------------
175 
176 
177 void cSDHBase::CheckRange( double value, double minvalue, double maxvalue, char const* name )
178 {
179  if (! InRange(value, minvalue, maxvalue) )
180  throw new cSDHErrorInvalidParameter( cMsg( "Invalid %s value (%f not in range [%f..%f])", name, value, minvalue, maxvalue ) );
181 }
182 //-----------------------------------------------------------------
183 
184 
185 void cSDHBase::CheckRange( double* values, double* minvalues, double* maxvalues, char const* name )
186 {
187  for ( int i=0; i < NUMBER_OF_AXES; i++ )
188  {
189  if (! InRange(values[i],minvalues[i],maxvalues[i]) )
190  throw new cSDHErrorInvalidParameter( cMsg( "Invalid %s value in vector (values[%d]=%f not in range [%f..%f])", name, i, values[i], minvalues[i], maxvalues[i] ) );
191  }
192 }
193 //-----------------------------------------------------------------
194 
195 
197 {
198  if ( 0 <= error_code && error_code < eEC_DIMENSION )
200  else
201  return "invalid error code";
202 }
203 //----------------------------------------------------------------------
204 
205 
207 {
208  if ( eGID_INVALID < grasp_id && grasp_id < eGID_DIMENSION )
209  return grasp_id_name[ grasp_id ];
210  else
211  return "invalid gasp id";
212 }
213 //----------------------------------------------------------------------
214 
215 
217 {
218  if ( eCT_INVALID < controller_type && controller_type < eCT_DIMENSION )
219  return controller_type_name[ controller_type ];
220  else
221  return "invalid controller type";
222 }
223 //----------------------------------------------------------------------
224 
225 
227 {
228  return NUMBER_OF_AXES;
229 }
230 //----------------------------------------------------------------------
231 
232 
234 {
235  return NUMBER_OF_FINGERS;
236 }
237 //----------------------------------------------------------------------
238 
239 
241 {
243 }
244 //----------------------------------------------------------------------
245 
246 
248 {
249  return firmware_state;
250 }
251 //----------------------------------------------------------------------
252 
253 
254 double cSDHBase::GetEps( void )
255 {
256  return eps;
257 }
258 //----------------------------------------------------------------------
259 
260 
262 {
263  return eps_v;
264 }
265 //----------------------------------------------------------------------
266 
267 
268 //======================================================================
269 /*
270  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
271  (e.g. to explicitely set C++ mode for *.h header files)
272 
273  Local Variables:
274  mode:C++
275  mode:ELSE
276  End:
277 */
278 //======================================================================
static char const * GetStringFromGraspId(eGraspId grasp_id)
Return a ptr to a (static) string describing grasp id grasp_id.
Definition: sdhbase.cpp:206
static char const * firmware_error_codes[]
A mapping from eErrorCode error code enums to strings with human readable error messages.
Definition: sdhbase.h:285
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...
Definition: sdhbase.cpp:169
eGraspId
The enum values of the known grasps.
Definition: sdhbase.h:162
Endmarker and dimension.
Definition: sdhbase.h:186
A simple vector implementation.
Definition: simplevector.h:91
int GetNumberOfFingers(void)
Return the number of fingers of the SDH.
Definition: sdhbase.cpp:233
Endmarker and dimension.
Definition: sdhbase.h:171
UInt16 error_code
0000h, if successful, otherwise error code
Definition: dsa.h:116
cSDHBase(int debug_level)
Definition: sdhbase.cpp:137
int GetNumberOfAxes(void)
Return the number of axes of the SDH.
Definition: sdhbase.cpp:226
eErrorCode firmware_state
the last known state of the SDH firmware
Definition: sdhbase.h:309
cSimpleVector min_angle_v
simple vector of 7 0 values ???
Definition: sdhbase.h:327
bool InRange(double v, double min, double max)
Definition: util.cpp:80
#define NAMESPACE_SDH_START
int NUMBER_OF_AXES
The number of axes.
Definition: sdhbase.h:297
static char const * controller_type_name[]
A mapping from eControllerType controller type enums to strings with human readable controller type n...
Definition: sdhbase.h:293
int GetNumberOfTemperatureSensors(void)
Return the number of temperature sensors of the SDH.
Definition: sdhbase.cpp:240
double GetEps(void)
Return the eps value.
Definition: sdhbase.cpp:254
int NUMBER_OF_TEMPERATURE_SENSORS
The number of temperature sensors.
Definition: sdhbase.h:303
int NUMBER_OF_FINGERS
The number of fingers.
Definition: sdhbase.h:300
Interface of auxilliary utility functions for SDHLibrary-CPP.
invalid grasp id
Definition: sdhbase.h:165
invalid controller_type (needed for cSDHSerial::con() to indicate "read current controller type") ...
Definition: sdhbase.h:178
void CheckRange(double value, double minvalue, double maxvalue, char const *name="")
Check if value is in [minvalue .. maxvalue]. Throw a cSDHErrorInvalidParameter exception if not...
Definition: sdhbase.cpp:177
eControllerType
An enum for all possible SDH internal controller types (order must match that in the SDH firmware in ...
Definition: sdhbase.h:176
cDBG cdbg
debug stream to print colored debug messages
Definition: sdhbase.h:279
cSimpleVector eps_v
simple vector of 7 epsilon values
Definition: sdhbase.h:318
Endmarker and dimension.
Definition: sdhbase.h:153
cSimpleVector const & GetEpsVector(void)
Return simple vector of number of axes epsilon values.
Definition: sdhbase.cpp:261
eErrorCode
Definition: sdhbase.h:112
Interface of class #SDH::cSDHBase.
#define USING_NAMESPACE_SDH
int all_axes_used
Bit field with the bits for all axes set.
Definition: sdhbase.h:306
static char const * GetStringFromErrorCode(eErrorCode error_code)
Return a ptr to a (static) string describing error code error_code.
Definition: sdhbase.cpp:196
#define NAMESPACE_SDH_END
static char const * GetStringFromControllerType(eControllerType controller_type)
Return a ptr to a (static) string describing controller type controller_Type.
Definition: sdhbase.cpp:216
eErrorCode GetFirmwareState(void)
Return the last known state of the SDH firmware.
Definition: sdhbase.cpp:247
USING_NAMESPACE_SDH NAMESPACE_SDH_START std::ostream * g_sdh_debug_log
Definition: sdhbase.cpp:55
Class for short, fixed maximum length text messages.
Definition: sdhexception.h:77
Derived exception class for exceptions related to invalid parameters.
Definition: sdhbase.h:78
static char const * grasp_id_name[]
A mapping from eGraspId grasp id enums to strings with human readable grasp id names.
Definition: sdhbase.h:289
double eps
epsilon value (max absolute deviation of reported values from actual hardware values) (needed since S...
Definition: sdhbase.h:315
cSimpleVector max_angle_v
Maximum allowed axis angles (in internal units (degrees))
Definition: sdhbase.h:330
cDBG cdbg(false, "red")


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Mon Feb 28 2022 23:41:51