Libbarrett  1.2.4
include/barrett/products/motor_puck.h
Go to the documentation of this file.
00001 
00033 #ifndef BARRETT_PRODUCTS_MOTOR_PUCK_H_
00034 #define BARRETT_PRODUCTS_MOTOR_PUCK_H_
00035 
00036 
00037 #include <boost/tuple/tuple.hpp>
00038 
00039 #include <barrett/bus/abstract/communications_bus.h>
00040 #include <barrett/math/utils.h>
00041 #include <barrett/products/puck.h>
00042 #include <barrett/products/abstract/special_puck.h>
00043 
00044 
00045 namespace barrett {
00046 
00047 
00048 class MotorPuck : public SpecialPuck {
00049 public:
00050         enum MotorMode {
00051                 MODE_IDLE,
00052                 MODE_DUTY,
00053                 MODE_TORQUE,
00054                 MODE_PID,
00055                 MODE_VELOCITY,
00056                 MODE_TRAPEZOIDAL
00057         };
00058 
00059 
00060         MotorPuck(Puck* puck = NULL) :
00061                 SpecialPuck(Puck::PT_Motor), cts(0), rpc(0.0), cpr(0.0), ipnm(0) { setPuck(puck); }
00062         ~MotorPuck() {}
00063 
00064         void setPuck(Puck* puck);
00065 
00066         int getCts() const { return cts; }
00067         double getRadsPerCount() const { return rpc; }
00068         double getCountsPerRad() const { return cpr; }
00069         double counts2rad(int counts) const { return rpc * counts; }
00070         int rad2counts(double rad) const { return floor(cpr * rad); }
00071 
00072         int getIpnm() const { return ipnm; }
00073         int nm2i(double torque) const { return floor(math::saturate(torque*ipnm, MAX_PUCK_TORQUE)); }
00074 
00075         bool foundIndexPulse() const {
00076                 return (p->getProperty(Puck::ECMIN) != 0)  ||  (p->getProperty(Puck::ECMAX) != 0);
00077         }
00078 
00079 
00080         static void sendPackedTorques(const bus::CommunicationsBus& bus, int groupId, int propId,
00081                         const double* pt, int numTorques);
00082 
00083 
00084         static const size_t PUCKS_PER_TORQUE_GROUP = 4;
00085         static const int MAX_PUCK_TORQUE = 8191;
00086 
00087 
00088         template<typename ResultType>
00089         struct MotorPositionParser {
00090                 static int busId(int id, int propId) {
00091                         return Puck::encodeBusId(id, PuckGroup::FGRP_MOTOR_POSITION);
00092                 }
00093 
00094                 typedef ResultType result_type;
00095                 static int parse(int id, int propId, result_type* result, const unsigned char* data, size_t len);
00096         };
00097         template<typename ResultType>
00098         struct SecondaryPositionParser {
00099                 static int busId(int id, int propId) {
00100                         return Puck::encodeBusId(id, PuckGroup::FGRP_SECONDARY_POSITION);
00101                 }
00102 
00103                 typedef ResultType result_type;
00104                 static int parse(int id, int propId, result_type* result, const unsigned char* data, size_t len);
00105         };
00106         template<typename ResultType>
00107         struct CombinedPositionParser {
00108                 static int busId(int id, int propId) {
00109                         return MotorPositionParser<ResultType>::busId(id, propId);
00110                 }
00111 
00112                 typedef boost::tuple<ResultType,ResultType> result_type;
00113                 static int parse(int id, int propId, result_type* result, const unsigned char* data, size_t len);
00114         };
00115 
00116 
00117 protected:
00118         int cts;
00119         double rpc, cpr;
00120         int ipnm;
00121 
00122 private:
00123         template<typename ResultType>
00124         static ResultType twentyTwoBit2(unsigned char msb, unsigned char middle, unsigned char lsb);
00125 };
00126 
00127 
00128 }
00129 
00130 
00131 // include template definitions
00132 #include <barrett/products/detail/motor_puck-inl.h>
00133 
00134 
00135 #endif /* BARRETT_PRODUCTS_MOTOR_PUCK_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines