mbed to Dynamixel servo communication.
Dependents: dynamixel_wheel_test
Dynamixel.h@4:92ff8b2f3b3f, 2015-08-19 (annotated)
- Committer:
- dmgongora
- Date:
- Wed Aug 19 09:23:06 2015 +0000
- Revision:
- 4:92ff8b2f3b3f
- Parent:
- 3:61785d105315
- Child:
- 5:7e661fef9c66
Added option to disable debugging messages
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 | 4:92ff8b2f3b3f | 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 | 4:92ff8b2f3b3f | 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 | 0:fb8a2d249639 | 32 | |
dmgongora | 0:fb8a2d249639 | 33 | class Dynamixel |
dmgongora | 0:fb8a2d249639 | 34 | { |
dmgongora | 0:fb8a2d249639 | 35 | public: |
dmgongora | 0:fb8a2d249639 | 36 | Dynamixel(PinName tx, PinName rx, PinName txEnable, uint8_t motorID, int baudrate); |
dmgongora | 1:ce081666d225 | 37 | uint8_t ping(); |
dmgongora | 1:ce081666d225 | 38 | uint8_t toggleLED(uint8_t ledState); |
dmgongora | 1:ce081666d225 | 39 | uint8_t move(uint16_t position); |
dmgongora | 1:ce081666d225 | 40 | uint8_t setSpeed(uint16_t speed); |
dmgongora | 3:61785d105315 | 41 | uint8_t setReturnDelayTime(uint16_t speed); |
dmgongora | 3:61785d105315 | 42 | uint8_t getReturnDelayTime(); |
dmgongora | 0:fb8a2d249639 | 43 | private: |
dmgongora | 0:fb8a2d249639 | 44 | Serial m_link; |
dmgongora | 0:fb8a2d249639 | 45 | DigitalOut m_txEnable; |
dmgongora | 0:fb8a2d249639 | 46 | uint8_t m_motorID; |
dmgongora | 0:fb8a2d249639 | 47 | const int m_baudrate; |
dmgongora | 0:fb8a2d249639 | 48 | }; |
dmgongora | 0:fb8a2d249639 | 49 | #endif |