Dyanamixel

Dependents:   YOZAKURA_ARM YOZAKURA_ARM_USB YOZAKURA_ARM_USB_Keyboard YOZAKURA_ARM_Keyboard0424 ... more

Committer:
yusuke_kyo
Date:
Tue Mar 31 09:45:27 2015 +0000
Revision:
0:10c9fb86002f
Child:
1:3ac0919c093f
Dynamixel

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 0:10c9fb86002f 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 0:10c9fb86002f 33 #define MX28_DEBUG 0
yusuke_kyo 0:10c9fb86002f 34
yusuke_kyo 0:10c9fb86002f 35 #define MX28_REG_ID 0x3
yusuke_kyo 0:10c9fb86002f 36 #define MX28_REG_CW_LIMIT 0x06
yusuke_kyo 0:10c9fb86002f 37 #define MX28_REG_CCW_LIMIT 0x08
yusuke_kyo 0:10c9fb86002f 38 #define MX28_REG_GOAL_POSITION 0x1E
yusuke_kyo 0:10c9fb86002f 39 #define MX28_REG_MOVING_SPEED 0x20
yusuke_kyo 0:10c9fb86002f 40 #define MX28_REG_VOLTS 0x2A
yusuke_kyo 0:10c9fb86002f 41 #define MX28_REG_TEMP 0x2B
yusuke_kyo 0:10c9fb86002f 42 #define MX28_REG_MOVING 0x2E
yusuke_kyo 0:10c9fb86002f 43 #define MX28_REG_POSITION 0x24
yusuke_kyo 0:10c9fb86002f 44 #define MX28_REG_CURRENT 0x44
yusuke_kyo 0:10c9fb86002f 45
yusuke_kyo 0:10c9fb86002f 46 #define MX28_MODE_POSITION 0
yusuke_kyo 0:10c9fb86002f 47 #define MX28_MODE_ROTATION 1
yusuke_kyo 0:10c9fb86002f 48
yusuke_kyo 0:10c9fb86002f 49 #define MX28_CW 1
yusuke_kyo 0:10c9fb86002f 50 #define MX28_CCW 0
yusuke_kyo 0:10c9fb86002f 51
yusuke_kyo 0:10c9fb86002f 52 class MX28 {
yusuke_kyo 0:10c9fb86002f 53
yusuke_kyo 0:10c9fb86002f 54 public:
yusuke_kyo 0:10c9fb86002f 55
yusuke_kyo 0:10c9fb86002f 56 /** Create an MX28 servo object connected to the specified serial port, with the specified ID
yusuke_kyo 0:10c9fb86002f 57 *
yusuke_kyo 0:10c9fb86002f 58 * @param pin tx pin
yusuke_kyo 0:10c9fb86002f 59 * @param pin rx pin
yusuke_kyo 0:10c9fb86002f 60 * @param int ID, the Bus ID of the servo 1-255
yusuke_kyo 0:10c9fb86002f 61 */
yusuke_kyo 0:10c9fb86002f 62 MX28(PinName tx, PinName rx, int ID);
yusuke_kyo 0:10c9fb86002f 63
yusuke_kyo 0:10c9fb86002f 64 /** Set the mode of the servo
yusuke_kyo 0:10c9fb86002f 65 * @param mode
yusuke_kyo 0:10c9fb86002f 66 * 0 = Positional, default
yusuke_kyo 0:10c9fb86002f 67 * 1 = Continuous rotation
yusuke_kyo 0:10c9fb86002f 68 */
yusuke_kyo 0:10c9fb86002f 69 int SetMode(int mode);
yusuke_kyo 0:10c9fb86002f 70
yusuke_kyo 0:10c9fb86002f 71 /** Set goal angle in integer degrees, in positional mode
yusuke_kyo 0:10c9fb86002f 72 *
yusuke_kyo 0:10c9fb86002f 73 * @param degrees 0-360
yusuke_kyo 0:10c9fb86002f 74 * @param flags, defaults to 0
yusuke_kyo 0:10c9fb86002f 75 * flags[0] = blocking, return when goal position reached
yusuke_kyo 0:10c9fb86002f 76 * flags[1] = register, activate with a broadcast trigger
yusuke_kyo 0:10c9fb86002f 77 *
yusuke_kyo 0:10c9fb86002f 78 */
yusuke_kyo 0:10c9fb86002f 79 int SetGoal(int degrees, int flags = 0);
yusuke_kyo 0:10c9fb86002f 80
yusuke_kyo 0:10c9fb86002f 81
yusuke_kyo 0:10c9fb86002f 82 /** Set the speed of the servo in continuous rotation mode
yusuke_kyo 0:10c9fb86002f 83 *
yusuke_kyo 0:10c9fb86002f 84 * @param speed, -1.0 to 1.0
yusuke_kyo 0:10c9fb86002f 85 * -1.0 = full speed counter clock wise
yusuke_kyo 0:10c9fb86002f 86 * 1.0 = full speed clock wise
yusuke_kyo 0:10c9fb86002f 87 */
yusuke_kyo 0:10c9fb86002f 88 int SetCRSpeed(float speed);
yusuke_kyo 0:10c9fb86002f 89
yusuke_kyo 0:10c9fb86002f 90
yusuke_kyo 0:10c9fb86002f 91 /** Set the clockwise limit of the servo
yusuke_kyo 0:10c9fb86002f 92 *
yusuke_kyo 0:10c9fb86002f 93 * @param degrees, 0-360
yusuke_kyo 0:10c9fb86002f 94 */
yusuke_kyo 0:10c9fb86002f 95 int SetCWLimit(int degrees);
yusuke_kyo 0:10c9fb86002f 96
yusuke_kyo 0:10c9fb86002f 97 /** Set the counter-clockwise limit of the servo
yusuke_kyo 0:10c9fb86002f 98 *
yusuke_kyo 0:10c9fb86002f 99 * @param degrees, 0-360
yusuke_kyo 0:10c9fb86002f 100 */
yusuke_kyo 0:10c9fb86002f 101 int SetCCWLimit(int degrees);
yusuke_kyo 0:10c9fb86002f 102
yusuke_kyo 0:10c9fb86002f 103 // Change the ID
yusuke_kyo 0:10c9fb86002f 104
yusuke_kyo 0:10c9fb86002f 105 /** Change the ID of a servo
yusuke_kyo 0:10c9fb86002f 106 *
yusuke_kyo 0:10c9fb86002f 107 * @param CurentID 1-255
yusuke_kyo 0:10c9fb86002f 108 * @param NewID 1-255
yusuke_kyo 0:10c9fb86002f 109 *
yusuke_kyo 0:10c9fb86002f 110 * If a servo ID is not know, the broadcast address of 0 can be used for CurrentID.
yusuke_kyo 0:10c9fb86002f 111 * In this situation, only one servo should be connected to the bus
yusuke_kyo 0:10c9fb86002f 112 */
yusuke_kyo 0:10c9fb86002f 113 int SetID(int CurrentID, int NewID);
yusuke_kyo 0:10c9fb86002f 114
yusuke_kyo 0:10c9fb86002f 115
yusuke_kyo 0:10c9fb86002f 116 /** Poll to see if the servo is moving
yusuke_kyo 0:10c9fb86002f 117 *
yusuke_kyo 0:10c9fb86002f 118 * @returns true is the servo is moving
yusuke_kyo 0:10c9fb86002f 119 */
yusuke_kyo 0:10c9fb86002f 120 int isMoving(void);
yusuke_kyo 0:10c9fb86002f 121
yusuke_kyo 0:10c9fb86002f 122 /** Send the broadcast "trigger" command, to activate any outstanding registered commands
yusuke_kyo 0:10c9fb86002f 123 */
yusuke_kyo 0:10c9fb86002f 124 void trigger(void);
yusuke_kyo 0:10c9fb86002f 125
yusuke_kyo 0:10c9fb86002f 126 /** Read the current angle of the servo
yusuke_kyo 0:10c9fb86002f 127 *
yusuke_kyo 0:10c9fb86002f 128 * @returns float in the range 0.0-360.0
yusuke_kyo 0:10c9fb86002f 129 */
yusuke_kyo 0:10c9fb86002f 130 float GetPosition();
yusuke_kyo 0:10c9fb86002f 131
yusuke_kyo 0:10c9fb86002f 132 /** Read the temperature of the servo
yusuke_kyo 0:10c9fb86002f 133 *
yusuke_kyo 0:10c9fb86002f 134 * @returns float temperature
yusuke_kyo 0:10c9fb86002f 135 */
yusuke_kyo 0:10c9fb86002f 136 float GetTemp(void);
yusuke_kyo 0:10c9fb86002f 137
yusuke_kyo 0:10c9fb86002f 138 /** Read the supply voltage of the servo
yusuke_kyo 0:10c9fb86002f 139 *
yusuke_kyo 0:10c9fb86002f 140 * @returns float voltage
yusuke_kyo 0:10c9fb86002f 141 */
yusuke_kyo 0:10c9fb86002f 142 float GetVolts(void);
yusuke_kyo 0:10c9fb86002f 143
yusuke_kyo 0:10c9fb86002f 144 /** Read the supply current of the servo
yusuke_kyo 0:10c9fb86002f 145 *
yusuke_kyo 0:10c9fb86002f 146 * @returns float current
yusuke_kyo 0:10c9fb86002f 147 */
yusuke_kyo 0:10c9fb86002f 148 float GetCurrent(void);
yusuke_kyo 0:10c9fb86002f 149
yusuke_kyo 0:10c9fb86002f 150 private :
yusuke_kyo 0:10c9fb86002f 151
yusuke_kyo 0:10c9fb86002f 152 SerialHalfDuplex _mx28;
yusuke_kyo 0:10c9fb86002f 153 int _ID;
yusuke_kyo 0:10c9fb86002f 154
yusuke_kyo 0:10c9fb86002f 155 int read(int ID, int start, int length, char* data);
yusuke_kyo 0:10c9fb86002f 156 int write(int ID, int start, int length, char* data, int flag=0);
yusuke_kyo 0:10c9fb86002f 157
yusuke_kyo 0:10c9fb86002f 158 };
yusuke_kyo 0:10c9fb86002f 159
yusuke_kyo 0:10c9fb86002f 160 #endif