e_Mode_Change.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  int dxl_id = 1;
26  int mode = 0;
27 
28  if (argc < 4)
29  {
30  printf("Please set '-port_name', '-baud_rate', '-dynamixel id' arguments for connected Dynamixels\n");
31  return 0;
32  }
33  else
34  {
35  port_name = argv[1];
36  baud_rate = atoi(argv[2]);
37  dxl_id = atoi(argv[3]);
38  }
39 
41 
42  const char *log;
43  bool result = false;
44 
45  uint16_t model_number = 0;
46 
47  result = dxl_wb.init(port_name, baud_rate, &log);
48  if (result == false)
49  {
50  printf("%s\n", log);
51  printf("Failed to init\n");
52 
53  return 0;
54  }
55  else
56  printf("Succeeded to init(%d)\n", baud_rate);
57 
58  result = dxl_wb.ping(dxl_id, &model_number, &log);
59  if (result == false)
60  {
61  printf("%s\n", log);
62  printf("Failed to ping\n");
63  }
64  else
65  {
66  printf("Succeeded to ping\n");
67  printf("id : %d, model_number : %d\n", dxl_id, model_number);
68  }
69 
70  printf("---> \n");
71  printf("Please insert the right number from 0 to 5 to set control mode \n");
72  printf("0 - current control mode\n");
73  printf("1 - velocity control mode\n");
74  printf("2 - position control mode\n");
75  printf("3 - extended position control mode\n");
76  printf("4 - current based position control mode\n");
77  printf("5 - pwm control mode\n");
78  printf("<--- \n\n");
79 
80  scanf("%d", &mode);
81 
82  switch (mode)
83  {
84  case 0:
85  result = dxl_wb.setCurrentControlMode(dxl_id, &log);
86  if (result == false)
87  {
88  printf("%s\n", log);
89  printf("Failed to set mode\n");
90  }
91  else
92  {
93  printf("Succeeded to set mode\n");
94  }
95  break;
96 
97  case 1:
98  result = dxl_wb.setVelocityControlMode(dxl_id, &log);
99  if (result == false)
100  {
101  printf("%s\n", log);
102  printf("Failed to set mode\n");
103  }
104  else
105  {
106  printf("Succeeded to set mode\n");
107  }
108  break;
109 
110  case 2:
111  result = dxl_wb.setPositionControlMode(dxl_id, &log);
112  if (result == false)
113  {
114  printf("%s\n", log);
115  printf("Failed to set mode\n");
116  }
117  else
118  {
119  printf("Succeeded to set mode\n");
120  }
121  break;
122 
123  case 3:
124  result = dxl_wb.setExtendedPositionControlMode(dxl_id, &log);
125  if (result == false)
126  {
127  printf("%s\n", log);
128  printf("Failed to set mode\n");
129  }
130  else
131  {
132  printf("Succeeded to set mode\n");
133  }
134  break;
135 
136  case 4:
137  result = dxl_wb.setCurrentBasedPositionControlMode(dxl_id, &log);
138  if (result == false)
139  {
140  printf("%s\n", log);
141  printf("Failed to set mode\n");
142  }
143  else
144  {
145  printf("Succeeded to set mode\n");
146  }
147  break;
148 
149  case 5:
150  result = dxl_wb.setPWMControlMode(dxl_id, &log);
151  if (result == false)
152  {
153  printf("%s\n", log);
154  printf("Failed to set mode\n");
155  }
156  else
157  {
158  printf("Succeeded to set mode\n");
159  }
160  break;
161 
162  default:
163  result = dxl_wb.setPositionControlMode(dxl_id, &log);
164  if (result == false)
165  {
166  printf("%s\n", log);
167  printf("Failed to set mode\n");
168  }
169  else
170  {
171  printf("Succeeded to set mode\n");
172  }
173  break;
174  }
175 
176  return 0;
177 }
bool setCurrentBasedPositionControlMode(uint8_t id, const char **log=NULL)
bool setCurrentControlMode(uint8_t id, const char **log=NULL)
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
bool setExtendedPositionControlMode(uint8_t id, const char **log=NULL)
bool ping(uint8_t id, uint16_t *get_model_number, const char **log=NULL)
bool setVelocityControlMode(uint8_t id, const char **log=NULL)
bool setPWMControlMode(uint8_t id, const char **log=NULL)
bool setPositionControlMode(uint8_t id, 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