![](/media/cache/group/Diana_su_nero.jpg.50x50_q85.jpg)
FOrk
Dependencies: Servo AX12_final MX106_not_working comunication_1
MX.h@22:ffb26af4d5d8, 2019-07-29 (annotated)
- Committer:
- gidiana
- Date:
- Mon Jul 29 22:34:34 2019 +0000
- Revision:
- 22:ffb26af4d5d8
- Parent:
- 11:19e8022f60ea
refactor complete
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
clynamen | 10:2acfa1a84c96 | 1 | #ifndef MX_H |
clynamen | 10:2acfa1a84c96 | 2 | #define MX_H |
clynamen | 10:2acfa1a84c96 | 3 | |
clynamen | 10:2acfa1a84c96 | 4 | #define MX_REG_ID 0x3 |
clynamen | 10:2acfa1a84c96 | 5 | #define MX_REG_CW_LIMIT 0x06 |
clynamen | 10:2acfa1a84c96 | 6 | #define MX_REG_CCW_LIMIT 0x08 |
clynamen | 10:2acfa1a84c96 | 7 | #define MX_REG_GOAL_POSITION 0x1E |
clynamen | 10:2acfa1a84c96 | 8 | #define MX_REG_MOVING_SPEED 0x20 |
clynamen | 10:2acfa1a84c96 | 9 | #define MX_REG_VOLTS 0x2A |
clynamen | 10:2acfa1a84c96 | 10 | #define MX_REG_AMPERE 0x44 |
clynamen | 10:2acfa1a84c96 | 11 | #define MX_REG_TEMP 0x2B |
clynamen | 10:2acfa1a84c96 | 12 | #define MX_REG_PGAIN 0x1C |
clynamen | 10:2acfa1a84c96 | 13 | #define MX_REG_IGAIN 0x1B |
clynamen | 10:2acfa1a84c96 | 14 | #define MX_REG_DGAIN 0X1A |
clynamen | 10:2acfa1a84c96 | 15 | #define MX_REG_MOVING 0x2E |
clynamen | 10:2acfa1a84c96 | 16 | #define MX_REG_MAXTORQUE 0x22 |
clynamen | 10:2acfa1a84c96 | 17 | #define MX_REG_POSITION 0x24 |
clynamen | 10:2acfa1a84c96 | 18 | #define MX_RESOLUTION 0.088 |
clynamen | 10:2acfa1a84c96 | 19 | //bit per degrees 4095/360° |
clynamen | 10:2acfa1a84c96 | 20 | #define MX_REG_MOTORONOFF 0x18 |
clynamen | 10:2acfa1a84c96 | 21 | #define MX_BIT_DEG 11.375 |
clynamen | 10:2acfa1a84c96 | 22 | #define MX_DEBUG 1 |
clynamen | 10:2acfa1a84c96 | 23 | #define MX_TRIGGER_DEBUG 1 |
clynamen | 10:2acfa1a84c96 | 24 | #define MX_REG_CURRENT 0x44 |
clynamen | 10:2acfa1a84c96 | 25 | #define MX_REG_TEMP 0x2B |
clynamen | 10:2acfa1a84c96 | 26 | |
clynamen | 10:2acfa1a84c96 | 27 | #define MX_READ_DEBUG 1 |
clynamen | 10:2acfa1a84c96 | 28 | #define AX12_WRITE_DEBUG 1 |
clynamen | 10:2acfa1a84c96 | 29 | #define AX12_READ_DEBUG 1 |
clynamen | 10:2acfa1a84c96 | 30 | #define AX12_TRIGGER_DEBUG 1 |
clynamen | 10:2acfa1a84c96 | 31 | #define AX12_DEBUG 1 |
clynamen | 10:2acfa1a84c96 | 32 | |
clynamen | 10:2acfa1a84c96 | 33 | #define AX12_REG_ID 0x3 |
clynamen | 10:2acfa1a84c96 | 34 | #define AX12_REG_CW_LIMIT 0x06 |
clynamen | 10:2acfa1a84c96 | 35 | #define AX12_REG_CCW_LIMIT 0x08 |
clynamen | 10:2acfa1a84c96 | 36 | #define AX12_REG_GOAL_POSITION 0x1E |
clynamen | 10:2acfa1a84c96 | 37 | #define AX12_REG_MOVING_SPEED 0x20 |
clynamen | 10:2acfa1a84c96 | 38 | #define AX12_REG_VOLTS 0x2A |
clynamen | 10:2acfa1a84c96 | 39 | #define AX12_REG_TEMP 0x2B |
clynamen | 10:2acfa1a84c96 | 40 | #define AX12_REG_MOVING 0x2E |
clynamen | 10:2acfa1a84c96 | 41 | #define AX12_REG_POSITION 0x24 |
clynamen | 10:2acfa1a84c96 | 42 | #define AX12_REG_MAXTORQUE 0x22 |
clynamen | 10:2acfa1a84c96 | 43 | #define AX12_REG_MOTORONOFF 0x18 |
clynamen | 10:2acfa1a84c96 | 44 | #define AX12_MODE_POSITION 0 |
clynamen | 10:2acfa1a84c96 | 45 | #define AX12_MODE_ROTATION 1 |
clynamen | 10:2acfa1a84c96 | 46 | |
clynamen | 10:2acfa1a84c96 | 47 | #define AX12_CW 1 |
clynamen | 10:2acfa1a84c96 | 48 | #define AX12_CCW 1 |
clynamen | 10:2acfa1a84c96 | 49 | #define goal_resolution 0.08789 |
clynamen | 10:2acfa1a84c96 | 50 | |
clynamen | 10:2acfa1a84c96 | 51 | #define READ_DEBUG 1 |
clynamen | 10:2acfa1a84c96 | 52 | |
clynamen | 10:2acfa1a84c96 | 53 | #include "Joint.h" |
clynamen | 10:2acfa1a84c96 | 54 | |
clynamen | 10:2acfa1a84c96 | 55 | // TODO: spostare i metodi uguali da MX106, MX64 in questo file e in MX.cpp. |
clynamen | 10:2acfa1a84c96 | 56 | |
clynamen | 10:2acfa1a84c96 | 57 | class MX : public Joint |
clynamen | 10:2acfa1a84c96 | 58 | { |
clynamen | 10:2acfa1a84c96 | 59 | |
clynamen | 10:2acfa1a84c96 | 60 | public: |
clynamen | 10:2acfa1a84c96 | 61 | MX(communication_1& line, int ID, float gear_train); |
clynamen | 10:2acfa1a84c96 | 62 | virtual ~MX(); |
clynamen | 10:2acfa1a84c96 | 63 | void setID(int newID); |
clynamen | 11:19e8022f60ea | 64 | int getID(); |
clynamen | 10:2acfa1a84c96 | 65 | |
clynamen | 10:2acfa1a84c96 | 66 | /** Set the mode of the servo |
clynamen | 10:2acfa1a84c96 | 67 | * @param mode |
clynamen | 10:2acfa1a84c96 | 68 | * 0 = Positional, default |
clynamen | 10:2acfa1a84c96 | 69 | * 1 = Continuous rotation |
clynamen | 10:2acfa1a84c96 | 70 | */ |
clynamen | 11:19e8022f60ea | 71 | virtual void setMode(int mode); |
clynamen | 11:19e8022f60ea | 72 | |
clynamen | 11:19e8022f60ea | 73 | void setCWLimitUnits(short limit); |
clynamen | 11:19e8022f60ea | 74 | void setCCWLimitUnits(short limit); |
clynamen | 11:19e8022f60ea | 75 | |
clynamen | 10:2acfa1a84c96 | 76 | /** Set the clockwise limit of the servo |
clynamen | 10:2acfa1a84c96 | 77 | * |
clynamen | 10:2acfa1a84c96 | 78 | * @param degrees, 0-300 |
clynamen | 10:2acfa1a84c96 | 79 | */ |
clynamen | 10:2acfa1a84c96 | 80 | void setCWLimit(float degrees); |
clynamen | 10:2acfa1a84c96 | 81 | /** Set the counter-clockwise limit of the servo |
clynamen | 10:2acfa1a84c96 | 82 | * |
clynamen | 10:2acfa1a84c96 | 83 | * @param degrees, 0-300 |
clynamen | 10:2acfa1a84c96 | 84 | */ |
clynamen | 10:2acfa1a84c96 | 85 | void setCCWLimit(float degrees); |
clynamen | 11:19e8022f60ea | 86 | |
clynamen | 10:2acfa1a84c96 | 87 | /** Set the speed of the servo in continuous rotation mode |
clynamen | 10:2acfa1a84c96 | 88 | * |
clynamen | 10:2acfa1a84c96 | 89 | * @param speed, -1.0 to 1.0 |
clynamen | 10:2acfa1a84c96 | 90 | * -1.0 = full speed counter clock wise |
clynamen | 10:2acfa1a84c96 | 91 | * 1.0 = full speed clock wise |
clynamen | 10:2acfa1a84c96 | 92 | */ |
clynamen | 11:19e8022f60ea | 93 | //void setCRSpeed(float speed); |
clynamen | 11:19e8022f60ea | 94 | // |
clynamen | 10:2acfa1a84c96 | 95 | void setGoalPosition(float degrees); |
clynamen | 10:2acfa1a84c96 | 96 | float getPosition(); |
clynamen | 10:2acfa1a84c96 | 97 | |
clynamen | 10:2acfa1a84c96 | 98 | /** Set goal angle in integer degrees, in positional mode |
clynamen | 10:2acfa1a84c96 | 99 | * |
clynamen | 10:2acfa1a84c96 | 100 | * @param degrees 0-300 |
clynamen | 10:2acfa1a84c96 | 101 | * @param flags, defaults to 0 |
clynamen | 10:2acfa1a84c96 | 102 | * flags[0] = blocking, return when goal position reached |
clynamen | 10:2acfa1a84c96 | 103 | * flags[1] = register, activate with a broadcast trigger |
clynamen | 10:2acfa1a84c96 | 104 | * |
clynamen | 10:2acfa1a84c96 | 105 | */ |
clynamen | 10:2acfa1a84c96 | 106 | int setGoal(float degrees, int flags = 0); |
clynamen | 11:19e8022f60ea | 107 | void setMaxSpeed(float degreeS); |
clynamen | 11:19e8022f60ea | 108 | void setCRSpeed(float degreeS); |
clynamen | 11:19e8022f60ea | 109 | void setSpeed(float degreeS); |
clynamen | 10:2acfa1a84c96 | 110 | float getTemp(); |
clynamen | 10:2acfa1a84c96 | 111 | float getCurrent(); |
clynamen | 10:2acfa1a84c96 | 112 | float getVolts(); |
gidiana | 22:ffb26af4d5d8 | 113 | float getTorqueMax(); |
clynamen | 11:19e8022f60ea | 114 | virtual float getPGain(); |
clynamen | 11:19e8022f60ea | 115 | virtual float getIGain(); |
clynamen | 11:19e8022f60ea | 116 | virtual float getDGain(); |
clynamen | 11:19e8022f60ea | 117 | virtual void setPGain(float gain); |
clynamen | 11:19e8022f60ea | 118 | virtual void setIGain(float gain); |
clynamen | 11:19e8022f60ea | 119 | virtual void setDGain(float gain); |
clynamen | 10:2acfa1a84c96 | 120 | void setMaxTorque(float torque); |
clynamen | 10:2acfa1a84c96 | 121 | void setMotorEnabled(bool enabled); |
clynamen | 10:2acfa1a84c96 | 122 | bool isMoving(); |
clynamen | 10:2acfa1a84c96 | 123 | |
clynamen | 10:2acfa1a84c96 | 124 | protected: |
clynamen | 10:2acfa1a84c96 | 125 | communication_1& _line; |
clynamen | 10:2acfa1a84c96 | 126 | float _gear_train; |
clynamen | 10:2acfa1a84c96 | 127 | int _ID; |
clynamen | 10:2acfa1a84c96 | 128 | int _mode; |
clynamen | 11:19e8022f60ea | 129 | float maxSpeedDegreeS; |
clynamen | 11:19e8022f60ea | 130 | float limitCWDegrees; |
clynamen | 11:19e8022f60ea | 131 | float limitCCWDegrees;; |
clynamen | 10:2acfa1a84c96 | 132 | }; |
clynamen | 10:2acfa1a84c96 | 133 | |
clynamen | 10:2acfa1a84c96 | 134 | #endif |