find_dynamixel.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) */
18 
19 #include <ros/ros.h>
21 
22 #define BAUDRATE_NUM 7
23 
24 int main(int argc, char *argv[])
25 {
26  std::string port_name = "/dev/ttyUSB0";
27 
28  if (argc < 2)
29  {
30  printf("Please set '-port_name'arguments for connected Dynamixels\n");
31  return 0;
32  }
33  else
34  {
35  port_name = argv[1];
36  }
37 
39 
40  const char *log;
41  bool result = false;
42 
43  uint8_t scanned_id[100];
44  uint8_t dxl_cnt = 0;
45 
46  uint32_t baudrate[BAUDRATE_NUM] = {9600, 57600, 115200, 1000000, 2000000, 3000000, 4000000};
47  uint8_t range = 253;
48 
49  uint8_t index = 0;
50 
51  while (index < BAUDRATE_NUM)
52  {
53  result = dxl_wb.init(port_name.c_str(), baudrate[index], &log);
54  if (result == false)
55  {
56  ROS_WARN("%s", log);
57  ROS_WARN("Failed to init");
58  }
59  else
60  {
61  ROS_INFO("Succeed to init(%d)", baudrate[index]);
62  }
63 
64  dxl_cnt = 0;
65  for (uint8_t num = 0; num < 100; num++) scanned_id[num] = 0;
66 
67  ROS_INFO("Wait for scanning...");
68  result = dxl_wb.scan(scanned_id, &dxl_cnt, range, &log);
69  if (result == false)
70  {
71  ROS_WARN("%s", log);
72  ROS_WARN("Failed to scan");
73  }
74  else
75  {
76  ROS_INFO("Find %d Dynamixels", dxl_cnt);
77 
78  for (int cnt = 0; cnt < dxl_cnt; cnt++)
79  ROS_INFO("id : %d, model name : %s", scanned_id[cnt], dxl_wb.getModelName(scanned_id[cnt]));
80  }
81 
82  index++;
83  }
84 
85  return 0;
86 }
bool init(const char *device_name="/dev/ttyUSB0", uint32_t baud_rate=57600, const char **log=NULL)
DynamixelWorkbench dxl_wb
const char * getModelName(uint8_t id, const char **log=NULL)
#define ROS_WARN(...)
#define BAUDRATE_NUM
#define ROS_INFO(...)
bool scan(uint8_t *get_id, uint8_t *get_the_number_of_id, uint8_t range=253, const char **log=NULL)
int main(int argc, char *argv[])


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