pierre Rousselin
/
AX12
a
Fork of AX12 by
AX12.h@4:a7c95f3012db, 2017-10-18 (annotated)
- Committer:
- ROUSSELIN
- Date:
- Wed Oct 18 11:58:25 2017 +0000
- Revision:
- 4:a7c95f3012db
- Parent:
- 3:ced71d1b2558
For Apollo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 0:be51952765ec | 1 | #define AX12_REG_ID 0x3 |
chris | 3:ced71d1b2558 | 2 | #define AX12_REG_BAUD 0x4 |
chris | 0:be51952765ec | 3 | #define AX12_REG_CW_LIMIT 0x06 |
chris | 0:be51952765ec | 4 | #define AX12_REG_CCW_LIMIT 0x08 |
chris | 0:be51952765ec | 5 | #define AX12_REG_GOAL_POSITION 0x1E |
chris | 0:be51952765ec | 6 | #define AX12_REG_MOVING_SPEED 0x20 |
chris | 0:be51952765ec | 7 | #define AX12_REG_VOLTS 0x2A |
chris | 0:be51952765ec | 8 | #define AX12_REG_TEMP 0x2B |
chris | 0:be51952765ec | 9 | #define AX12_REG_MOVING 0x2E |
chris | 0:be51952765ec | 10 | #define AX12_REG_POSITION 0x24 |
chris | 0:be51952765ec | 11 | |
chris | 0:be51952765ec | 12 | #define AX12_MODE_POSITION 0 |
chris | 0:be51952765ec | 13 | #define AX12_MODE_ROTATION 1 |
chris | 0:be51952765ec | 14 | |
chris | 0:be51952765ec | 15 | #define AX12_CW 1 |
chris | 0:be51952765ec | 16 | #define AX12_CCW 0 |
chris | 0:be51952765ec | 17 | |
chris | 0:be51952765ec | 18 | class AX12 { |
chris | 0:be51952765ec | 19 | |
chris | 0:be51952765ec | 20 | public: |
chris | 0:be51952765ec | 21 | |
chris | 1:93ad80f5fde7 | 22 | /** Create an AX12 servo object connected to the specified serial port, with the specified ID |
chris | 1:93ad80f5fde7 | 23 | * |
chris | 1:93ad80f5fde7 | 24 | * @param pin tx pin |
chris | 1:93ad80f5fde7 | 25 | * @param pin rx pin |
chris | 1:93ad80f5fde7 | 26 | * @param int ID, the Bus ID of the servo 1-255 |
chris | 1:93ad80f5fde7 | 27 | */ |
ROUSSELIN | 4:a7c95f3012db | 28 | AX12(int tx, int rx, int ID, int baud=1000000); |
chris | 0:be51952765ec | 29 | |
chris | 1:93ad80f5fde7 | 30 | /** Set the mode of the servo |
chris | 1:93ad80f5fde7 | 31 | * @param mode |
chris | 1:93ad80f5fde7 | 32 | * 0 = Positional, default |
chris | 1:93ad80f5fde7 | 33 | * 1 = Continuous rotation |
chris | 1:93ad80f5fde7 | 34 | */ |
chris | 1:93ad80f5fde7 | 35 | int SetMode(int mode); |
chris | 0:be51952765ec | 36 | |
chris | 3:ced71d1b2558 | 37 | /** Set baud rate of all attached servos |
chris | 3:ced71d1b2558 | 38 | * @param mode |
chris | 3:ced71d1b2558 | 39 | * 0x01 = 1,000,000 bps |
chris | 3:ced71d1b2558 | 40 | * 0x03 = 500,000 bps |
chris | 3:ced71d1b2558 | 41 | * 0x04 = 400,000 bps |
chris | 3:ced71d1b2558 | 42 | * 0x07 = 250,000 bps |
chris | 3:ced71d1b2558 | 43 | * 0x09 = 200,000 bps |
chris | 3:ced71d1b2558 | 44 | * 0x10 = 115,200 bps |
chris | 3:ced71d1b2558 | 45 | * 0x22 = 57,600 bps |
chris | 3:ced71d1b2558 | 46 | * 0x67 = 19,200 bps |
chris | 3:ced71d1b2558 | 47 | * 0xCF = 9,600 bp |
chris | 3:ced71d1b2558 | 48 | */ |
chris | 3:ced71d1b2558 | 49 | int SetBaud(int baud); |
chris | 3:ced71d1b2558 | 50 | |
chris | 3:ced71d1b2558 | 51 | |
chris | 1:93ad80f5fde7 | 52 | /** Set goal angle in integer degrees, in positional mode |
chris | 1:93ad80f5fde7 | 53 | * |
chris | 1:93ad80f5fde7 | 54 | * @param degrees 0-300 |
chris | 1:93ad80f5fde7 | 55 | * @param flags, defaults to 0 |
chris | 1:93ad80f5fde7 | 56 | * flags[0] = blocking, return when goal position reached |
chris | 1:93ad80f5fde7 | 57 | * flags[1] = register, activate with a broadcast trigger |
chris | 1:93ad80f5fde7 | 58 | * |
chris | 1:93ad80f5fde7 | 59 | */ |
chris | 0:be51952765ec | 60 | int SetGoal(int degrees, int flags = 0); |
chris | 0:be51952765ec | 61 | |
chris | 0:be51952765ec | 62 | |
chris | 1:93ad80f5fde7 | 63 | /** Set the speed of the servo in continuous rotation mode |
chris | 1:93ad80f5fde7 | 64 | * |
chris | 1:93ad80f5fde7 | 65 | * @param speed, -1.0 to 1.0 |
chris | 1:93ad80f5fde7 | 66 | * -1.0 = full speed counter clock wise |
chris | 1:93ad80f5fde7 | 67 | * 1.0 = full speed clock wise |
chris | 1:93ad80f5fde7 | 68 | */ |
chris | 0:be51952765ec | 69 | int SetCRSpeed(float speed); |
chris | 0:be51952765ec | 70 | |
chris | 1:93ad80f5fde7 | 71 | |
chris | 1:93ad80f5fde7 | 72 | /** Set the clockwise limit of the servo |
chris | 1:93ad80f5fde7 | 73 | * |
chris | 1:93ad80f5fde7 | 74 | * @param degrees, 0-300 |
chris | 1:93ad80f5fde7 | 75 | */ |
chris | 0:be51952765ec | 76 | int SetCWLimit(int degrees); |
chris | 1:93ad80f5fde7 | 77 | |
chris | 1:93ad80f5fde7 | 78 | /** Set the counter-clockwise limit of the servo |
chris | 1:93ad80f5fde7 | 79 | * |
chris | 1:93ad80f5fde7 | 80 | * @param degrees, 0-300 |
chris | 1:93ad80f5fde7 | 81 | */ |
chris | 0:be51952765ec | 82 | int SetCCWLimit(int degrees); |
chris | 0:be51952765ec | 83 | |
chris | 0:be51952765ec | 84 | // Change the ID |
chris | 1:93ad80f5fde7 | 85 | |
chris | 1:93ad80f5fde7 | 86 | /** Change the ID of a servo |
chris | 1:93ad80f5fde7 | 87 | * |
chris | 1:93ad80f5fde7 | 88 | * @param CurentID 1-255 |
chris | 1:93ad80f5fde7 | 89 | * @param NewID 1-255 |
chris | 1:93ad80f5fde7 | 90 | * |
chris | 1:93ad80f5fde7 | 91 | * If a servo ID is not know, the broadcast address of 0 can be used for CurrentID. |
chris | 1:93ad80f5fde7 | 92 | * In this situation, only one servo should be connected to the bus |
chris | 1:93ad80f5fde7 | 93 | */ |
chris | 0:be51952765ec | 94 | int SetID(int CurrentID, int NewID); |
chris | 0:be51952765ec | 95 | |
chris | 1:93ad80f5fde7 | 96 | |
chris | 1:93ad80f5fde7 | 97 | /** Poll to see if the servo is moving |
chris | 1:93ad80f5fde7 | 98 | * |
chris | 1:93ad80f5fde7 | 99 | * @returns true is the servo is moving |
chris | 1:93ad80f5fde7 | 100 | */ |
chris | 0:be51952765ec | 101 | int isMoving(void); |
chris | 0:be51952765ec | 102 | |
chris | 1:93ad80f5fde7 | 103 | /** Send the broadcast "trigger" command, to activate any outstanding registered commands |
chris | 1:93ad80f5fde7 | 104 | */ |
chris | 0:be51952765ec | 105 | void trigger(void); |
chris | 0:be51952765ec | 106 | |
chris | 1:93ad80f5fde7 | 107 | /** Read the current angle of the servo |
chris | 1:93ad80f5fde7 | 108 | * |
chris | 1:93ad80f5fde7 | 109 | * @returns float in the range 0.0-300.0 |
chris | 1:93ad80f5fde7 | 110 | */ |
chris | 0:be51952765ec | 111 | float GetPosition(); |
chris | 0:be51952765ec | 112 | |
chris | 1:93ad80f5fde7 | 113 | /** Read the temperature of the servo |
chris | 1:93ad80f5fde7 | 114 | * |
chris | 1:93ad80f5fde7 | 115 | * @returns float temperature |
chris | 1:93ad80f5fde7 | 116 | */ |
chris | 0:be51952765ec | 117 | float GetTemp(void); |
chris | 1:93ad80f5fde7 | 118 | |
chris | 1:93ad80f5fde7 | 119 | /** Read the supply voltage of the servo |
chris | 1:93ad80f5fde7 | 120 | * |
chris | 1:93ad80f5fde7 | 121 | * @returns float voltage |
chris | 1:93ad80f5fde7 | 122 | */ |
chris | 0:be51952765ec | 123 | float GetVolts(void); |
chris | 0:be51952765ec | 124 | |
chris | 2:5ea99c37a2d7 | 125 | int read(int ID, int start, int length, char* data); |
chris | 2:5ea99c37a2d7 | 126 | int write(int ID, int start, int length, char* data, int flag=0); |
chris | 2:5ea99c37a2d7 | 127 | |
chris | 0:be51952765ec | 128 | private : |
ROUSSELIN | 4:a7c95f3012db | 129 | |
ROUSSELIN | 4:a7c95f3012db | 130 | // SerialHalfDuplex _ax12; |
chris | 0:be51952765ec | 131 | int _ID; |
chris | 2:5ea99c37a2d7 | 132 | int _baud; |
ROUSSELIN | 4:a7c95f3012db | 133 | |
ROUSSELIN | 4:a7c95f3012db | 134 | |
ROUSSELIN | 4:a7c95f3012db | 135 | }; |
chris | 0:be51952765ec | 136 | |
chris | 1:93ad80f5fde7 | 137 |