-
Notifications
You must be signed in to change notification settings - Fork 1
/
CM730.h
154 lines (125 loc) · 3.7 KB
/
CM730.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
/**
* @autor tekatod
* @date 8/7/17
*/
#pragma once
#include <string>
#include <unordered_map>
#include "MX28.h"
namespace Robot {
class BulkReadData {
public:
int start_address;
int length;
int error;
unsigned char table[MX28::MAXNUM_ADDRESS];
BulkReadData();
virtual ~BulkReadData() {}
int ReadByte(int address);
int ReadWord(int address);
};
class CM730 {
public:
enum {
SUCCESS,
TX_CORRUPT,
TX_FAIL,
RX_FAIL,
RX_TIMEOUT,
RX_CORRUPT
};
enum {
P_MODEL_NUMBER_L = 0,
P_MODEL_NUMBER_H = 1,
P_VERSION = 2,
P_ID = 3,
P_BAUD_RATE = 4,
P_RETURN_DELAY_TIME = 5,
P_RETURN_LEVEL = 16,
P_DXL_POWER = 24,
P_LED_PANNEL = 25,
P_LED_HEAD_L = 26,
P_LED_HEAD_H = 27,
P_LED_EYE_L = 28,
P_LED_EYE_H = 29,
P_BUTTON = 30,
P_GYRO_Z_L = 38,
P_GYRO_Z_H = 39,
P_GYRO_Y_L = 40,
P_GYRO_Y_H = 41,
P_GYRO_X_L = 42,
P_GYRO_X_H = 43,
P_ACCEL_X_L = 44,
P_ACCEL_X_H = 45,
P_ACCEL_Y_L = 46,
P_ACCEL_Y_H = 47,
P_ACCEL_Z_L = 48,
P_ACCEL_Z_H = 49,
P_VOLTAGE = 50,
P_LEFT_MIC_L = 51,
P_LEFT_MIC_H = 52,
P_ADC2_L = 53,
P_ADC2_H = 54,
P_ADC3_L = 55,
P_ADC3_H = 56,
P_ADC4_L = 57,
P_ADC4_H = 58,
P_ADC5_L = 59,
P_ADC5_H = 60,
P_ADC6_L = 61,
P_ADC6_H = 62,
P_ADC7_L = 63,
P_ADC7_H = 64,
P_ADC8_L = 65,
P_ADC8_H = 66,
P_RIGHT_MIC_L = 67,
P_RIGHT_MIC_H = 68,
P_ADC10_L = 69,
P_ADC10_H = 70,
P_ADC11_L = 71,
P_ADC11_H = 72,
P_ADC12_L = 73,
P_ADC12_H = 74,
P_ADC13_L = 75,
P_ADC13_H = 76,
P_ADC14_L = 77,
P_ADC14_H = 78,
P_ADC15_L = 79,
P_ADC15_H = 80,
MAXNUM_ADDRESS
};
enum {
ID_CM = 200,
ID_BROADCAST = 254
};
BulkReadData m_BulkReadData[ID_BROADCAST];
CM730(int client_id = -1, std::string device_postfix = "");
CM730(std::string server_ip, int server_port, int client_id = -1, std::string device_postfix = "");
//This is dummy for now it can do nothing
int WriteByte(int address, int value, int* error);
//This is dummy for now it can do nothing
int WriteWord(int id, int address, int value, int* error);
//This is dummy for now it can do nothing
int ReadByte(int id, int address, int* pValue, int* error);
//This is dummy for now it can do nothing
bool Connect();
//This is dummy for now it can do nothing
void DXLPowerOn();
//Note: This works only with joints
int SyncWrite(int start_addr, int each_length, int number, int *pParam);
int ReadWord(int id, int address, int* pValue, int* error);
int BulkRead();
int get_client_id();
// Utility
static int MakeWord(int lowbyte, int highbyte);
static int GetLowByte(int word);
static int GetHighByte(int word);
~CM730();
private:
void init_devices();
int connect_device(std::string device_name);
int m_client_id;
std::string m_device_postfix;
std::unordered_map<int, int> m_sim_devices;
};
}