mbed to Dynamixel servo communication.
Dependents: dynamixel_wheel_test
Dynamixel.h@6:edba46e8f8b4, 2015-10-25 (annotated)
- Committer:
- dmgongora
- Date:
- Sun Oct 25 02:15:04 2015 +0000
- Revision:
- 6:edba46e8f8b4
- Parent:
- 5:7e661fef9c66
Added function to set the rotation mode: Wheel, Joint, Multi-turn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmgongora | 0:fb8a2d249639 | 1 | #ifndef DEF_DYNAMIXEL |
dmgongora | 0:fb8a2d249639 | 2 | #define DEF_DYNAMIXEL |
dmgongora | 0:fb8a2d249639 | 3 | |
dmgongora | 0:fb8a2d249639 | 4 | #include "mbed.h" |
dmgongora | 5:7e661fef9c66 | 5 | // ========== Compile Options ========== |
dmgongora | 4:92ff8b2f3b3f | 6 | #define ENABLE_uSerial 0 |
dmgongora | 4:92ff8b2f3b3f | 7 | // ========== DEBUG Console ============ |
dmgongora | 4:92ff8b2f3b3f | 8 | #if ENABLE_uSerial |
dmgongora | 4:92ff8b2f3b3f | 9 | Serial debug_userial(USBTX, USBRX); |
dmgongora | 4:92ff8b2f3b3f | 10 | #define DEBUG(...) { debug_userial.printf(__VA_ARGS__); } |
dmgongora | 4:92ff8b2f3b3f | 11 | #else |
dmgongora | 4:92ff8b2f3b3f | 12 | #define DEBUG(...) |
dmgongora | 5:7e661fef9c66 | 13 | #endif |
dmgongora | 1:ce081666d225 | 14 | const unsigned char BROADCAST_ID = 0xfe; |
dmgongora | 1:ce081666d225 | 15 | const unsigned char STATUS_PACKET_LENGTH = 0x06; |
dmgongora | 0:fb8a2d249639 | 16 | // Instruction set |
dmgongora | 0:fb8a2d249639 | 17 | const unsigned char PING = 0x01; |
dmgongora | 0:fb8a2d249639 | 18 | const unsigned char READ_DATA = 0x02; |
dmgongora | 0:fb8a2d249639 | 19 | const unsigned char WRITE_DATA = 0x03; |
dmgongora | 0:fb8a2d249639 | 20 | const unsigned char REG_WRITE = 0x04; |
dmgongora | 0:fb8a2d249639 | 21 | const unsigned char ACTION = 0x05; |
dmgongora | 0:fb8a2d249639 | 22 | const unsigned char RESET = 0x06; |
dmgongora | 0:fb8a2d249639 | 23 | const unsigned char SYNC_WRITE = 0x83; |
dmgongora | 0:fb8a2d249639 | 24 | // Control table |
dmgongora | 0:fb8a2d249639 | 25 | const unsigned char ADDRESS_PRESENT_TEMPERATURE = 0x2B; |
dmgongora | 0:fb8a2d249639 | 26 | const unsigned char ADDRESS_GOAL_POSITION = 0x1E; |
dmgongora | 0:fb8a2d249639 | 27 | const unsigned char ADDRESS_LED = 0x19; |
dmgongora | 0:fb8a2d249639 | 28 | const unsigned char ADDRESS_MOVING_SPEED = 0x20; |
dmgongora | 3:61785d105315 | 29 | const unsigned char ADDRESS_RETURN_DELAY_TIME = 0x05; |
dmgongora | 3:61785d105315 | 30 | const unsigned char ADDRESS_MAX_TORQUE = 0x0E; |
dmgongora | 3:61785d105315 | 31 | const unsigned char ADDRESS_TORQUE_ENABLE = 0x18; |
dmgongora | 6:edba46e8f8b4 | 32 | const unsigned char ADDRESS_CW_ANGLE_LIMIT = 0x06; |
dmgongora | 6:edba46e8f8b4 | 33 | const unsigned char ADDRESS_CCW_ANGLE_LIMIT = 0x08; |
dmgongora | 0:fb8a2d249639 | 34 | |
dmgongora | 0:fb8a2d249639 | 35 | class Dynamixel |
dmgongora | 0:fb8a2d249639 | 36 | { |
dmgongora | 0:fb8a2d249639 | 37 | public: |
dmgongora | 0:fb8a2d249639 | 38 | Dynamixel(PinName tx, PinName rx, PinName txEnable, uint8_t motorID, int baudrate); |
dmgongora | 1:ce081666d225 | 39 | uint8_t ping(); |
dmgongora | 1:ce081666d225 | 40 | uint8_t toggleLED(uint8_t ledState); |
dmgongora | 1:ce081666d225 | 41 | uint8_t move(uint16_t position); |
dmgongora | 6:edba46e8f8b4 | 42 | uint8_t setAngleLimit(uint16_t mode, uint8_t address); |
dmgongora | 1:ce081666d225 | 43 | uint8_t setSpeed(uint16_t speed); |
dmgongora | 3:61785d105315 | 44 | uint8_t setReturnDelayTime(uint16_t speed); |
dmgongora | 3:61785d105315 | 45 | uint8_t getReturnDelayTime(); |
dmgongora | 0:fb8a2d249639 | 46 | private: |
dmgongora | 0:fb8a2d249639 | 47 | Serial m_link; |
dmgongora | 0:fb8a2d249639 | 48 | DigitalOut m_txEnable; |
dmgongora | 0:fb8a2d249639 | 49 | uint8_t m_motorID; |
dmgongora | 0:fb8a2d249639 | 50 | const int m_baudrate; |
dmgongora | 0:fb8a2d249639 | 51 | }; |
dmgongora | 0:fb8a2d249639 | 52 | #endif |