A library to control MX28 servos. It could also be used with the rest of the MX series servos.
Fork of MX28 by
This library is based on Robotis documentation regarding the dynamixel and MX28 protocols
- http://robosavvy.com/docs/Bioloid/AX-12(english).pdf
- http://support.robotis.com/en/product/dynamixel/mx_series/mx-28.htm
It is part of a bigger project involving seven mbeds to control a hexapod robot.
I have not tried to control other MX series servos, but it should be possible to use this library with minor modifications.
Utilities.h@2:85216442d3ef, 2013-04-03 (annotated)
- Committer:
- GIPetrou
- Date:
- Wed Apr 03 16:44:50 2013 +0000
- Revision:
- 2:85216442d3ef
- Parent:
- 1:5f537df9dca8
Updated code to work with latest mbed version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GIPetrou | 0:ea5b951002cf | 1 | /* Copyright (c) 2012 Georgios Petrou, MIT License |
GIPetrou | 0:ea5b951002cf | 2 | * |
GIPetrou | 0:ea5b951002cf | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
GIPetrou | 0:ea5b951002cf | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
GIPetrou | 0:ea5b951002cf | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
GIPetrou | 0:ea5b951002cf | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
GIPetrou | 0:ea5b951002cf | 7 | * furnished to do so, subject to the following conditions: |
GIPetrou | 0:ea5b951002cf | 8 | * |
GIPetrou | 0:ea5b951002cf | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
GIPetrou | 0:ea5b951002cf | 10 | * substantial portions of the Software. |
GIPetrou | 0:ea5b951002cf | 11 | * |
GIPetrou | 0:ea5b951002cf | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
GIPetrou | 0:ea5b951002cf | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
GIPetrou | 0:ea5b951002cf | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
GIPetrou | 0:ea5b951002cf | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
GIPetrou | 0:ea5b951002cf | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
GIPetrou | 0:ea5b951002cf | 17 | */ |
GIPetrou | 0:ea5b951002cf | 18 | |
GIPetrou | 2:85216442d3ef | 19 | #ifndef MX28_UTILITIES_H |
GIPetrou | 2:85216442d3ef | 20 | #define MX28_UTILITIES_H |
GIPetrou | 0:ea5b951002cf | 21 | |
GIPetrou | 0:ea5b951002cf | 22 | #include "mbed.h" |
GIPetrou | 0:ea5b951002cf | 23 | |
GIPetrou | 1:5f537df9dca8 | 24 | /** MX28 utility functions class |
GIPetrou | 1:5f537df9dca8 | 25 | */ |
GIPetrou | 0:ea5b951002cf | 26 | class Utilities |
GIPetrou | 0:ea5b951002cf | 27 | { |
GIPetrou | 0:ea5b951002cf | 28 | public: |
GIPetrou | 0:ea5b951002cf | 29 | /** Get the checksum for a packet. |
GIPetrou | 0:ea5b951002cf | 30 | * |
GIPetrou | 0:ea5b951002cf | 31 | * @param data The array of bytes. |
GIPetrou | 0:ea5b951002cf | 32 | * @param length The size of the array. |
GIPetrou | 0:ea5b951002cf | 33 | * @return checksum |
GIPetrou | 0:ea5b951002cf | 34 | */ |
GIPetrou | 0:ea5b951002cf | 35 | static uint8_t GetCheckSum(const uint8_t *data, uint8_t length); |
GIPetrou | 0:ea5b951002cf | 36 | |
GIPetrou | 0:ea5b951002cf | 37 | /** Convert a UInt16 number to array of chars. |
GIPetrou | 0:ea5b951002cf | 38 | * |
GIPetrou | 0:ea5b951002cf | 39 | * @param value The number value. |
GIPetrou | 0:ea5b951002cf | 40 | * @param data The array to store the conversion. |
GIPetrou | 0:ea5b951002cf | 41 | */ |
GIPetrou | 0:ea5b951002cf | 42 | static void ConvertUInt16ToUInt8Array(uint16_t value, uint8_t* data); |
GIPetrou | 0:ea5b951002cf | 43 | |
GIPetrou | 0:ea5b951002cf | 44 | /** Convert an Int16 number to array of chars. |
GIPetrou | 0:ea5b951002cf | 45 | * |
GIPetrou | 0:ea5b951002cf | 46 | * @param value The number value. |
GIPetrou | 0:ea5b951002cf | 47 | * @param data The array to store the conversion. |
GIPetrou | 0:ea5b951002cf | 48 | */ |
GIPetrou | 0:ea5b951002cf | 49 | static void ConvertInt16ToUInt8Array(int16_t value, uint8_t* data); |
GIPetrou | 0:ea5b951002cf | 50 | |
GIPetrou | 0:ea5b951002cf | 51 | /** Convert a UInt32 number to array of chars. |
GIPetrou | 0:ea5b951002cf | 52 | * |
GIPetrou | 0:ea5b951002cf | 53 | * @param value The number value. |
GIPetrou | 0:ea5b951002cf | 54 | * @param data The array to store the conversion. |
GIPetrou | 0:ea5b951002cf | 55 | */ |
GIPetrou | 0:ea5b951002cf | 56 | static void ConvertUInt32ToUInt8Array(uint32_t value, uint8_t* data); |
GIPetrou | 0:ea5b951002cf | 57 | |
GIPetrou | 0:ea5b951002cf | 58 | /** Convert an Int32 number to array of chars. |
GIPetrou | 0:ea5b951002cf | 59 | * |
GIPetrou | 0:ea5b951002cf | 60 | * @param value The number value. |
GIPetrou | 0:ea5b951002cf | 61 | * @param data The array to store the conversion. |
GIPetrou | 0:ea5b951002cf | 62 | */ |
GIPetrou | 0:ea5b951002cf | 63 | static void ConvertInt32ToUInt8Array(int32_t value, uint8_t* data); |
GIPetrou | 0:ea5b951002cf | 64 | |
GIPetrou | 0:ea5b951002cf | 65 | /** Convert an array of char to UInt16. |
GIPetrou | 0:ea5b951002cf | 66 | * |
GIPetrou | 0:ea5b951002cf | 67 | * @param data The array containing the chars. |
GIPetrou | 0:ea5b951002cf | 68 | * @return UInt16 converted number. |
GIPetrou | 0:ea5b951002cf | 69 | */ |
GIPetrou | 0:ea5b951002cf | 70 | static uint16_t ConvertUInt8ArrayToUInt16(uint8_t* data); |
GIPetrou | 0:ea5b951002cf | 71 | |
GIPetrou | 0:ea5b951002cf | 72 | /** Convert an array of char to Int16. |
GIPetrou | 0:ea5b951002cf | 73 | * |
GIPetrou | 0:ea5b951002cf | 74 | * @param data The array containing the chars. |
GIPetrou | 0:ea5b951002cf | 75 | * @return Int16 converted number. |
GIPetrou | 0:ea5b951002cf | 76 | */ |
GIPetrou | 0:ea5b951002cf | 77 | static int16_t ConvertUInt8ArrayToInt16(uint8_t* data); |
GIPetrou | 0:ea5b951002cf | 78 | |
GIPetrou | 0:ea5b951002cf | 79 | /** Convert an array of char to Int32. |
GIPetrou | 0:ea5b951002cf | 80 | * |
GIPetrou | 0:ea5b951002cf | 81 | * @param data The array containing the chars. |
GIPetrou | 0:ea5b951002cf | 82 | * @return Int32 number. |
GIPetrou | 0:ea5b951002cf | 83 | */ |
GIPetrou | 0:ea5b951002cf | 84 | static int32_t ConvertUInt8ArrayToInt32(uint8_t* data); |
GIPetrou | 0:ea5b951002cf | 85 | }; |
GIPetrou | 0:ea5b951002cf | 86 | |
GIPetrou | 2:85216442d3ef | 87 | #endif // MX28_UTILITIES_H |
GIPetrou | 0:ea5b951002cf | 88 |