Fork from Dynamixel AX12 Servo for MX64 use and not-finishi now

Dependents:   2014-Mx64 2014-mx64-test

Fork of AX12 by Chris Styles

This Library was Fork From Chris Styles's AX12 Library .

Dynamixel MX64 Servo

MX64 is like a new generation Dynamixel Servo Use TTL 2.0 bus, Half-duplex Serial just like a pro-version AX12 300

Quote:

The MX-64T Dynamixel Robot Servo Actuator is the newest generation of Robotis Dynamixel actuator; equipped with an onboard 32bit 72mhz Cortex M3, a contact-less magnetic encoder with 4x the resolution over the AX/RX series, and up to 3mpbs using the new TTL 2.0 bus. Each servo has the ability to track its speed, temperature, shaft position, voltage, and load.

Information

In cace AX12 you can use This Library

Import libraryAX12

new ax12 lib

You need this Dependence Library SerialHalfDuplex library too

Import librarySerialHalfDuplex

Serial Half Duplex implementation

Committer:
ppr2013G2
Date:
Fri Jun 20 06:25:54 2014 +0000
Revision:
8:bf333220b2f1
Parent:
7:69c59554290b
fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ppr2013G2 4:acc6261cf054 1 /* mbed MX-64 Servo Library
ppr2013G2 4:acc6261cf054 2 *
ppr2013G2 4:acc6261cf054 3 * Copyright (c) 2010, cstyles (http://mbed.org)
ppr2013G2 4:acc6261cf054 4 *
ppr2013G2 4:acc6261cf054 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
ppr2013G2 4:acc6261cf054 6 * of this software and associated documentation files (the "Software"), to deal
ppr2013G2 4:acc6261cf054 7 * in the Software without restriction, including without limitation the rights
ppr2013G2 4:acc6261cf054 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ppr2013G2 4:acc6261cf054 9 * copies of the Software, and to permit persons to whom the Software is
ppr2013G2 4:acc6261cf054 10 * furnished to do so, subject to the following conditions:
ppr2013G2 4:acc6261cf054 11 *
ppr2013G2 4:acc6261cf054 12 * The above copyright notice and this permission notice shall be included in
ppr2013G2 4:acc6261cf054 13 * all copies or substantial portions of the Software.
ppr2013G2 4:acc6261cf054 14 *
ppr2013G2 4:acc6261cf054 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ppr2013G2 4:acc6261cf054 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ppr2013G2 4:acc6261cf054 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ppr2013G2 4:acc6261cf054 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ppr2013G2 4:acc6261cf054 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ppr2013G2 4:acc6261cf054 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ppr2013G2 4:acc6261cf054 21 * THE SOFTWARE.
ppr2013G2 4:acc6261cf054 22 */
ppr2013G2 4:acc6261cf054 23
ppr2013G2 4:acc6261cf054 24 #ifndef MBED_MX64_H
ppr2013G2 4:acc6261cf054 25 #define MBED_MX64_H
ppr2013G2 4:acc6261cf054 26
ppr2013G2 4:acc6261cf054 27 #include "mbed.h"
ppr2013G2 4:acc6261cf054 28 #include "SerialHalfDuplex.h"
ppr2013G2 4:acc6261cf054 29
ppr2013G2 4:acc6261cf054 30 //#define MX64_WRITE_DEBUG 0
ppr2013G2 4:acc6261cf054 31 //#define MX64_READ_DEBUG 0
ppr2013G2 4:acc6261cf054 32 //#define MX64_TRIGGER_DEBUG 0
ppr2013G2 4:acc6261cf054 33 //#define MX64_DEBUG 0
ppr2013G2 4:acc6261cf054 34
ppr2013G2 4:acc6261cf054 35 #define MX64_REG_ID 0x3
ppr2013G2 4:acc6261cf054 36 #define MX64_REG_BAUD 0x4
ppr2013G2 4:acc6261cf054 37 #define MX64_REG_CW_LIMIT 0x06
ppr2013G2 4:acc6261cf054 38 #define MX64_REG_CCW_LIMIT 0x08
ppr2013G2 4:acc6261cf054 39 #define MX64_REG_GOAL_POSITION 0x1E
ppr2013G2 4:acc6261cf054 40 #define MX64_REG_MOVING_SPEED 0x20
ppr2013G2 4:acc6261cf054 41 #define MX64_REG_VOLTS 0x2A
ppr2013G2 4:acc6261cf054 42 #define MX64_REG_TEMP 0x2B
ppr2013G2 4:acc6261cf054 43 #define MX64_REG_MOVING 0x2E
ppr2013G2 4:acc6261cf054 44 #define MX64_REG_POSITION 0x24
ppr2013G2 4:acc6261cf054 45
ppr2013G2 4:acc6261cf054 46 #define MX64_MODE_POSITION 0
ppr2013G2 4:acc6261cf054 47 #define MX64_MODE_ROTATION 1
ppr2013G2 4:acc6261cf054 48
ppr2013G2 4:acc6261cf054 49 #define MX64_CW 1
ppr2013G2 4:acc6261cf054 50 #define MX64_CCW 0
ppr2013G2 4:acc6261cf054 51
ppr2013G2 4:acc6261cf054 52 /** Servo control class, based on a PwmOut
ppr2013G2 4:acc6261cf054 53 *
ppr2013G2 4:acc6261cf054 54 * Example:
ppr2013G2 4:acc6261cf054 55 * @code
ppr2013G2 4:acc6261cf054 56 * #include "mbed.h"
ppr2013G2 4:acc6261cf054 57 * #include "MX64.h"
ppr2013G2 4:acc6261cf054 58 *
ppr2013G2 4:acc6261cf054 59 * int main() {
ppr2013G2 4:acc6261cf054 60 *
ppr2013G2 7:69c59554290b 61 * //MX64 mymx64 (p9, p10, 1); //for LPC1768
ppr2013G2 7:69c59554290b 62 * MX64 mymx64 (PTD2, PTD3, 1); //for KL25Z
ppr2013G2 4:acc6261cf054 63 *
ppr2013G2 4:acc6261cf054 64 * while (1) {
ppr2013G2 4:acc6261cf054 65 * mymx64.SetGoal(0); // go to 0 degrees
ppr2013G2 4:acc6261cf054 66 * wait (2.0);
ppr2013G2 7:69c59554290b 67 * mymx64.SetGoal(360); // go to 360 degrees
ppr2013G2 4:acc6261cf054 68 * wait (2.0);
ppr2013G2 4:acc6261cf054 69 * }
ppr2013G2 4:acc6261cf054 70 * }
ppr2013G2 4:acc6261cf054 71 * @endcode
ppr2013G2 4:acc6261cf054 72 */
ppr2013G2 4:acc6261cf054 73 class MX64 {
ppr2013G2 4:acc6261cf054 74
ppr2013G2 4:acc6261cf054 75 public:
ppr2013G2 4:acc6261cf054 76
ppr2013G2 4:acc6261cf054 77 /** Create an MX64 servo object connected to the specified serial port, with the specified ID
ppr2013G2 4:acc6261cf054 78 *
ppr2013G2 4:acc6261cf054 79 * @param pin tx pin
ppr2013G2 4:acc6261cf054 80 * @param pin rx pin
ppr2013G2 4:acc6261cf054 81 * @param int ID, the Bus ID of the servo 1-255
ppr2013G2 4:acc6261cf054 82 */
ppr2013G2 4:acc6261cf054 83 MX64(PinName tx, PinName rx, int ID, int baud=1000000);
ppr2013G2 4:acc6261cf054 84
ppr2013G2 4:acc6261cf054 85 /** Set the mode of the servo
ppr2013G2 4:acc6261cf054 86 * @param mode
ppr2013G2 4:acc6261cf054 87 * 0 = Positional, default
ppr2013G2 4:acc6261cf054 88 * 1 = Continuous rotation
ppr2013G2 4:acc6261cf054 89 */
ppr2013G2 4:acc6261cf054 90 int SetMode(int mode);
ppr2013G2 4:acc6261cf054 91
ppr2013G2 4:acc6261cf054 92 /** Set baud rate of all attached servos
ppr2013G2 4:acc6261cf054 93 * @param mode
ppr2013G2 4:acc6261cf054 94 * 0x01 = 1,000,000 bps
ppr2013G2 4:acc6261cf054 95 * 0x03 = 500,000 bps
ppr2013G2 4:acc6261cf054 96 * 0x04 = 400,000 bps
ppr2013G2 4:acc6261cf054 97 * 0x07 = 250,000 bps
ppr2013G2 4:acc6261cf054 98 * 0x09 = 200,000 bps
ppr2013G2 4:acc6261cf054 99 * 0x10 = 115,200 bps
ppr2013G2 4:acc6261cf054 100 * 0x22 = 57,600 bps
ppr2013G2 4:acc6261cf054 101 * 0x67 = 19,200 bps
ppr2013G2 4:acc6261cf054 102 * 0xCF = 9,600 bp
ppr2013G2 4:acc6261cf054 103 */
ppr2013G2 4:acc6261cf054 104 int SetBaud(int baud);
ppr2013G2 4:acc6261cf054 105
ppr2013G2 4:acc6261cf054 106
ppr2013G2 4:acc6261cf054 107 /** Set goal angle in integer degrees, in positional mode
ppr2013G2 4:acc6261cf054 108 *
ppr2013G2 4:acc6261cf054 109 * @param degrees 0-300
ppr2013G2 4:acc6261cf054 110 * @param flags, defaults to 0
ppr2013G2 4:acc6261cf054 111 * flags[0] = blocking, return when goal position reached
ppr2013G2 4:acc6261cf054 112 * flags[1] = register, activate with a broadcast trigger
ppr2013G2 4:acc6261cf054 113 *
ppr2013G2 4:acc6261cf054 114 */
ppr2013G2 4:acc6261cf054 115 int SetGoal(int degrees, int flags = 0);
ppr2013G2 4:acc6261cf054 116
ppr2013G2 5:15f8cd3b7dfb 117 /** Set goal angle in integer degrees, in positional mode
ppr2013G2 5:15f8cd3b7dfb 118 *
ppr2013G2 5:15f8cd3b7dfb 119 * @param degrees 0-300
ppr2013G2 5:15f8cd3b7dfb 120 * @param speed 0-100
ppr2013G2 5:15f8cd3b7dfb 121 * @param flags, defaults to 0
ppr2013G2 5:15f8cd3b7dfb 122 * flags[0] = blocking, return when goal position reached
ppr2013G2 5:15f8cd3b7dfb 123 * flags[1] = register, activate with a broadcast trigger
ppr2013G2 5:15f8cd3b7dfb 124 *
ppr2013G2 5:15f8cd3b7dfb 125 */
ppr2013G2 5:15f8cd3b7dfb 126 int SetGoalSpeed(int degrees, int speed, int flags = 0);
ppr2013G2 5:15f8cd3b7dfb 127
ppr2013G2 4:acc6261cf054 128
ppr2013G2 4:acc6261cf054 129 /** Set the speed of the servo in continuous rotation mode
ppr2013G2 4:acc6261cf054 130 *
ppr2013G2 4:acc6261cf054 131 * @param speed, -1.0 to 1.0
ppr2013G2 4:acc6261cf054 132 * -1.0 = full speed counter clock wise
ppr2013G2 4:acc6261cf054 133 * 1.0 = full speed clock wise
ppr2013G2 4:acc6261cf054 134 */
ppr2013G2 4:acc6261cf054 135 int SetCRSpeed(float speed);
ppr2013G2 4:acc6261cf054 136
ppr2013G2 4:acc6261cf054 137
ppr2013G2 4:acc6261cf054 138 /** Set the clockwise limit of the servo
ppr2013G2 4:acc6261cf054 139 *
ppr2013G2 8:bf333220b2f1 140 * @param degrees, 0-360
ppr2013G2 4:acc6261cf054 141 */
ppr2013G2 4:acc6261cf054 142 int SetCWLimit(int degrees);
ppr2013G2 4:acc6261cf054 143
ppr2013G2 4:acc6261cf054 144 /** Set the counter-clockwise limit of the servo
ppr2013G2 4:acc6261cf054 145 *
ppr2013G2 8:bf333220b2f1 146 * @param degrees, 0-360
ppr2013G2 4:acc6261cf054 147 */
ppr2013G2 4:acc6261cf054 148 int SetCCWLimit(int degrees);
ppr2013G2 4:acc6261cf054 149
ppr2013G2 4:acc6261cf054 150 // Change the ID
ppr2013G2 4:acc6261cf054 151
ppr2013G2 4:acc6261cf054 152 /** Change the ID of a servo
ppr2013G2 4:acc6261cf054 153 *
ppr2013G2 4:acc6261cf054 154 * @param CurentID 1-255
ppr2013G2 4:acc6261cf054 155 * @param NewID 1-255
ppr2013G2 4:acc6261cf054 156 *
ppr2013G2 4:acc6261cf054 157 * If a servo ID is not know, the broadcast address of 0 can be used for CurrentID.
ppr2013G2 4:acc6261cf054 158 * In this situation, only one servo should be connected to the bus
ppr2013G2 4:acc6261cf054 159 */
ppr2013G2 4:acc6261cf054 160 int SetID(int CurrentID, int NewID);
ppr2013G2 4:acc6261cf054 161
ppr2013G2 4:acc6261cf054 162
ppr2013G2 4:acc6261cf054 163 /** Poll to see if the servo is moving
ppr2013G2 4:acc6261cf054 164 *
ppr2013G2 4:acc6261cf054 165 * @returns true is the servo is moving
ppr2013G2 4:acc6261cf054 166 */
ppr2013G2 4:acc6261cf054 167 int isMoving(void);
ppr2013G2 4:acc6261cf054 168
ppr2013G2 4:acc6261cf054 169 /** Send the broadcast "trigger" command, to activate any outstanding registered commands
ppr2013G2 4:acc6261cf054 170 */
ppr2013G2 4:acc6261cf054 171 void trigger(void);
ppr2013G2 4:acc6261cf054 172
ppr2013G2 4:acc6261cf054 173 /** Read the current angle of the servo
ppr2013G2 4:acc6261cf054 174 *
ppr2013G2 4:acc6261cf054 175 * @returns float in the range 0.0-300.0
ppr2013G2 4:acc6261cf054 176 */
ppr2013G2 4:acc6261cf054 177 float GetPosition();
ppr2013G2 4:acc6261cf054 178
ppr2013G2 4:acc6261cf054 179 /** Read the temperature of the servo
ppr2013G2 4:acc6261cf054 180 *
ppr2013G2 4:acc6261cf054 181 * @returns float temperature
ppr2013G2 4:acc6261cf054 182 */
ppr2013G2 4:acc6261cf054 183 float GetTemp(void);
ppr2013G2 4:acc6261cf054 184
ppr2013G2 4:acc6261cf054 185 /** Read the supply voltage of the servo
ppr2013G2 4:acc6261cf054 186 *
ppr2013G2 4:acc6261cf054 187 * @returns float voltage
ppr2013G2 4:acc6261cf054 188 */
ppr2013G2 4:acc6261cf054 189 float GetVolts(void);
ppr2013G2 4:acc6261cf054 190
ppr2013G2 4:acc6261cf054 191 int read(int ID, int start, int length, char* data);
ppr2013G2 4:acc6261cf054 192 int write(int ID, int start, int length, char* data, int flag=0);
ppr2013G2 4:acc6261cf054 193
ppr2013G2 4:acc6261cf054 194 private :
ppr2013G2 4:acc6261cf054 195
ppr2013G2 4:acc6261cf054 196 SerialHalfDuplex _mx64;
ppr2013G2 4:acc6261cf054 197 int _ID;
ppr2013G2 4:acc6261cf054 198 int _baud;
ppr2013G2 4:acc6261cf054 199
ppr2013G2 4:acc6261cf054 200
ppr2013G2 4:acc6261cf054 201 };
ppr2013G2 4:acc6261cf054 202
ppr2013G2 4:acc6261cf054 203 #endif