Libbarrett
1.2.4
|
00001 00033 #ifndef BARRETT_PRODUCTS_FT_SENSOR_H_ 00034 #define BARRETT_PRODUCTS_FT_SENSOR_H_ 00035 00036 00037 #include <Eigen/Core> 00038 00039 #include <barrett/detail/ca_macro.h> 00040 #include <barrett/units.h> 00041 #include <barrett/bus/abstract/communications_bus.h> 00042 #include <barrett/products/puck.h> 00043 #include <barrett/products/abstract/special_puck.h> 00044 00045 00046 namespace barrett { 00047 00048 00049 class ForceTorqueSensor : public SpecialPuck { 00050 public: 00051 BARRETT_UNITS_FIXED_SIZE_TYPEDEFS; 00052 00054 ForceTorqueSensor(Puck* puck = NULL) : SpecialPuck(/* TODO(dc): Puck::PT_ForceTorque */), bus(NULL) { setPuck(puck); } 00056 ~ForceTorqueSensor() {} 00057 00059 void setPuck(Puck* puck); 00061 void tare() { Puck::setProperty(*bus, id, propId, 0); } 00063 void update(bool realtime = false); 00065 const cf_type& getForce() const { return cf; } 00067 const ct_type& getTorque() const { return ct; } 00069 void updateAccel(bool realtime = false); 00071 const ca_type& getAccel() const { return ca; } 00072 00074 struct ForceParser { 00075 static int busId(int id, int propId) { 00076 return Puck::encodeBusId(id, PuckGroup::FGRP_FT_FORCE); 00077 } 00078 00079 static const double SCALE_FACTOR = 256.0; 00080 typedef cf_type result_type; 00081 static int parse(int id, int propId, result_type* result, const unsigned char* data, size_t len) { 00082 return ForceTorqueSensor::parse(id, propId, result, data, len, SCALE_FACTOR); 00083 } 00084 }; 00086 struct TorqueParser { 00087 static int busId(int id, int propId) { 00088 return Puck::encodeBusId(id, PuckGroup::FGRP_FT_TORQUE); 00089 } 00090 00091 static const double SCALE_FACTOR = 4096.0; 00092 typedef ct_type result_type; 00093 static int parse(int id, int propId, result_type* result, const unsigned char* data, size_t len) { 00094 return ForceTorqueSensor::parse(id, propId, result, data, len, SCALE_FACTOR); 00095 } 00096 }; 00098 struct AccelParser { 00099 static int busId(int id, int propId) { 00100 return Puck::encodeBusId(id, PuckGroup::FGRP_FT_ACCEL); 00101 } 00102 00103 static const double SCALE_FACTOR = 1024.0; 00104 typedef ca_type result_type; 00105 static int parse(int id, int propId, result_type* result, const unsigned char* data, size_t len) { 00106 return ForceTorqueSensor::parse(id, propId, result, data, len, SCALE_FACTOR); 00107 } 00108 }; 00109 00110 00111 protected: 00112 const bus::CommunicationsBus* bus; 00113 int id; 00114 int propId; 00115 00116 cf_type cf; 00117 ct_type ct; 00118 ca_type ca; 00119 00120 private: 00121 typedef cf_type::Base base_type; 00122 00123 static int twoByte2int(unsigned char lsb, unsigned char msb); 00124 static int parse(int id, int propId, base_type* result, const unsigned char* data, size_t len, double scaleFactor); 00125 00126 DISALLOW_COPY_AND_ASSIGN(ForceTorqueSensor); 00127 00128 public: 00129 EIGEN_MAKE_ALIGNED_OPERATOR_NEW 00130 }; 00131 00132 00133 } 00134 00135 00136 #endif /* BARRETT_PRODUCTS_FT_SENSOR_H_ */