]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/peripherals/AX12/AX12.h
1 /* mbed AX-12+ Servo Library
3 * Copyright (c) 2010, cstyles (http://mbed.org)
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
29 #define AX12_WRITE_DEBUG 1
30 #define AX12_READ_DEBUG 1
31 #define AX12_TRIGGER_DEBUG 1
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
45 #define AX12_MODE_POSITION 0
46 #define AX12_MODE_ROTATION 1
51 /** Servo control class, based on a PwmOut
60 * AX12 myax12 (p9, p10, 1);
63 * myax12.SetGoal(0); // go to 0 degrees
65 * myax12.SetGoal(300); // go to 300 degrees
75 /** Create an AX12 servo object connected to the specified serial port, with the specified ID
79 * @param int ID, the Bus ID of the servo 1-255
81 AX12(PinName tx
, PinName rx
, int ID
, int baud
=1000000);
83 /** Set the mode of the servo
85 * 0 = Positional, default
86 * 1 = Continuous rotation
88 int SetMode(int mode
);
90 /** Set baud rate of all attached servos
92 * 0x01 = 1,000,000 bps
102 int SetBaud(int baud
);
105 /** Set goal angle in integer degrees, in positional mode
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
113 int SetGoal(int degrees
, int flags
= 0);
116 /** Set the speed of the servo in continuous rotation mode
118 * @param speed, -1.0 to 1.0
119 * -1.0 = full speed counter clock wise
120 * 1.0 = full speed clock wise
122 int SetCRSpeed(float speed
);
125 /** Set the clockwise limit of the servo
127 * @param degrees, 0-300
129 int SetCWLimit(int degrees
);
131 /** Set the counter-clockwise limit of the servo
133 * @param degrees, 0-300
135 int SetCCWLimit(int degrees
);
139 /** Change the ID of a servo
141 * @param CurentID 1-255
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
147 int SetID(int CurrentID
, int NewID
);
150 /** Poll to see if the servo is moving
152 * @returns true is the servo is moving
156 /** Send the broadcast "trigger" command, to activate any outstanding registered commands
160 /** Read the current angle of the servo
162 * @returns float in the range 0.0-300.0
166 /** Read the temperature of the servo
168 * @returns float temperature
172 /** Read the supply voltage of the servo
174 * @returns float voltage
176 float GetVolts(void);
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);
183 SerialHalfDuplex _ax12
;