dynamixel_tool.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2018 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /* Authors: Taehun Lim (Darby), Ryan Shim */
18 
19 #include "../../include/dynamixel_workbench_toolbox/dynamixel_tool.h"
20 
21 //===================================================================
22 // Define Serial ID to Namd table
23 //===================================================================
24 typedef struct
25 {
26  uint16_t number;
27  const char* name;
29 
31  {AX_12A, "AX-12A"},
32  {AX_12W, "AX-12W"},
33  {AX_18A, "AX-18A"},
34 
35  {RX_10, "RX-10"},
36  {RX_24F, "RX-24F"},
37  {RX_28, "RX-28"},
38  {RX_64, "RX-64"},
39 
40  {EX_106, "EX-106"},
41 
42  {MX_12W, "MX-12W"},
43  {MX_28, "MX-28"},
44  {MX_28_2, "MX-28-2"},
45  {MX_64, "MX-64"},
46  {MX_64_2, "MX-64-2"},
47  {MX_106, "MX-106"},
48  {MX_106_2, "MX-106-2"},
49 
50  {XL_320, "XL-320"},
51  {XL430_W250, "XL430-W250"},
52 
53  {XL430_W250_2, "XL430-W250-2"}, // 2XL
54 
55  {XC430_W150, "XC430-W150"},
56  {XC430_W240, "XC430-W240"},
57 
58  {XM430_W210, "XM430-W210"},
59  {XM430_W350, "XM430-W350"},
60 
61  {XM540_W150, "XM540-W150"},
62  {XM540_W270, "XM540-W270"},
63 
64  {XH430_V210, "XH430-V210"},
65  {XH430_V350, "XH430-V350"},
66  {XH430_W210, "XH430-W210"},
67  {XH430_W350, "XH430-W350"},
68 
69  {XH540_W150, "XH540_W150"},
70  {XH540_W270, "XH540_W270"},
71  {XH540_V150, "XH540_V150"},
72  {XH540_V270, "XH540_V270"},
73 
74  {XW540_T260, "XW540_T260"},
75  {XW540_T140, "XW540_T140"},
76 
77  {PRO_L42_10_S300_R, "PRO-L42-10-S300-R"},
78  {PRO_L54_30_S400_R, "PRO-L54-30-S400-R"},
79  {PRO_L54_30_S500_R, "PRO-L54-30-S500-R"},
80  {PRO_L54_50_S290_R, "PRO-L54-50-S290-R"},
81  {PRO_L54_50_S500_R, "PRO-L54-50-S500-R"},
82 
83  {PRO_M42_10_S260_R, "PRO-M42-10-S260-R"},
84  {PRO_M54_40_S250_R, "PRO-M54-40-S250-R"},
85  {PRO_M54_60_S250_R, "PRO-M54-60-S250-R"},
86 
87  {PRO_H42_20_S300_R, "PRO-H42-20-S300-R"},
88  {PRO_H54_100_S500_R, "PRO-H54-100-S500-R"},
89  {PRO_H54_200_S500_R, "PRO-H54-200-S500-R"},
90 
91  {PRO_M42_10_S260_R_A, "PRO-M42-10-S260-R-A"},
92  {PRO_M54_40_S250_R_A, "PRO-M54-40-S250-R-A"},
93  {PRO_M54_60_S250_R_A, "PRO-M54-60-S250-R-A"},
94 
95  {PRO_H42_20_S300_R_A, "PRO-H42-20-S300-R-A"},
96  {PRO_H54_100_S500_R_A, "PRO-H54-100-S500-R-A"},
97  {PRO_H54_200_S500_R_A, "PRO-H54-200-S500-R-A"},
98 
99  {PRO_PLUS_M42P_010_S260_R, "PRO-PLUS-M42P-010-S260-R"},
100  {PRO_PLUS_M54P_040_S250_R, "PRO-PLUS-M54P-040-S250-R"},
101  {PRO_PLUS_M54P_060_S250_R, "PRO-PLUS-M54P-060-S250-R"},
102 
103  {PRO_PLUS_H42P_020_S300_R, "PRO-PLUS-H42P-020-S300-R"},
104  {PRO_PLUS_H54P_100_S500_R, "PRO-PLUS-H54P-100-S500-R"},
105  {PRO_PLUS_H54P_200_S500_R, "PRO-PLUS-H54P-200-S500-R"},
106 
107  {RH_P12_RN, "RH-P12-RN"},
108 
109  {RH_P12_RN_A, "RH-P12-RN-A"}
110 };
111 #define COUNT_DYNAMIXEL_MODEL (sizeof(dynamixel_model_table)/sizeof(dynamixel_model_table[0]))
112 
113 DynamixelTool::DynamixelTool() : dxl_cnt_(0), the_number_of_control_item_(0){}
114 
116 
118 {
119  for (uint8_t i = 0; i < DYNAMIXEL_BUFFER; i++)
120  dxl_id_[i] = 0;
121 
122  dxl_cnt_ = 0;
123 }
124 
125 bool DynamixelTool::addTool(const char *model_name, uint8_t id, const char **log)
126 {
127  bool result = false;
128  initTool();
129 
131  result = setModelNumber(model_name, log);
132  if (result == false) return false;
133  dxl_id_[dxl_cnt_++] = id;
134 
135  result = setControlTable(model_name, log);
136  if (result == false) return false;
137 
138  return true;
139 }
140 
141 bool DynamixelTool::addTool(uint16_t model_number, uint8_t id, const char **log)
142 {
143  bool result = false;
144  initTool();
145 
146  result = setModelName(model_number, log);
147  if (result == false) return false;
148  model_number_ = model_number;
149  dxl_id_[dxl_cnt_++] = id;
150 
151  result = setControlTable(model_number, log);
152  if (result == false) return false;
153 
154  return result;
155 }
156 
157 void DynamixelTool::addDXL(uint8_t id)
158 {
159  dxl_id_[dxl_cnt_++] = id;
160 }
161 
162 bool DynamixelTool::setControlTable(const char *model_name, const char **log)
163 {
164  const char* name = model_name;
165  uint8_t name_length = strlen(name);
166 
167  for (uint8_t index=0; index < COUNT_DYNAMIXEL_MODEL; index++)
168  {
169  if(strncmp(name, dynamixel_model_table[index].name, name_length) == 0)
170  {
171  return setControlTable(dynamixel_model_table[index].number, log);
172  }
173  }
174 
175  if (log != NULL)
176  *log = "[DynamixelTool] Failed to set control table due to mismatch model name and model number";
177  return false;
178 }
179 
180 bool DynamixelTool::setControlTable(uint16_t model_number, const char **log)
181 {
185 
186  if (control_table_ == NULL || model_info_ == NULL)
187  {
188  if (log != NULL)
189  *log = "[DynamixelTool] Failed to get control table or model info";
190  return false;
191  }
192 
193  return true;
194 }
195 
196 bool DynamixelTool::setModelName(uint16_t model_number, const char **log)
197 {
198  uint16_t num = model_number;
199 
200  for (uint8_t index=0; index < COUNT_DYNAMIXEL_MODEL; index++)
201  {
202  if (num == dynamixel_model_table[index].number)
203  {
204  model_name_ = dynamixel_model_table[index].name;
205  return true;
206  }
207  }
208 
209  if (log != NULL)
210  *log = "[DynamixelTool] Failed to find model name";
211  return false;
212 }
213 
214 bool DynamixelTool::setModelNumber(const char *model_name, const char **log)
215 {
216  const char* name = model_name;
217  uint8_t name_length = strlen(name);
218 
219  for (uint8_t index=0; index < COUNT_DYNAMIXEL_MODEL; index++)
220  {
221  if(strncmp(name, model_name_, name_length) == 0)
222  {
223  model_number_ = dynamixel_model_table[index].number;
224  return true;
225  }
226  }
227 
228  if (log != NULL)
229  *log = "[DynamixelTool] Failed to find model number";
230  return false;
231 }
232 
234 {
235  return model_name_;
236 }
237 
239 {
240  return model_number_;
241 }
242 
243 const uint8_t* DynamixelTool::getID(void)
244 {
245  const uint8_t* id_table_ = dxl_id_;
246 
247  return id_table_;
248 }
249 
251 {
252  return dxl_cnt_;
253 }
254 
256 {
257  return DYNAMIXEL_BUFFER;
258 }
259 
261 {
262  return model_info_->rpm;
263 }
264 
266 {
268 }
269 
271 {
273 }
274 
276 {
278 }
279 
281 {
282  return model_info_->min_radian;
283 }
284 
286 {
287  return model_info_->max_radian;
288 }
289 
291 {
293 }
294 
295 const ControlItem *DynamixelTool::getControlItem(const char *item_name, const char **log)
296 {
297  const ControlItem* control_item = control_table_;
298  uint8_t name_length = strlen(item_name);
299 
300  for (uint8_t num = 0; num < the_number_of_control_item_; num++)
301  {
302  if ((name_length == control_item->item_name_length) &&
303  (memcmp(item_name, control_item->item_name, name_length) == 0))
304  {
305  return control_item;
306  }
307  control_item++;
308  }
309 
310  if (log != NULL)
311  *log = "[DynamixelTool] Can't find Item";
312  return NULL;
313 }
314 
316 {
317  return control_table_;
318 }
319 
321 {
322  return model_info_;
323 }
324 
const ControlItem * getControlTable(uint16_t model_number)
static const DynamixelModel dynamixel_model_table[]
const ModelInfo * model_info_
const ControlItem * getControlItem(const char *item_name, const char **log=NULL)
const ModelInfo * getModelInfo(void)
#define MX_28
#define RH_P12_RN_A
#define PRO_H54_100_S500_R
bool setControlTable(const char *model_name, const char **log=NULL)
#define PRO_M54_60_S250_R_A
#define XH540_V150
#define XM540_W270
#define XH540_W150
uint16_t model_number_
#define XM430_W350
#define RX_64
float getMaxRadian(void)
#define PRO_M42_10_S260_R_A
#define RX_24F
#define AX_12A
int64_t value_of_min_radian_position
#define PRO_M54_40_S250_R
#define MX_64_2
#define XC430_W240
int64_t getValueOfMaxRadianPosition(void)
#define PRO_H54_100_S500_R_A
uint8_t getTheNumberOfControlItem()
static const char * model_name
const ModelInfo * getModelInfo(uint16_t model_number)
#define PRO_PLUS_H54P_100_S500_R
uint8_t dxl_id_[DYNAMIXEL_BUFFER]
#define MX_106_2
#define XH430_W210
uint8_t dxl_cnt_
float getRPM(void)
#define XW540_T140
#define PRO_L54_50_S290_R
#define RX_28
#define PRO_PLUS_M42P_010_S260_R
float getMinRadian(void)
#define AX_12W
uint8_t item_name_length
int64_t value_of_max_radian_position
float max_radian
#define XM540_W150
#define AX_18A
#define XH540_V270
#define PRO_PLUS_M54P_060_S250_R
#define MX_12W
#define XL_320
uint8_t getDynamixelCount(void)
#define XL430_W250_2
const ControlItem * getControlTable(void)
uint8_t getTheNumberOfControlItem(void)
#define PRO_L54_50_S500_R
bool setModelName(uint16_t model_number, const char **log=NULL)
#define PRO_H42_20_S300_R
const ControlItem * control_table_
const char * model_name_
#define PRO_PLUS_H54P_200_S500_R
int64_t getValueOfZeroRadianPosition(void)
#define RX_10
void initTool(void)
const char * getModelName(void)
#define XH540_W270
#define MX_64
int64_t value_of_zero_radian_position
#define XH430_W350
#define MX_28_2
#define PRO_M42_10_S260_R
const uint8_t * getID(void)
#define XL430_W250
#define COUNT_DYNAMIXEL_MODEL
#define PRO_M54_40_S250_R_A
void addDXL(uint8_t id)
uint8_t getDynamixelBuffer(void)
#define PRO_H54_200_S500_R_A
#define EX_106
bool setModelNumber(const char *model_name, const char **log=NULL)
#define XH430_V210
#define MX_106
#define XH430_V350
#define PRO_L54_30_S400_R
#define RH_P12_RN
const char * name
#define PRO_M54_60_S250_R
#define PRO_H54_200_S500_R
bool addTool(const char *model_name, uint8_t id, const char **log=NULL)
#define XM430_W210
#define PRO_H42_20_S300_R_A
int64_t getValueOfMinRadianPosition(void)
#define PRO_L42_10_S300_R
uint16_t getModelNumber(void)
#define PRO_PLUS_H42P_020_S300_R
#define PRO_PLUS_M54P_040_S250_R
#define XW540_T260
#define XC430_W150
float min_radian
const char * item_name
uint16_t the_number_of_control_item_
#define PRO_L54_30_S500_R


dynamixel_workbench_toolbox
Author(s): Darby Lim , Ryan Shim
autogenerated on Mon Sep 28 2020 03:37:05