modify to nucleo STM32F411
Fork of MX28 by
Protocol.h@4:30da84384307, 2015-08-25 (annotated)
- Committer:
- soulx
- Date:
- Tue Aug 25 08:51:58 2015 +0000
- Revision:
- 4:30da84384307
- Parent:
- 2:85216442d3ef
modify for Nucleo STM32F411
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GIPetrou | 0:ea5b951002cf | 1 | /* Dynamixel MX28 servo library |
GIPetrou | 0:ea5b951002cf | 2 | * Copyright (c) 2012 Georgios Petrou, MIT License |
GIPetrou | 0:ea5b951002cf | 3 | * |
GIPetrou | 0:ea5b951002cf | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
GIPetrou | 0:ea5b951002cf | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
GIPetrou | 0:ea5b951002cf | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
GIPetrou | 0:ea5b951002cf | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
GIPetrou | 0:ea5b951002cf | 8 | * furnished to do so, subject to the following conditions: |
GIPetrou | 0:ea5b951002cf | 9 | * |
GIPetrou | 0:ea5b951002cf | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
GIPetrou | 0:ea5b951002cf | 11 | * substantial portions of the Software. |
GIPetrou | 0:ea5b951002cf | 12 | * |
GIPetrou | 0:ea5b951002cf | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
GIPetrou | 0:ea5b951002cf | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
GIPetrou | 0:ea5b951002cf | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
GIPetrou | 0:ea5b951002cf | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
GIPetrou | 0:ea5b951002cf | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
GIPetrou | 0:ea5b951002cf | 18 | */ |
GIPetrou | 0:ea5b951002cf | 19 | |
GIPetrou | 2:85216442d3ef | 20 | #ifndef MX28_PROTOCOL_H |
GIPetrou | 2:85216442d3ef | 21 | #define MX28_PROTOCOL_H |
GIPetrou | 0:ea5b951002cf | 22 | |
GIPetrou | 0:ea5b951002cf | 23 | #include "mbed.h" |
GIPetrou | 0:ea5b951002cf | 24 | |
GIPetrou | 0:ea5b951002cf | 25 | #define MX28_BUFFER_SIZE 0x8F |
GIPetrou | 0:ea5b951002cf | 26 | |
GIPetrou | 0:ea5b951002cf | 27 | #define MX28_PROTOCOL_COMMAND_RESPONSE_TIMEOUT_MS 200 |
GIPetrou | 0:ea5b951002cf | 28 | |
GIPetrou | 0:ea5b951002cf | 29 | #define MX28_PROTOCOL_HEADER_0 0xFF |
GIPetrou | 0:ea5b951002cf | 30 | #define MX28_PROTOCOL_HEADER_1 0xFF |
GIPetrou | 0:ea5b951002cf | 31 | |
GIPetrou | 0:ea5b951002cf | 32 | #define MX28_PROTOCOL_BROADCAST_ID 0xFE |
GIPetrou | 0:ea5b951002cf | 33 | |
GIPetrou | 0:ea5b951002cf | 34 | // EEPROM Area |
GIPetrou | 0:ea5b951002cf | 35 | #define MX28_MODEL_NUMBER_L 0x00 |
GIPetrou | 0:ea5b951002cf | 36 | #define MX28_MODEL_NUMBER_H 0x01 |
GIPetrou | 0:ea5b951002cf | 37 | #define MX28_VERSION 0x02 |
GIPetrou | 0:ea5b951002cf | 38 | #define MX28_ID 0x03 |
GIPetrou | 0:ea5b951002cf | 39 | #define MX28_BAUD_RATE 0x04 |
GIPetrou | 0:ea5b951002cf | 40 | #define MX28_RETURN_DELAY_TIME 0x05 |
GIPetrou | 0:ea5b951002cf | 41 | #define MX28_CW_ANGLE_LIMIT_L 0x06 |
GIPetrou | 0:ea5b951002cf | 42 | #define MX28_CW_ANGLE_LIMIT_H 0x07 |
GIPetrou | 0:ea5b951002cf | 43 | #define MX28_CCW_ANGLE_LIMIT_L 0x08 |
GIPetrou | 0:ea5b951002cf | 44 | #define MX28_CCW_ANGLE_LIMIT_H 0x09 |
GIPetrou | 0:ea5b951002cf | 45 | #define MX28_UP_LIMIT_TEMPERATURE 0x0B |
GIPetrou | 0:ea5b951002cf | 46 | #define MX28_DOWN_LIMIT_VOLTAGE 0x0C |
GIPetrou | 0:ea5b951002cf | 47 | #define MX28_UP_LIMIT_VOLTAGE 0x0D |
GIPetrou | 0:ea5b951002cf | 48 | #define MX28_MAX_TORQUE_L 0x0E |
GIPetrou | 0:ea5b951002cf | 49 | #define MX28_MAX_TORQUE_H 0x0F |
GIPetrou | 0:ea5b951002cf | 50 | #define MX28_STATUS_RETURN_LEVEL 0x10 |
GIPetrou | 0:ea5b951002cf | 51 | #define MX28_ALARM_LED 0x11 |
GIPetrou | 0:ea5b951002cf | 52 | #define MX28_ALARM_SHUTDOWN 0x12 |
GIPetrou | 0:ea5b951002cf | 53 | |
GIPetrou | 0:ea5b951002cf | 54 | // RAM Area |
GIPetrou | 0:ea5b951002cf | 55 | #define MX28_TORQUE_ENABLE 0x18 |
GIPetrou | 0:ea5b951002cf | 56 | #define MX28_LED_ENABLE 0x19 |
GIPetrou | 0:ea5b951002cf | 57 | #define MX28_D_GAIN 0x1A |
GIPetrou | 0:ea5b951002cf | 58 | #define MX28_I_GAIN 0x1B |
GIPetrou | 0:ea5b951002cf | 59 | #define MX28_P_GAIN 0x1C |
GIPetrou | 0:ea5b951002cf | 60 | #define MX28_GOAL_POSITION_L 0x1E |
GIPetrou | 0:ea5b951002cf | 61 | #define MX28_GOAL_POSITION_H 0x1F |
GIPetrou | 0:ea5b951002cf | 62 | #define MX28_MOVING_SPEED_L 0x20 |
GIPetrou | 0:ea5b951002cf | 63 | #define MX28_MOVING_SPEED_H 0x21 |
GIPetrou | 0:ea5b951002cf | 64 | #define MX28_TORQUE_LIMIT_L 0x22 |
GIPetrou | 0:ea5b951002cf | 65 | #define MX28_TORQUE_LIMIT_H 0x23 |
GIPetrou | 0:ea5b951002cf | 66 | #define MX28_PRESENT_POSITION_L 0x24 |
GIPetrou | 0:ea5b951002cf | 67 | #define MX28_PRESENT_POSITION_H 0x25 |
GIPetrou | 0:ea5b951002cf | 68 | #define MX28_PRESENT_SPEED_L 0x26 |
GIPetrou | 0:ea5b951002cf | 69 | #define MX28_PRESENT_SPEED_H 0x27 |
GIPetrou | 0:ea5b951002cf | 70 | #define MX28_PRESENT_LOAD_L 0x28 |
GIPetrou | 0:ea5b951002cf | 71 | #define MX28_PRESENT_LOAD_H 0x29 |
GIPetrou | 0:ea5b951002cf | 72 | #define MX28_PRESENT_VOLTAGE 0x2A |
GIPetrou | 0:ea5b951002cf | 73 | #define MX28_PRESENT_TEMPERATURE 0x2B |
GIPetrou | 0:ea5b951002cf | 74 | #define MX28_REGISTERED_INSTRUCTION 0x2C |
GIPetrou | 0:ea5b951002cf | 75 | #define MX28_MOVING 0x3E |
GIPetrou | 0:ea5b951002cf | 76 | #define MX28_LOCK 0x2F |
GIPetrou | 0:ea5b951002cf | 77 | #define MX28_PUNCH_L 0x30 |
GIPetrou | 0:ea5b951002cf | 78 | #define MX28_PUNCH_H 0x31 |
GIPetrou | 0:ea5b951002cf | 79 | |
GIPetrou | 0:ea5b951002cf | 80 | // Instruction set |
GIPetrou | 0:ea5b951002cf | 81 | #define MX28_PING 0x01 |
GIPetrou | 0:ea5b951002cf | 82 | #define MX28_READ_DATA 0x02 |
GIPetrou | 0:ea5b951002cf | 83 | #define MX28_WRITE_DATA 0x03 |
GIPetrou | 0:ea5b951002cf | 84 | #define MX28_REG_WRITE 0x04 |
GIPetrou | 0:ea5b951002cf | 85 | #define MX28_ACTION 0x05 |
GIPetrou | 0:ea5b951002cf | 86 | #define MX28_RESET 0x06 |
GIPetrou | 0:ea5b951002cf | 87 | #define MX28_SYNC_WRITE 0x83 |
GIPetrou | 0:ea5b951002cf | 88 | |
GIPetrou | 0:ea5b951002cf | 89 | // Errors |
GIPetrou | 0:ea5b951002cf | 90 | #define MX28_ERRBIT_NONE 0x00 |
GIPetrou | 0:ea5b951002cf | 91 | #define MX28_ERRBIT_VOLTAGE 0x01 |
GIPetrou | 0:ea5b951002cf | 92 | #define MX28_ERRBIT_ANGLE 0x02 |
GIPetrou | 0:ea5b951002cf | 93 | #define MX28_ERRBIT_OVERHEAT 0x04 |
GIPetrou | 0:ea5b951002cf | 94 | #define MX28_ERRBIT_RANGE 0x08 |
GIPetrou | 0:ea5b951002cf | 95 | #define MX28_ERRBIT_CHECKSUM 0x10 |
GIPetrou | 0:ea5b951002cf | 96 | #define MX28_ERRBIT_OVERLOAD 0x20 |
GIPetrou | 0:ea5b951002cf | 97 | #define MX28_ERRBIT_INSTRUCTION 0x40 |
GIPetrou | 0:ea5b951002cf | 98 | |
GIPetrou | 0:ea5b951002cf | 99 | // Extra errors |
GIPetrou | 0:ea5b951002cf | 100 | #define MX28_ERRBIT_WRITE_TIMEOUT 0xFD |
GIPetrou | 0:ea5b951002cf | 101 | #define MX28_ERRBIT_READ_TIMEOUT 0xFE |
GIPetrou | 0:ea5b951002cf | 102 | #define MX28_ERRBIT_MASTER_CHECKSUM 0xFF |
GIPetrou | 0:ea5b951002cf | 103 | |
GIPetrou | 0:ea5b951002cf | 104 | struct MX28_PROTOCOL_PACKET |
GIPetrou | 0:ea5b951002cf | 105 | { |
GIPetrou | 0:ea5b951002cf | 106 | uint8_t servoId; |
GIPetrou | 0:ea5b951002cf | 107 | uint8_t length; |
GIPetrou | 0:ea5b951002cf | 108 | uint8_t instructionErrorId; |
GIPetrou | 0:ea5b951002cf | 109 | uint8_t parameter[MX28_BUFFER_SIZE]; |
GIPetrou | 0:ea5b951002cf | 110 | uint8_t checkSum; |
GIPetrou | 0:ea5b951002cf | 111 | }; |
GIPetrou | 0:ea5b951002cf | 112 | |
GIPetrou | 0:ea5b951002cf | 113 | enum MX28_PROTOCOL_ENCODER_DECODER_STATE |
GIPetrou | 0:ea5b951002cf | 114 | { |
GIPetrou | 0:ea5b951002cf | 115 | WAIT_ON_HEADER_0, |
GIPetrou | 0:ea5b951002cf | 116 | WAIT_ON_HEADER_1, |
GIPetrou | 1:5f537df9dca8 | 117 | WAIT_ON_SERVO_ID, |
GIPetrou | 0:ea5b951002cf | 118 | WAIT_ON_LENGTH, |
GIPetrou | 0:ea5b951002cf | 119 | WAIT_ON_INSTRUCTION_ERROR_ID, |
GIPetrou | 0:ea5b951002cf | 120 | WAIT_ON_PARAMETER, |
GIPetrou | 0:ea5b951002cf | 121 | WAIT_ON_CHECK_SUM |
GIPetrou | 0:ea5b951002cf | 122 | }; |
GIPetrou | 0:ea5b951002cf | 123 | |
GIPetrou | 2:85216442d3ef | 124 | #endif // MX28_PROTOCOL_H |