00001
00030
00031
00032 #ifndef SDH_h_
00033 #define SDH_h_
00034
00035 #include "sdhlibrary_settings.h"
00036 #include "basisdef.h"
00037
00038 #if SDH_USE_VCC
00039 # pragma warning(disable : 4996)
00040 #endif
00041
00042
00043
00044
00045
00046 #include <vector>
00047 #include <string>
00048
00049
00050
00051
00052
00053 #include "sdhbase.h"
00054 #include "sdhserial.h"
00055 #include "unit_converter.h"
00056 #include "serialbase.h"
00057 #if WITH_ESD_CAN
00058 # include "canserial-esd.h"
00059 #endif
00060
00061 #if WITH_PEAK_CAN
00062 # include "canserial-peak.h"
00063 #endif
00064
00065
00066
00067
00068
00069 #if SDH_USE_NAMESPACE
00070
00077 #endif
00078
00079 NAMESPACE_SDH_START
00080
00081 #if ! WITH_ESD_CAN
00082 typedef void* NTCAN_HANDLE;
00083 #endif
00084
00085 #if ! WITH_PEAK_CAN
00086
00087 typedef void* PCAN_HANDLE;
00088 #endif
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00166 class cSDH : public cSDHBase
00167 {
00168 public:
00169
00171 enum eMotorCurrentMode
00172 {
00173 eMCM_MOVE=0,
00174 eMCM_GRIP=1,
00175 eMCM_HOLD=2,
00176
00177 eMCM_DIMENSION
00178 };
00179
00180
00182 enum eAxisState
00183 {
00184 eAS_IDLE = 0,
00185 eAS_POSITIONING,
00186 eAS_SPEED_MODE,
00187 eAS_NOT_INITIALIZED,
00188 eAS_CW_BLOCKED,
00189 eAS_CCW_BLOCKED,
00190 eAS_DISABLED,
00191 eAS_LIMITS_REACHED,
00192
00193 eAS_DIMENSION
00194 };
00195
00196
00197
00213
00214 static cUnitConverter const uc_angle_degrees;
00215
00217 static cUnitConverter const uc_angle_radians;
00218
00220 static cUnitConverter const uc_time_seconds;
00221
00223 static cUnitConverter const uc_time_milliseconds;
00224
00226 static cUnitConverter const uc_temperature_celsius;
00227
00229 static cUnitConverter const uc_temperature_fahrenheit;
00230
00232 static cUnitConverter const uc_angular_velocity_degrees_per_second;
00233
00235 static cUnitConverter const uc_angular_velocity_radians_per_second;
00236
00238 static cUnitConverter const uc_angular_acceleration_degrees_per_second_squared;
00239
00241 static cUnitConverter const uc_angular_acceleration_radians_per_second_squared;
00242
00244 static cUnitConverter const uc_motor_current_ampere;
00245
00247 static cUnitConverter const uc_motor_current_milliampere;
00248
00250 static cUnitConverter const uc_position_millimeter;
00251
00253 static cUnitConverter const uc_position_meter;
00254
00255
00256
00258
00259 protected:
00260
00261
00262
00264 int NUMBER_OF_AXES_PER_FINGER;
00265
00266
00268 int NUMBER_OF_VIRTUAL_AXES;
00269
00271 int nb_all_axes;
00272
00274 std::vector<int> finger_number_of_axes;
00275
00276
00278 std::vector<std::vector<int> > finger_axis_index;
00279
00281
00282
00284 std::vector<double> f_zeros_v;
00285
00287 std::vector<double> f_ones_v;
00288
00289
00291 std::vector<double> zeros_v;
00292
00294 std::vector<double> ones_v;
00295
00296
00298 std::vector<double> f_min_motor_current_v;
00299
00301 std::vector<double> f_max_motor_current_v;
00302
00303
00304
00306 std::vector<double> f_min_angle_v;
00307
00309 std::vector<double> f_max_angle_v;
00310
00312 std::vector<double> f_min_velocity_v;
00313
00315 std::vector<double> f_max_velocity_v;
00316
00318 std::vector<double> f_min_acceleration_v;
00319
00321 std::vector<double> f_max_acceleration_v;
00322
00324 double grip_max_velocity;
00325
00333
00334 double l1;
00335
00337 double l2;
00338
00339
00340 double d;
00341
00342
00343 double h;
00344
00349 std::vector<std::vector<double> > offset;
00350
00351 cSerialBase* com;
00352
00353
00354 public:
00356 cSDHSerial comm_interface;
00357
00359 virtual void SetDebugOutput( std::ostream* debuglog )
00360 {
00361 cSDHBase::SetDebugOutput( debuglog );
00362 comm_interface.SetDebugOutput( debuglog );
00363 }
00364
00365 protected:
00366
00367
00375
00402 void SetAxisValueVector( std::vector<int> const& axes,
00403 std::vector<double> const& values,
00404 pSetFunction ll_set,
00405 pGetFunction ll_get,
00406 cUnitConverter const* uc,
00407 std::vector<double> const& min_values,
00408 std::vector<double> const& max_values,
00409 char const* name )
00410 throw (cSDHLibraryException*);
00411
00412
00413
00434 std::vector<double> GetAxisValueVector( std::vector<int> const& axes,
00435 pGetFunction ll_get,
00436 cUnitConverter const* uc,
00437 char const* name )
00438 throw (cSDHLibraryException*);
00439
00440
00456 std::vector<int> ToIndexVector( int index, std::vector<int>& all_replacement, int maxindex, char const* name )
00457 throw (cSDHLibraryException*);
00458
00459
00460
00466 pSetFunction GetMotorCurrentModeFunction( eMotorCurrentMode mode )
00467 throw(cSDHLibraryException*);
00468
00469
00470
00474 std::vector<double> _GetFingerXYZ( int fi, std::vector<double> r_angles )
00475 throw(cSDHLibraryException*);
00476
00477
00478
00480
00481
00482
00483 public:
00484
00492
00493 std::vector<int> all_axes;
00494
00496 std::vector<int> all_real_axes;
00497
00499 std::vector<int> all_fingers;
00500
00502 std::vector<int> all_temperature_sensors;
00503
00504
00506
00507
00508
00509
00533
00534 const cUnitConverter* uc_angle;
00535
00536
00538 const cUnitConverter* uc_angular_velocity;
00539
00540
00542 const cUnitConverter* uc_angular_acceleration;
00543
00544
00546 const cUnitConverter* uc_time;
00547
00548
00550 const cUnitConverter* uc_temperature;
00551
00552
00554 const cUnitConverter* uc_motor_current;
00555
00556
00558 const cUnitConverter* uc_position;
00559
00560
00561
00563
00564
00565
00566
00650 cSDH( bool _use_radians=false, bool _use_fahrenheit=false, int _debug_level=0 );
00651
00652
00653
00661 virtual ~cSDH();
00662
00663
00664
00672
00674 bool IsVirtualAxis( int iAxis )
00675 throw (cSDHLibraryException*);
00676
00677
00695 void UseRadians( void );
00696
00697
00698
00718 void UseDegrees( void );
00719
00720
00721
00741 int GetFingerNumberOfAxes( int iFinger )
00742 throw (cSDHLibraryException*);
00743
00744
00745
00769 int GetFingerAxisIndex( int iFinger, int iFingerAxis )
00770 throw (cSDHLibraryException*);
00771
00772
00773
00788 static char const* GetLibraryRelease( void );
00789
00790
00791
00806 static char const* GetLibraryName( void );
00807
00808
00809
00826 char const* GetFirmwareRelease( void )
00827 throw (cSDHLibraryException*);
00828
00855 char const* GetInfo( char const* what )
00856 throw (cSDHLibraryException*);
00857
00858
00911 std::vector<double> GetTemperature( std::vector<int> const& sensors )
00912 throw (cSDHLibraryException*);
00913
00914
00915
00920 double GetTemperature( int iSensor )
00921 throw (cSDHLibraryException*);
00922
00923
00924
00926
00927
00928
00929
00937
00972 void OpenRS232( int _port=0, unsigned long _baudrate = 115200, double _timeout=-1, char const* _device_format_string="/dev/ttyS%d" )
00973 throw (cSDHLibraryException*);
00974
00975
01003 void OpenCAN_ESD( int _net=0, unsigned long _baudrate=1000000, double _timeout=0.0, Int32 _id_read=43, Int32 _id_write=42 )
01004 throw (cSDHLibraryException*);
01005
01006
01035 void OpenCAN_ESD( NTCAN_HANDLE _ntcan_handle, double _timeout=0.0, Int32 _id_read=43, Int32 _id_write=42 )
01036 throw (cSDHLibraryException*);
01037
01038
01066 void OpenCAN_PEAK( unsigned long _baudrate=1000000, double _timeout=0.0, Int32 _id_read=43, Int32 _id_write=42, const char *device="/dev/pcanusb0" )
01067 throw (cSDHLibraryException*);
01068
01069
01099 void OpenCAN_PEAK( PCAN_HANDLE _handle, double _timeout=0.0, Int32 _id_read=43, Int32 _id_write=42 )
01100 throw (cSDHLibraryException*);
01101
01102
01103
01134 void Close( bool leave_enabled=false )
01135 throw (cSDHLibraryException*);
01136
01137
01141 virtual bool IsOpen( void )
01142 throw ();
01143
01144
01145
01147
01148
01149
01150
01158
01180 void EmergencyStop( void )
01181 throw (cSDHLibraryException*);
01182
01183
01184
01215 void Stop( void )
01216 throw (cSDHLibraryException*);
01217
01218
01219
01220
01221
01222
01223
01224
01274 void SetController( cSDHBase::eControllerType controller )
01275 throw( cSDHLibraryException* );
01276
01277
01299 eControllerType GetController( void )
01300 throw (cSDHLibraryException*);
01301
01302
01323 void SetVelocityProfile( eVelocityProfile velocity_profile )
01324 throw (cSDHLibraryException*);
01325
01326
01327
01346 eVelocityProfile GetVelocityProfile( void )
01347 throw (cSDHLibraryException*);
01348
01349
01350
01352
01353
01354
01355
01363
01436 void SetAxisMotorCurrent( std::vector<int> const& axes, std::vector<double> const& motor_currents, eMotorCurrentMode mode=eMCM_MOVE )
01437 throw (cSDHLibraryException*);
01438
01439
01440
01447 void SetAxisMotorCurrent( int iAxis, double motor_current, eMotorCurrentMode mode=eMCM_MOVE )
01448 throw (cSDHLibraryException*);
01449
01450
01451
01503 std::vector<double> GetAxisMotorCurrent( std::vector<int> const& axes, eMotorCurrentMode mode=eMCM_MOVE )
01504 throw (cSDHLibraryException*);
01505
01506
01507
01512 double GetAxisMotorCurrent( int iAxis, eMotorCurrentMode mode=eMCM_MOVE )
01513 throw (cSDHLibraryException*);
01514
01515
01516
01579 void SetAxisEnable( std::vector<int> const& axes, std::vector<double> const& states )
01580 throw (cSDHLibraryException*);
01581
01582
01583
01590 void SetAxisEnable( int iAxis=All, double state=1.0 )
01591 throw (cSDHLibraryException*);
01592
01593
01594
01599 void SetAxisEnable( std::vector<int> const& axes, std::vector<bool> const& states )
01600 throw (cSDHLibraryException*);
01601
01602
01603
01610 void SetAxisEnable( int iAxis=All, bool state=true )
01611 throw (cSDHLibraryException*);
01612
01613
01614
01663 std::vector<double> GetAxisEnable( std::vector<int> const& axes )
01664 throw (cSDHLibraryException*);
01665
01666
01667
01672 double GetAxisEnable( int iAxis )
01673 throw (cSDHLibraryException*);
01674
01675
01676
01722 std::vector<eAxisState> GetAxisActualState( std::vector<int> const& axes )
01723 throw (cSDHLibraryException*);
01724
01725
01726
01731 eAxisState GetAxisActualState( int iAxis )
01732 throw (cSDHLibraryException*);
01733
01734
01735
01858 void WaitAxis( std::vector<int> const& axes, double timeout = -1.0 )
01859 throw (cSDHLibraryException*);
01860
01861
01862
01863
01870 void WaitAxis( int iAxis, double timeout = -1.0 )
01871 throw (cSDHLibraryException*);
01872
01873
01874
01948 void SetAxisTargetAngle( std::vector<int> const& axes, std::vector<double> const& angles )
01949 throw (cSDHLibraryException*);
01950
01951
01952
01959 void SetAxisTargetAngle( int iAxis, double angle )
01960 throw (cSDHLibraryException*);
01961
01962
01963
02012 std::vector<double> GetAxisTargetAngle( std::vector<int> const& axes )
02013 throw (cSDHLibraryException*);
02014
02015
02016
02022 double GetAxisTargetAngle( int iAxis )
02023 throw (cSDHLibraryException*);
02024
02025
02026
02075 std::vector<double> GetAxisActualAngle( std::vector<int> const& axes )
02076 throw (cSDHLibraryException*);
02077
02078
02079
02085 double GetAxisActualAngle( int iAxis )
02086 throw (cSDHLibraryException*);
02087
02088
02089
02173 void SetAxisTargetVelocity( std::vector<int> const& axes, std::vector<double> const& velocities )
02174 throw (cSDHLibraryException*);
02175
02176
02177
02182 void SetAxisTargetVelocity( int iAxis, double velocity )
02183 throw (cSDHLibraryException*);
02184
02185
02186
02235 std::vector<double> GetAxisTargetVelocity( std::vector<int> const& axes )
02236 throw (cSDHLibraryException*);
02237
02238
02239
02245 double GetAxisTargetVelocity( int iAxis )
02246 throw (cSDHLibraryException*);
02247
02248
02249
02298 std::vector<double> GetAxisLimitVelocity( std::vector<int> const& axes )
02299 throw (cSDHLibraryException*);
02300
02301
02302
02308 double GetAxisLimitVelocity( int iAxis )
02309 throw (cSDHLibraryException*);
02310
02311
02312
02361 std::vector<double> GetAxisLimitAcceleration( std::vector<int> const& axes )
02362 throw (cSDHLibraryException*);
02363
02364
02365
02371 double GetAxisLimitAcceleration( int iAxis )
02372 throw (cSDHLibraryException*);
02373
02374
02375
02420 std::vector<double> GetAxisActualVelocity( std::vector<int>const& axes )
02421 throw (cSDHLibraryException*);
02422
02423
02424
02430 double GetAxisActualVelocity( int iAxis )
02431 throw (cSDHLibraryException*);
02432
02433
02434
02491 std::vector<double> GetAxisReferenceVelocity( std::vector<int>const& axes )
02492 throw (cSDHLibraryException*);
02493
02494
02495
02501 double GetAxisReferenceVelocity( int iAxis )
02502 throw (cSDHLibraryException*);
02503
02504
02505
02587 void SetAxisTargetAcceleration( std::vector<int>const& axes, std::vector<double>const& accelerations )
02588 throw (cSDHLibraryException*);
02589
02590
02591
02596 void SetAxisTargetAcceleration( int iAxis, double acceleration )
02597 throw (cSDHLibraryException*);
02598
02599
02600
02649 std::vector<double> GetAxisTargetAcceleration( std::vector<int>const& axes )
02650 throw (cSDHLibraryException*);
02651
02652
02653
02659 double GetAxisTargetAcceleration( int iAxis )
02660 throw (cSDHLibraryException*);
02661
02662
02663
02718 std::vector<double> GetAxisMinAngle( std::vector<int> const& axes )
02719 throw (cSDHLibraryException*);
02720
02721
02722
02728 double GetAxisMinAngle( int iAxis )
02729 throw (cSDHLibraryException*);
02730
02731
02732
02787 std::vector<double> GetAxisMaxAngle( std::vector<int> const& axes )
02788 throw (cSDHLibraryException*);
02789
02790
02791
02797 double GetAxisMaxAngle( int iAxis )
02798 throw (cSDHLibraryException*);
02799
02800
02801
02861 std::vector<double> GetAxisMaxVelocity( std::vector<int> const& axes )
02862 throw (cSDHLibraryException*);
02863
02864
02865
02871 double GetAxisMaxVelocity( int iAxis )
02872 throw (cSDHLibraryException*);
02873
02874
02875
02930 std::vector<double> GetAxisMaxAcceleration( std::vector<int> const& axes )
02931 throw (cSDHLibraryException*);
02932
02933
02934
02940 double GetAxisMaxAcceleration( int iAxis )
02941 throw (cSDHLibraryException*);
02942
02943
02944
03055 double MoveAxis( std::vector<int>const& axes, bool sequ=true )
03056 throw (cSDHLibraryException*);
03057
03058
03059
03064 double MoveAxis( int iAxis, bool sequ=true )
03065 throw (cSDHLibraryException*);
03066
03067
03068
03069
03070
03071
03072
03073
03074
03076
03077
03078
03086
03148 void SetFingerEnable( std::vector<int> const& fingers, std::vector<double> const& states )
03149 throw (cSDHLibraryException*);
03150
03151
03152
03158 void SetFingerEnable( int iFinger, double state=1.0 )
03159 throw (cSDHLibraryException*);
03160
03161
03162
03168 void SetFingerEnable( std::vector<int> const& fingers, std::vector<bool> const& states )
03169 throw (cSDHLibraryException*);
03170
03171
03172
03178 void SetFingerEnable( int iFinger, bool state )
03179 throw (cSDHLibraryException*);
03180
03181
03182
03232 std::vector<double> GetFingerEnable( std::vector<int> const& fingers )
03233 throw (cSDHLibraryException*);
03234
03235
03236
03242 double GetFingerEnable( int iFinger )
03243 throw (cSDHLibraryException*);
03244
03245
03246
03306 void SetFingerTargetAngle( int iFinger, std::vector<double> const& angles )
03307 throw (cSDHLibraryException*);
03308
03309
03310
03315 void SetFingerTargetAngle( int iFinger, double a0, double a1, double a2 )
03316 throw (cSDHLibraryException*);
03317
03318
03319
03358 std::vector<double> GetFingerTargetAngle( int iFinger )
03359 throw (cSDHLibraryException*);
03360
03361
03362
03367 void GetFingerTargetAngle( int iFinger, double& a0, double& a1, double& a2 )
03368 throw (cSDHLibraryException*);
03369
03370
03371
03410 std::vector<double> GetFingerActualAngle( int iFinger )
03411 throw (cSDHLibraryException*);
03412
03413
03414
03419 void GetFingerActualAngle( int iFinger, double& a0, double& a1, double& a2 )
03420 throw (cSDHLibraryException*);
03421
03422
03423
03471 std::vector<double> GetFingerMinAngle( int iFinger )
03472 throw (cSDHLibraryException*);
03473
03474
03475
03481 void GetFingerMinAngle( int iFinger, double& a0, double& a1, double& a2 )
03482 throw (cSDHLibraryException*);
03483
03484
03485
03533 std::vector<double> GetFingerMaxAngle( int iFinger )
03534 throw (cSDHLibraryException*);
03535
03536
03537
03543 void GetFingerMaxAngle( int iFinger, double& a0, double& a1, double& a2 )
03544 throw (cSDHLibraryException*);
03545
03546
03547
03548
03605 std::vector<double> GetFingerXYZ( int iFinger, std::vector<double> const& angles )
03606 throw (cSDHLibraryException*);
03607
03608
03609
03614 std::vector<double> GetFingerXYZ( int iFinger, double a0, double a1, double a2 )
03615 throw (cSDHLibraryException*);
03616
03617
03618
03716 double MoveFinger( std::vector<int>const& fingers, bool sequ=true )
03717 throw (cSDHLibraryException*);
03718
03719
03720
03725 double MoveFinger( int iFinger, bool sequ=true )
03726 throw (cSDHLibraryException*);
03727
03728
03729
03747 double MoveHand( bool sequ=true )
03748 throw (cSDHLibraryException*);
03749
03750
03751
03753
03754
03755
03756
03764
03791 double GetGripMaxVelocity( void );
03792
03793
03794
03864 double GripHand( eGraspId grip, double close, double velocity, bool sequ=true )
03865 throw (cSDHLibraryException*);
03866
03867
03868
03870
03871
03872 private:
03876 void UpdateSettingsFromSDH();
03877
03884 void AdjustLimits( cSDHBase::eControllerType controller );
03885
03886
03888 std::string release_firmware;
03889
03891 eControllerType controller_type;
03892
03893
03894
03895
03896
03897
03898
03899
03900
03901
03902
03903
03904
03905
03906
03907 };
03908
03909
03910 NAMESPACE_SDH_END
03911
03912 #endif
03913
03914
03915
03916
03917
03918
03919
03920
03921
03922
03923
03924
03925