a_Model_Scan.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 <DynamixelWorkbench.h>
20 
21 int main(int argc, char *argv[])
22 {
23  const char* port_name = "/dev/ttyUSB0";
24  int baud_rate = 57600;
25 
26  if (argc < 3)
27  {
28  printf("Please set '-port_name' and '-baud_rate' arguments for connected Dynamixels\n");
29  return 0;
30  }
31  else
32  {
33  port_name = argv[1];
34  baud_rate = atoi(argv[2]);
35  }
36 
38 
39  const char *log;
40  bool result = false;
41 
42  uint8_t scanned_id[16];
43  uint8_t dxl_cnt = 0;
44  uint8_t range = 100;
45 
46  result = dxl_wb.init(port_name, baud_rate, &log);
47  if (result == false)
48  {
49  printf("%s\n", log);
50  printf("Failed to init\n");
51 
52  return 0;
53  }
54  else
55  printf("Succeeded to init(%d)\n", baud_rate);
56 
57  printf("Wait for scan...\n");
58  result = dxl_wb.scan(scanned_id, &dxl_cnt, range, &log);
59  if (result == false)
60  {
61  printf("%s\n", log);
62  printf("Failed to scan\n");
63  }
64  else
65  {
66  printf("Find %d Dynamixels\n", dxl_cnt);
67 
68  for (int cnt = 0; cnt < dxl_cnt; cnt++)
69  printf("id : %d, model name : %s\n", scanned_id[cnt], dxl_wb.getModelName(scanned_id[cnt]));
70  }
71 
72  return 0;
73 }
bool init(const char *device_name="/dev/ttyUSB0", uint32_t baud_rate=57600, const char **log=NULL)
DynamixelWorkbench dxl_wb
Definition: p_Monitor.cpp:40
const char * getModelName(uint8_t id, const char **log=NULL)
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_toolbox
Author(s): Darby Lim , Ryan Shim
autogenerated on Mon Sep 28 2020 03:37:05