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