Dyanamixel

Dependents:   YOZAKURA_ARM YOZAKURA_ARM_USB YOZAKURA_ARM_USB_Keyboard YOZAKURA_ARM_Keyboard0424 ... more

Committer:
yusuke_kyo
Date:
Tue Aug 18 11:43:09 2015 +0000
Revision:
14:874b672847bc
Parent:
9:0927a7b74806
linear->MX28

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yusuke_kyo 0:10c9fb86002f 1 /* mbed AX-12+ Servo Library
yusuke_kyo 0:10c9fb86002f 2 *
yusuke_kyo 0:10c9fb86002f 3 * Copyright (c) 2010, cstyles (http://mbed.org)
yusuke_kyo 0:10c9fb86002f 4 *
yusuke_kyo 0:10c9fb86002f 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
yusuke_kyo 0:10c9fb86002f 6 * of this software and associated documentation files (the "Software"), to deal
yusuke_kyo 0:10c9fb86002f 7 * in the Software without restriction, including without limitation the rights
yusuke_kyo 0:10c9fb86002f 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yusuke_kyo 0:10c9fb86002f 9 * copies of the Software, and to permit persons to whom the Software is
yusuke_kyo 0:10c9fb86002f 10 * furnished to do so, subject to the following conditions:
yusuke_kyo 0:10c9fb86002f 11 *
yusuke_kyo 0:10c9fb86002f 12 * The above copyright notice and this permission notice shall be included in
yusuke_kyo 0:10c9fb86002f 13 * all copies or substantial portions of the Software.
yusuke_kyo 0:10c9fb86002f 14 *
yusuke_kyo 0:10c9fb86002f 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yusuke_kyo 0:10c9fb86002f 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yusuke_kyo 0:10c9fb86002f 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yusuke_kyo 0:10c9fb86002f 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yusuke_kyo 0:10c9fb86002f 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yusuke_kyo 0:10c9fb86002f 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yusuke_kyo 0:10c9fb86002f 21 * THE SOFTWARE.
yusuke_kyo 0:10c9fb86002f 22 */
yusuke_kyo 0:10c9fb86002f 23
yusuke_kyo 0:10c9fb86002f 24 #ifndef MBED_MX28_H
yusuke_kyo 0:10c9fb86002f 25 #define MBED_MX28_H
yusuke_kyo 0:10c9fb86002f 26
yusuke_kyo 0:10c9fb86002f 27 #include "mbed.h"
yusuke_kyo 3:97fc13b4168c 28 #include "SerialHalfDuplex.h"
yusuke_kyo 0:10c9fb86002f 29
yusuke_kyo 0:10c9fb86002f 30 #define MX28_WRITE_DEBUG 0
yusuke_kyo 0:10c9fb86002f 31 #define MX28_READ_DEBUG 0
yusuke_kyo 0:10c9fb86002f 32 #define MX28_TRIGGER_DEBUG 0
yusuke_kyo 9:0927a7b74806 33 #define MX28_DEBUG 0
yusuke_kyo 9:0927a7b74806 34 #define MX28_ERROR_DEBUG 0
yusuke_kyo 0:10c9fb86002f 35
yusuke_kyo 0:10c9fb86002f 36 #define MX28_REG_ID 0x3
yusuke_kyo 0:10c9fb86002f 37 #define MX28_REG_CW_LIMIT 0x06
yusuke_kyo 0:10c9fb86002f 38 #define MX28_REG_CCW_LIMIT 0x08
yusuke_kyo 1:3ac0919c093f 39 #define MX28_REG_TORQUE_ENABLE 0x18
yusuke_kyo 0:10c9fb86002f 40 #define MX28_REG_GOAL_POSITION 0x1E
yusuke_kyo 0:10c9fb86002f 41 #define MX28_REG_MOVING_SPEED 0x20
yusuke_kyo 0:10c9fb86002f 42 #define MX28_REG_VOLTS 0x2A
yusuke_kyo 0:10c9fb86002f 43 #define MX28_REG_TEMP 0x2B
yusuke_kyo 0:10c9fb86002f 44 #define MX28_REG_MOVING 0x2E
yusuke_kyo 0:10c9fb86002f 45 #define MX28_REG_POSITION 0x24
yusuke_kyo 1:3ac0919c093f 46 #define MX28_REG_TORQUE_LIMIT 0x22
yusuke_kyo 9:0927a7b74806 47 #define MX28_REG_CURRENT 0x38
yusuke_kyo 0:10c9fb86002f 48
yusuke_kyo 0:10c9fb86002f 49 #define MX28_MODE_POSITION 0
yusuke_kyo 0:10c9fb86002f 50 #define MX28_MODE_ROTATION 1
yusuke_kyo 0:10c9fb86002f 51
yusuke_kyo 0:10c9fb86002f 52 #define MX28_CW 1
yusuke_kyo 0:10c9fb86002f 53 #define MX28_CCW 0
yusuke_kyo 0:10c9fb86002f 54
yusuke_kyo 1:3ac0919c093f 55 class MX28
yusuke_kyo 1:3ac0919c093f 56 {
yusuke_kyo 0:10c9fb86002f 57
yusuke_kyo 0:10c9fb86002f 58 public:
yusuke_kyo 0:10c9fb86002f 59
yusuke_kyo 0:10c9fb86002f 60 /** Create an MX28 servo object connected to the specified serial port, with the specified ID
yusuke_kyo 0:10c9fb86002f 61 *
yusuke_kyo 0:10c9fb86002f 62 * @param pin tx pin
yusuke_kyo 1:3ac0919c093f 63 * @param pin rx pin
yusuke_kyo 1:3ac0919c093f 64 * @param int ID, the Bus ID of the servo 1-255
yusuke_kyo 0:10c9fb86002f 65 */
yusuke_kyo 5:950c4f4f73c6 66 MX28(PinName tx, PinName rx, int ID, int baudrate);
yusuke_kyo 0:10c9fb86002f 67
yusuke_kyo 0:10c9fb86002f 68 /** Set the mode of the servo
yusuke_kyo 0:10c9fb86002f 69 * @param mode
yusuke_kyo 0:10c9fb86002f 70 * 0 = Positional, default
yusuke_kyo 0:10c9fb86002f 71 * 1 = Continuous rotation
yusuke_kyo 0:10c9fb86002f 72 */
yusuke_kyo 0:10c9fb86002f 73 int SetMode(int mode);
yusuke_kyo 0:10c9fb86002f 74
yusuke_kyo 0:10c9fb86002f 75 /** Set goal angle in integer degrees, in positional mode
yusuke_kyo 0:10c9fb86002f 76 *
yusuke_kyo 0:10c9fb86002f 77 * @param degrees 0-360
yusuke_kyo 0:10c9fb86002f 78 * @param flags, defaults to 0
yusuke_kyo 1:3ac0919c093f 79 * flags[0] = blocking, return when goal position reached
yusuke_kyo 0:10c9fb86002f 80 * flags[1] = register, activate with a broadcast trigger
yusuke_kyo 0:10c9fb86002f 81 *
yusuke_kyo 0:10c9fb86002f 82 */
yusuke_kyo 0:10c9fb86002f 83 int SetGoal(int degrees, int flags = 0);
yusuke_kyo 0:10c9fb86002f 84
yusuke_kyo 0:10c9fb86002f 85 /** Set the speed of the servo in continuous rotation mode
yusuke_kyo 0:10c9fb86002f 86 *
yusuke_kyo 0:10c9fb86002f 87 * @param speed, -1.0 to 1.0
yusuke_kyo 0:10c9fb86002f 88 * -1.0 = full speed counter clock wise
yusuke_kyo 0:10c9fb86002f 89 * 1.0 = full speed clock wise
yusuke_kyo 0:10c9fb86002f 90 */
yusuke_kyo 0:10c9fb86002f 91 int SetCRSpeed(float speed);
yusuke_kyo 0:10c9fb86002f 92
yusuke_kyo 0:10c9fb86002f 93
yusuke_kyo 0:10c9fb86002f 94 /** Set the clockwise limit of the servo
yusuke_kyo 0:10c9fb86002f 95 *
yusuke_kyo 0:10c9fb86002f 96 * @param degrees, 0-360
yusuke_kyo 0:10c9fb86002f 97 */
yusuke_kyo 0:10c9fb86002f 98 int SetCWLimit(int degrees);
yusuke_kyo 1:3ac0919c093f 99
yusuke_kyo 0:10c9fb86002f 100 /** Set the counter-clockwise limit of the servo
yusuke_kyo 0:10c9fb86002f 101 *
yusuke_kyo 0:10c9fb86002f 102 * @param degrees, 0-360
yusuke_kyo 0:10c9fb86002f 103 */
yusuke_kyo 0:10c9fb86002f 104 int SetCCWLimit(int degrees);
yusuke_kyo 0:10c9fb86002f 105
yusuke_kyo 0:10c9fb86002f 106 // Change the ID
yusuke_kyo 0:10c9fb86002f 107
yusuke_kyo 0:10c9fb86002f 108 /** Change the ID of a servo
yusuke_kyo 0:10c9fb86002f 109 *
yusuke_kyo 0:10c9fb86002f 110 * @param CurentID 1-255
yusuke_kyo 0:10c9fb86002f 111 * @param NewID 1-255
yusuke_kyo 0:10c9fb86002f 112 *
yusuke_kyo 0:10c9fb86002f 113 * If a servo ID is not know, the broadcast address of 0 can be used for CurrentID.
yusuke_kyo 0:10c9fb86002f 114 * In this situation, only one servo should be connected to the bus
yusuke_kyo 0:10c9fb86002f 115 */
yusuke_kyo 0:10c9fb86002f 116 int SetID(int CurrentID, int NewID);
yusuke_kyo 0:10c9fb86002f 117
yusuke_kyo 0:10c9fb86002f 118
yusuke_kyo 0:10c9fb86002f 119 /** Poll to see if the servo is moving
yusuke_kyo 0:10c9fb86002f 120 *
yusuke_kyo 0:10c9fb86002f 121 * @returns true is the servo is moving
yusuke_kyo 0:10c9fb86002f 122 */
yusuke_kyo 0:10c9fb86002f 123 int isMoving(void);
yusuke_kyo 0:10c9fb86002f 124
yusuke_kyo 0:10c9fb86002f 125 /** Send the broadcast "trigger" command, to activate any outstanding registered commands
yusuke_kyo 0:10c9fb86002f 126 */
yusuke_kyo 0:10c9fb86002f 127 void trigger(void);
yusuke_kyo 0:10c9fb86002f 128
yusuke_kyo 0:10c9fb86002f 129 /** Read the current angle of the servo
yusuke_kyo 0:10c9fb86002f 130 *
yusuke_kyo 0:10c9fb86002f 131 * @returns float in the range 0.0-360.0
yusuke_kyo 0:10c9fb86002f 132 */
yusuke_kyo 0:10c9fb86002f 133 float GetPosition();
yusuke_kyo 0:10c9fb86002f 134
yusuke_kyo 0:10c9fb86002f 135 /** Read the temperature of the servo
yusuke_kyo 0:10c9fb86002f 136 *
yusuke_kyo 1:3ac0919c093f 137 * @returns float temperature
yusuke_kyo 0:10c9fb86002f 138 */
yusuke_kyo 0:10c9fb86002f 139 float GetTemp(void);
yusuke_kyo 0:10c9fb86002f 140
yusuke_kyo 0:10c9fb86002f 141 /** Read the supply voltage of the servo
yusuke_kyo 0:10c9fb86002f 142 *
yusuke_kyo 0:10c9fb86002f 143 * @returns float voltage
yusuke_kyo 0:10c9fb86002f 144 */
yusuke_kyo 0:10c9fb86002f 145 float GetVolts(void);
yusuke_kyo 1:3ac0919c093f 146
yusuke_kyo 0:10c9fb86002f 147 /** Read the supply current of the servo
yusuke_kyo 0:10c9fb86002f 148 *
yusuke_kyo 0:10c9fb86002f 149 * @returns float current
yusuke_kyo 0:10c9fb86002f 150 */
yusuke_kyo 0:10c9fb86002f 151 float GetCurrent(void);
yusuke_kyo 0:10c9fb86002f 152
yusuke_kyo 1:3ac0919c093f 153 int TorqueEnable(int mode);
yusuke_kyo 1:3ac0919c093f 154
yusuke_kyo 1:3ac0919c093f 155 int SetTorqueLimit(float torque_limit);
yusuke_kyo 1:3ac0919c093f 156
yusuke_kyo 0:10c9fb86002f 157 private :
yusuke_kyo 0:10c9fb86002f 158
yusuke_kyo 3:97fc13b4168c 159 SerialHalfDuplex _mx28;
yusuke_kyo 3:97fc13b4168c 160 // Serial _mx28;
yusuke_kyo 0:10c9fb86002f 161 int _ID;
yusuke_kyo 0:10c9fb86002f 162
yusuke_kyo 0:10c9fb86002f 163 int read(int ID, int start, int length, char* data);
yusuke_kyo 0:10c9fb86002f 164 int write(int ID, int start, int length, char* data, int flag=0);
yusuke_kyo 0:10c9fb86002f 165
yusuke_kyo 0:10c9fb86002f 166 };
yusuke_kyo 0:10c9fb86002f 167
yusuke_kyo 0:10c9fb86002f 168 #endif