A library to control MX28 servos. It could also be used with the rest of the MX series servos.

Dependents:   IDcheck

Fork of MX28 by Georgios Petrou

This library is based on Robotis documentation regarding the dynamixel and MX28 protocols

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.

Committer:
GIPetrou
Date:
Wed Apr 03 16:44:50 2013 +0000
Revision:
2:85216442d3ef
Parent:
0:ea5b951002cf
Updated code to work with latest mbed version

Who changed what in which revision?

UserRevisionLine numberNew 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 0:ea5b951002cf 19 #include "Utilities.h"
GIPetrou 0:ea5b951002cf 20
GIPetrou 0:ea5b951002cf 21 uint8_t Utilities::GetCheckSum(const uint8_t *data, uint8_t length)
GIPetrou 0:ea5b951002cf 22 {
GIPetrou 0:ea5b951002cf 23 uint8_t checkSum = 0;
GIPetrou 0:ea5b951002cf 24
GIPetrou 0:ea5b951002cf 25 for(int i = 0; i < length; i++)
GIPetrou 0:ea5b951002cf 26 checkSum += data[i];
GIPetrou 0:ea5b951002cf 27
GIPetrou 0:ea5b951002cf 28 checkSum = ~checkSum;
GIPetrou 0:ea5b951002cf 29
GIPetrou 0:ea5b951002cf 30 return checkSum;
GIPetrou 0:ea5b951002cf 31 }
GIPetrou 0:ea5b951002cf 32
GIPetrou 0:ea5b951002cf 33 void Utilities::ConvertUInt16ToUInt8Array(uint16_t value, uint8_t* data)
GIPetrou 0:ea5b951002cf 34 {
GIPetrou 0:ea5b951002cf 35 data[0] = value;
GIPetrou 0:ea5b951002cf 36 data[1] = value >> 8;
GIPetrou 0:ea5b951002cf 37 }
GIPetrou 0:ea5b951002cf 38
GIPetrou 0:ea5b951002cf 39 void Utilities::ConvertInt16ToUInt8Array(int16_t value, uint8_t* data)
GIPetrou 0:ea5b951002cf 40 {
GIPetrou 0:ea5b951002cf 41 data[0] = value;
GIPetrou 0:ea5b951002cf 42 data[1] = value >> 8;
GIPetrou 0:ea5b951002cf 43 }
GIPetrou 0:ea5b951002cf 44
GIPetrou 0:ea5b951002cf 45 void Utilities::ConvertUInt32ToUInt8Array(uint32_t value, uint8_t* data)
GIPetrou 0:ea5b951002cf 46 {
GIPetrou 0:ea5b951002cf 47 data[0] = value;
GIPetrou 0:ea5b951002cf 48 data[1] = value >> 8;
GIPetrou 0:ea5b951002cf 49 data[2] = value >> 16;
GIPetrou 0:ea5b951002cf 50 data[3] = value >> 24;
GIPetrou 0:ea5b951002cf 51 }
GIPetrou 0:ea5b951002cf 52
GIPetrou 0:ea5b951002cf 53 void Utilities::ConvertInt32ToUInt8Array(int32_t value, uint8_t* data)
GIPetrou 0:ea5b951002cf 54 {
GIPetrou 0:ea5b951002cf 55 data[0] = value;
GIPetrou 0:ea5b951002cf 56 data[1] = value >> 8;
GIPetrou 0:ea5b951002cf 57 data[2] = value >> 16;
GIPetrou 0:ea5b951002cf 58 data[3] = value >> 24;
GIPetrou 0:ea5b951002cf 59 }
GIPetrou 0:ea5b951002cf 60
GIPetrou 0:ea5b951002cf 61 uint16_t Utilities::ConvertUInt8ArrayToUInt16(uint8_t* data)
GIPetrou 0:ea5b951002cf 62 {
GIPetrou 0:ea5b951002cf 63 return (((uint16_t)data[1]) << 8) | ((uint16_t)data[0]);
GIPetrou 0:ea5b951002cf 64 }
GIPetrou 0:ea5b951002cf 65
GIPetrou 0:ea5b951002cf 66 int16_t Utilities::ConvertUInt8ArrayToInt16(uint8_t* data)
GIPetrou 0:ea5b951002cf 67 {
GIPetrou 0:ea5b951002cf 68 return (((int16_t)data[1]) << 8) | ((int16_t)data[0]);
GIPetrou 0:ea5b951002cf 69 }
GIPetrou 0:ea5b951002cf 70
GIPetrou 0:ea5b951002cf 71 int32_t Utilities::ConvertUInt8ArrayToInt32(uint8_t* data)
GIPetrou 0:ea5b951002cf 72 {
GIPetrou 0:ea5b951002cf 73 return (((int32_t)data[3]) << 24) | (((int32_t)data[2]) << 16) | (((int32_t)data[1]) << 8) | ((int32_t)data[0]);
GIPetrou 0:ea5b951002cf 74 }
GIPetrou 0:ea5b951002cf 75