Libbarrett  1.2.4
include/barrett/products/hand.h
00001 
00026 /*
00027  * @file hand.h
00028  * @date 11/09/2010
00029  * @author Dan Cody
00030  * 
00031  */
00032 
00033 #ifndef BARRETT_PRODUCTS_HAND_H_
00034 #define BARRETT_PRODUCTS_HAND_H_
00035 
00036 
00037 #include <vector>
00038 
00039 #include <Eigen/Core>
00040 
00041 #include <barrett/detail/ca_macro.h>
00042 #include <barrett/units.h>
00043 #include <barrett/products/abstract/multi_puck_product.h>
00044 #include <barrett/products/puck.h>
00045 #include <barrett/products/motor_puck.h>
00046 #include <barrett/products/tactile_puck.h>
00047 
00048 
00049 namespace barrett {
00050 
00051 
00052 class Hand : public MultiPuckProduct {
00053 public:
00054         static const size_t DOF = 4;
00055         BARRETT_UNITS_TYPEDEFS(DOF);
00056 
00057 
00058         // Constants for referring to specific axes of the Hand
00059         static const unsigned int F1         = 1 << 0;
00060         static const unsigned int F2         = 1 << 1;
00061         static const unsigned int F3         = 1 << 2;
00062         static const unsigned int SPREAD     = 1 << 3;
00063         static const unsigned int GRASP      = F1 | F2 | F3;
00064         static const unsigned int WHOLE_HAND = GRASP | SPREAD;
00065 
00067         Hand(const std::vector<Puck*>& pucks);
00069         ~Hand();
00071         void initialize() const;
00073         void idle() const { group.setProperty(Puck::MODE, MotorPuck::MODE_IDLE); }
00075         bool doneMoving(unsigned int whichDigits = WHOLE_HAND, bool realtime = false) const;
00077         void waitUntilDoneMoving(unsigned int whichDigits = WHOLE_HAND, double period_s = 0.1) const;
00078 
00079         // Basic moves
00081         void open(unsigned int whichDigits = WHOLE_HAND, bool blocking = true) const;
00083         void open(bool blocking) const { open(WHOLE_HAND, blocking); }
00085         void close(unsigned int whichDigits = WHOLE_HAND, bool blocking = true) const;
00087         void close(bool blocking) const { close(WHOLE_HAND, blocking); }
00088 
00089         // Preferred: low control-rate moves
00091         void trapezoidalMove(const jp_type& jp, unsigned int whichDigits = WHOLE_HAND, bool blocking = true) const;
00093         void trapezoidalMove(const jp_type& jp, bool blocking) const { trapezoidalMove(jp, WHOLE_HAND, blocking); }
00095         void velocityMove(const jv_type& jv, unsigned int whichDigits = WHOLE_HAND) const;
00096 
00097         // Advanced: high control-rate moves
00099         void setPositionMode(unsigned int whichDigits = WHOLE_HAND) const;
00101         void setPositionCommand(const jp_type& jp, unsigned int whichDigits = WHOLE_HAND) const;
00103         void setTorqueMode(unsigned int whichDigits = WHOLE_HAND) const;
00105         void setTorqueCommand(const jt_type& jt, unsigned int whichDigits = WHOLE_HAND) const;
00106 
00107 
00108         // Sensors
00109         static const unsigned int S_POSITION          = 1 << 0;
00110         static const unsigned int S_FINGERTIP_TORQUE = 1 << 1;
00111         static const unsigned int S_TACT_FULL         = 1 << 2;
00112         static const unsigned int S_ALL = S_POSITION | S_FINGERTIP_TORQUE | S_TACT_FULL;
00114         void update(unsigned int sensors = S_ALL, bool realtime = false);
00116         const jp_type& getInnerLinkPosition() const { return innerJp; }
00118         const jp_type& getOuterLinkPosition() const { return outerJp; }
00120         const std::vector<int>& getPrimaryEncoderPosition() const { return primaryEncoder; }
00122         const std::vector<int>& getSecondaryEncoderPosition() const { return secondaryEncoder; }
00124         void enableBreakawayEncoders(bool enable) { useSecondaryEncoders = enable; }  // Enabled by default.
00126         bool hasFingertipTorqueSensors() const { return hasFtt; }
00128         const std::vector<int>& getFingertipTorque() const { return ftt; }
00130         bool hasTactSensors() const { return hasTact; }
00132         const std::vector<TactilePuck*>& getTactilePucks() const { return tactilePucks; }
00133 
00134 
00135         static const size_t SPREAD_INDEX = 3;
00136 
00137 protected:
00139         bool digitsInclude(unsigned int whichDigits, size_t index) const { return whichDigits & (1 << index); }
00141         void setProperty(unsigned int whichDigits, enum Puck::Property prop, int value) const;
00143         void setProperty(unsigned int whichDigits, enum Puck::Property prop, const v_type& values) const;
00145         void blockIf(bool blocking, unsigned int whichDigits) const;
00146 
00147 
00148         static const double J2_RATIO = 125.0;
00149         static const double J2_ENCODER_RATIO = 50.0;
00150         static const double J3_RATIO = 375.0;
00151         static const double SPREAD_RATIO = 17.5;
00152 
00153 
00154         bool hasFtt;
00155         bool hasTact;
00156         bool useSecondaryEncoders;
00157 
00158         int holds[DOF];
00159         v_type j2pp, j2pt;
00160         mutable v_type pt;
00161 
00162         std::vector<MotorPuck::CombinedPositionParser<int>::result_type> encoderTmp;
00163         std::vector<int> primaryEncoder, secondaryEncoder;
00164         jp_type innerJp, outerJp;
00165         std::vector<int> ftt;
00166         std::vector<TactilePuck*> tactilePucks;
00167 
00168 private:
00169         static const int CMD_HI    = 13;
00170         static const int CMD_CLOSE = 18;
00171         static const int CMD_OPEN  = 20;
00172         static const enum Puck::Property props[];
00173 
00174         DISALLOW_COPY_AND_ASSIGN(Hand);
00175 
00176 public:
00177         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00178 };
00179 
00180 
00181 }
00182 
00183 
00184 #endif /* BARRETT_PRODUCTS_HAND_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Defines