ds402.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of the SCHUNK Canopen Driver suite.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
00012 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00027 //----------------------------------------------------------------------
00028 
00029 #ifndef DS402_H
00030 #define DS402_H
00031 
00032 #include "Logging.h"
00033 
00034 namespace icl_hardware {
00035 namespace canopen_schunk {
00036 namespace ds402{
00037 
00038 static const uint16_t ID_CONTROL_WORD   = 0x6040;
00039 static const uint16_t ID_STATUS_WORD    = 0x6041;
00040 
00041 enum eModeOfOperation
00042 {
00043   //-1 ... -128 Manufacturer specific modes of operation
00044   MOO_RESERVED_0                 = 0,
00045   MOO_PROFILE_POSITION_MODE      = 1,
00046   MOO_VELOCITY_MODE              = 2, // not supported right now
00047   MOO_PROFILE_VELOCITY_MODE      = 3,
00048   MOO_PROFILE_TORQUE_MODE        = 4,
00049   MOO_RESERVED_1                 = 5,
00050   MOO_HOMING_MODE                = 6,
00051   MOO_INTERPOLATED_POSITION_MODE = 7,
00052   MOO_CYCLIC_SYNC_POSITION_MODE  = 8,
00053   MOO_CYCLIC_SYNC_VELOCITY_MODE  = 9,
00054   MOO_CYCLIC_SYNC_TORQUE_MODE    = 10
00055   //11 ... 127 reserved
00056 };
00057 
00061 enum eState
00062 {
00063   // Do NOT change the order of these states!
00064   STATE_START,
00065   STATE_NOT_READY_TO_SWITCH_ON,
00066   STATE_SWITCH_ON_DISABLED,
00067   STATE_READY_TO_SWITCH_ON,
00068   STATE_SWITCHED_ON,
00069   STATE_OPERATION_ENABLE,
00070   STATE_QUICKSTOP_ACTIVE,
00071   STATE_FAULT_REACTION_ACTIVE,
00072   STATE_FAULT // This does not show up in the diagram, but it is acquired from the statusword
00073 };
00074 
00075 enum eStateTransission
00076 {
00077   STATE_TRANS_INITIALIZE = 1,             // 1, 7, 9, 10, 12
00078   STATE_TRANS_SHUTDOWN = 2,               // 2, 6, 8
00079   STATE_TRANS_SWITCH_ON = 3,              // 3, 5
00080   STATE_TRANS_ENABLE_OPERATION = 4,       // 4, 16
00081   STATE_TRANS_QUICK_STOP = 11,            // 11
00082   STATE_TRANS_FAULT_RESET = 15            // 15
00083   // 0, 13 and 14 cannot be performed manually
00084 };
00085 
00087 struct Controlword_
00088 {
00089   uint16_t switch_on                 : 1; // 0
00090   uint16_t enable_voltage            : 1; // 1
00091   uint16_t quick_stop                : 1; // 2
00092   uint16_t enable_operation          : 1; // 3
00093   uint16_t operation_mode_specific_0 : 1; // 4
00094   uint16_t operation_mode_specific_1 : 1; // 5
00095   uint16_t operation_mode_specific_2 : 1; // 6
00096   uint16_t reset_fault               : 1; // 7
00097   uint16_t halt                      : 1; // 8
00098   uint16_t reserved_0                : 1; // 9
00099   uint16_t reserved_1                : 1; // 10
00100   uint16_t manufacturer_specific_0   : 1; // 11
00101   uint16_t manufacturer_specific_1   : 1; // 12
00102   uint16_t manufacturer_specific_2   : 1; // 13
00103   uint16_t manufacturer_specific_3   : 1; // 14
00104   uint16_t manufacturer_specific_4   : 1; // 15
00105 };
00106 
00108 union Controlword
00109 {
00110   Controlword_ bit;
00111   uint16_t all;
00112 };
00113 
00115 struct Statusword_
00116 {
00117   uint16_t ready_to_switch_on        : 1; // 0
00118   uint16_t switched_on               : 1; // 1
00119   uint16_t operation_enabled         : 1; // 2
00120   uint16_t fault                     : 1; // 3
00121   uint16_t voltage_enabled           : 1; // 4
00122   uint16_t quick_stop                : 1; // 5
00123   uint16_t switch_on_disabled        : 1; // 6
00124   uint16_t warning                   : 1; // 7
00125   uint16_t manufacturer_specific_0   : 1; // 8
00126   uint16_t remote                    : 1; // 9
00127   uint16_t target_reached            : 1; // 10
00128   uint16_t internal_limit_active     : 1; // 11
00129   uint16_t operation_mode_specific_0 : 1; // 12
00130   uint16_t operation_mode_specific_1 : 1; // 13
00131   uint16_t manufacturer_specific_1   : 1; // 14
00132   uint16_t manufacturer_specific_2   : 1; // 15
00133 };
00134 
00136 union Statusword
00137 {
00138   Statusword_ bit;
00139   uint16_t all;
00140 };
00141 
00142 struct SupportedDriveModes_
00143 {
00144   uint32_t profile_position_mode      : 1; // 0
00145   uint32_t velocity_mode              : 1; // 1
00146   uint32_t profile_velocity_mode      : 1; // 2
00147   uint32_t profile_torque_mode        : 1; // 3
00148   uint32_t reserved_4                 : 1; // 4
00149   uint32_t homing_mode                : 1; // 5
00150   uint32_t interpolated_position_mode : 1; // 6
00151   uint32_t cyclic_sync_position_mode  : 1; // 7
00152   uint32_t cyclic_sync_velocity_mode  : 1; // 8
00153   uint32_t cyclic_sync_torque_mode    : 1; // 9
00154   // 10..15 reserved
00155   // 16..31 manufacturer specific
00156 };
00157 
00159 union SupportedDriveModes
00160 {
00161   SupportedDriveModes_    bit;
00162   uint32_t all;
00163 };
00164 
00169 struct ProfilePositionModeConfiguration
00170 {
00174   float profile_velocity;
00175 
00179   float profile_acceleration;
00180 
00188   float profile_deceleration;
00189 
00193   int16_t motion_profile_type;
00194 
00199   bool change_set_immediately;
00200 
00207   bool use_relative_targets;
00208 
00213   bool use_blending;
00214 
00215 
00216   ProfilePositionModeConfiguration()
00217     : profile_deceleration(0),
00218       motion_profile_type(0),
00219       change_set_immediately(false),
00220       use_relative_targets(false),
00221       use_blending(true)
00222     {}
00223 };
00224 
00229 struct HomingModeConfiguration
00230 {
00231   int8_t homing_method;
00232   uint32_t homing_speed_low;
00233   uint32_t homing_speed_high;
00234 
00235   HomingModeConfiguration()
00236     : homing_method(0), homing_speed_low(0), homing_speed_high(0) {}
00237 
00238   HomingModeConfiguration(int8_t method_, uint32_t speed_low_, uint32_t speed_high)
00239     : homing_method( method_ ), homing_speed_low(speed_low_), homing_speed_high(speed_high) {}
00240 };
00241 
00246 struct ProfileVelocityModeConfiguration
00247 {
00248   int16_t sensor_selection_code;
00249 
00250   enum eSensorCode
00251   {
00252     POSITION_ENCODER = 0,
00253     VELOCITY_ENCODER = 1
00254   };
00255 };
00256 
00261 struct ProfileTorqueModeConfiguration
00262 {
00263   uint32_t torque_slope;
00264   int16_t torque_profile_type;
00265   ProfileTorqueModeConfiguration()
00266     : torque_slope(0), torque_profile_type(0) {}
00267 };
00268 
00276 inline std::string deviceStatusString (const eState state)
00277 {
00278   switch (state)
00279   {
00280     case STATE_NOT_READY_TO_SWITCH_ON:
00281     {
00282       return "NOT READY TO SWITCH ON";
00283       break;
00284     }
00285     case STATE_SWITCH_ON_DISABLED:
00286     {
00287       return "SWITCH ON DISABLED";
00288       break;
00289     }
00290     case STATE_READY_TO_SWITCH_ON:
00291     {
00292       return "READY TO SWITCH ON";
00293       break;
00294     }
00295     case STATE_SWITCHED_ON:
00296     {
00297       return "SWITCHED ON";
00298       break;
00299     }
00300     case STATE_OPERATION_ENABLE:
00301     {
00302       return "OPERATION ENABLED";
00303       break;
00304     }
00305     case STATE_QUICKSTOP_ACTIVE:
00306     {
00307       return "QUICK STOP ACTIVE";
00308       break;
00309     }
00310     case STATE_FAULT_REACTION_ACTIVE:
00311     {
00312       return "FAULT REACTION ACTIVE";
00313       break;
00314     }
00315     case STATE_FAULT:
00316     {
00317       return "FAULT";
00318       break;
00319     }
00320     default:
00321     {
00322       // nothing. Will reach statement at end of function
00323     }
00324   }
00325   return "Unknown status code. This should not happen!";
00326 }
00327 
00328 inline std::string operationModeString (const eModeOfOperation mode)
00329 {
00330   switch (mode)
00331   {
00332     case MOO_HOMING_MODE:
00333     {
00334       return "HOMING_MODE";
00335     }
00336     case MOO_INTERPOLATED_POSITION_MODE:
00337     {
00338       return "MOO_INTERPOLATED_POSITION_MODE";
00339     }
00340     case MOO_PROFILE_POSITION_MODE:
00341     {
00342       return "MOO_PROFILE_POSITION_MODE";
00343     }
00344     case MOO_PROFILE_TORQUE_MODE:
00345     {
00346       return "MOO_PROFILE_TORQUE_MODE";
00347     }
00348     case MOO_VELOCITY_MODE:
00349     {
00350       return "MOO_VELOCITY_MODE";
00351     }
00352     case MOO_PROFILE_VELOCITY_MODE:
00353     {
00354       return "MOO_PROFILE_VELOCITY_MODE";
00355     }
00356     case MOO_CYCLIC_SYNC_POSITION_MODE:
00357     {
00358       return "MOO_CYCLIC_SYNC_POSITION_MODE";
00359     }
00360     case MOO_CYCLIC_SYNC_VELOCITY_MODE:
00361     {
00362       return "MOO_CYCLIC_SYNC_VELOCITY_MODE";
00363     }
00364     case MOO_CYCLIC_SYNC_TORQUE_MODE:
00365     {
00366       return "MOO_CYCLIC_SYNC_TORQUE_MODE";
00367     }
00368     default:
00369     {
00370       return "UNKNOWN_MODE_OF_OPERATION";
00371     }
00372   }
00373 }
00374 
00375 inline eState stateFromStatusword (const ds402::Statusword& statusword)
00376 {
00377   uint8_t lsb = statusword.all & 0xFF;
00378   if ( (lsb | 0b10110000) == 0b10110000)
00379   {
00380     return STATE_NOT_READY_TO_SWITCH_ON;
00381   }
00382   else if ( (lsb | 0b10110000) == 0b11110000)
00383   {
00384     return STATE_SWITCH_ON_DISABLED;
00385   }
00386   else if ( (lsb | 0b10010000) == 0b10110001)
00387   {
00388     return STATE_READY_TO_SWITCH_ON;
00389   }
00390   else if ( (lsb | 0b10010000) == 0b10110011)
00391   {
00392     return STATE_SWITCHED_ON;
00393   }
00394   else if ( (lsb | 0b10010000) == 0b10110111)
00395   {
00396     return STATE_OPERATION_ENABLE;
00397   }
00398   else if ( (lsb | 0b10010000) == 0b10010111)
00399   {
00400     return STATE_QUICKSTOP_ACTIVE;
00401   }
00402   else if ( (lsb | 0b10110000) == 0b10111111)
00403   {
00404     return STATE_FAULT_REACTION_ACTIVE;
00405   }
00406   else if ( (lsb | 0b10110000) == 0b10111000)
00407   {
00408     return STATE_FAULT;
00409   }
00410 
00411   // if we reach this point, something is wrong!
00412   LOGGING_ERROR (CanOpen, "Failed to get DS402 state from statusword! Something is probably wrong with the statusword. Returning STATE_FAULT" << endl);
00413   return STATE_FAULT;
00414 }
00415 
00416 }}} // end of NS
00417 #endif // DS402_H


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Thu Jun 6 2019 20:17:24