-
Notifications
You must be signed in to change notification settings - Fork 0
/
ax12.h
166 lines (133 loc) · 4.53 KB
/
ax12.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* ax12.h - C18 library to use the AX-12 servomotor (Dynamixel Series) from
* Robotis on the PIC18F family from Microchip.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AX12_H
#define _AX12_H
#define PIN_REMAPABLE_AX12_OUT _RP10R
#define PIN_REMAPABLE_AX12_IN 10
#define TRIS_PIN_REMAPABLE_AX12 _TRISB10
#define OPEN_DRAIN_PIN_REMAPABLE_AX12 _ODCB10
//#define DOUBLE_COMMANDE_AX12
#define TEST_RECEPTION_AX12
typedef unsigned char byte;
// EEPROM Registers
#define AX_MODEL_NUMBER 0
#define AX_VERSION 2
#define AX_ID 3
#define AX_BAUD_RATE 4
#define AX_RETURN_DELAY_TIME 5
#define AX_CW_ANGLE_LIMIT 6
#define AX_CCW_ANGLE_LIMIT 8
#define AX_RESERVED_1 10
#define AX_LIMIT_TEMPERATURE 11
#define AX_DOWN_LIMIT_VOLTAGE 12
#define AX_UP_LIMIT_VOLTAGE 13
#define AX_MAX_TORQUE 14
#define AX_RETURN_LEVEL 16
#define AX_ALARM_LED 17
#define AX_ALARM_SHUTDOWN 18
#define AX_RESERVED_2 19
#define AX_DOWN_CALIBRATION 20
#define AX_UP_CALIBRATION 22
// RAM Registers
#define AX_TORQUE_ENABLE 24
#define AX_LED 25
#define AX_CW_COMPLIANCE_MARGIN 26
#define AX_CCW_COMPLIANCE_MARGIN 27
#define AX_CW_COMPLIANCE_SLOPE 28
#define AX_CCW_COMPLIANCE_SLOPE 29
#define AX_GOAL_POSITION 30
#define AX_MOVING_SPEED 32
#define AX_TORQUE_LIMIT 34
#define AX_PRESENT_POSITION 36
#define AX_PRESENT_SPEED 38
#define AX_PRESENT_LOAD 40
#define AX_PRESENT_VOLTAGE 42
#define AX_PRESENT_TEMPERATURE 43
#define AX_REGISTERED_INSTRUCTION 44
#define AX_PAUSE_TIME 45
#define AX_MOVING 46
#define AX_LOCK 47
#define AX_PUNCH 48
// Status Return Levels
#define AX_RETURN_NONE 0
#define AX_RETURN_READ 1
#define AX_RETURN_ALL 2
// Instruction Set
#define AX_INST_PING 1
#define AX_INST_READ_DATA 2
#define AX_INST_WRITE_DATA 3
#define AX_INST_REG_WRITE 4
#define AX_INST_ACTION 5
#define AX_INST_RESET 6
#define AX_INST_SYNC_WRITE 131
// Broadcast ID
#define AX_GAUCHE 3
#define AX_DROIT 2
#define AX_BROADCAST 254
/*
* Stucture to decode error fields used in the return status, address17 and
* address18, where each bit has a different meaning.
*/
typedef struct {
unsigned input_voltage : 1;
unsigned angle_limit : 1;
unsigned overheating : 1;
unsigned range : 1;
unsigned cheksum : 1;
unsigned overload : 1;
unsigned instruction : 1;
unsigned : 1;
} errorAX;
/*
* Public global variables.
*/
extern volatile int responseReadyAX;
typedef volatile struct {
byte id;
byte len;
errorAX error;
byte params[10]; // Could be larger.
} responseAXtype;
extern responseAXtype responseAX;
void Init_IT_AX12 (void);
/*
* Function prototypes.
*/
void SetTX(void);
void SetRX(void);
void PushUART(byte b);
void InterruptAX(void);
void PushHeaderAX(byte id, byte len, byte inst);
void PushBufferAX(byte len, byte* buf);
void PushFooterAX(void);
void PingAX(byte id);
void ReadAX(byte id, byte address, byte len);
void WriteAX(byte id, byte address, byte len, byte* buf);
void RegWriteAX(byte id, byte address, byte len, byte* buf);
void ActionAX(byte id);
void ResetAX(byte id);
//void SyncWriteAX(byte id, ...);
byte RegisterLenAX(byte address);
char GetAX(byte id, byte address);
//void PutAX(byte id, byte address, int value);
char PutAX(byte id, byte address, int value);
extern volatile int Delay_TimeOut_AX12;
char PutAX_Check(byte id, byte address, int value);
char GetAX_Check (byte id, byte address);
int GetAX_Pos (byte id);
#endif /* _AX12_H */