48 struct termios oldt, newt;
51 tcgetattr( STDIN_FILENO, &oldt );
53 newt.c_lflag &= ~(ICANON | ECHO);
56 tcsetattr( STDIN_FILENO, TCSANOW, &newt );
58 tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
65 struct termios oldt, newt;
69 tcgetattr(STDIN_FILENO, &oldt);
71 newt.c_lflag &= ~(ICANON | ECHO);
72 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
73 oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
74 fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
78 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
79 fcntl(STDIN_FILENO, F_SETFL, oldf);
91 printf(
"----------------------------------------------------------------------\n");
92 printf(
"Single Manager supports GUI (dynamixel_workbench_single_manager_gui) \n");
93 printf(
"----------------------------------------------------------------------\n");
94 printf(
"Command list :\n");
95 printf(
"[help|h|?]...............: help\n");
96 printf(
"[info]...................: information of a Dynamixel\n");
97 printf(
"[table]..................: check a control table of a Dynamixel\n");
98 printf(
"[torque_on]..............: torque on Dynamixel\n");
99 printf(
"[torque_off].............: torque off Dynamixel\n");
100 printf(
"[joint] [data]...........: set data to goal position address\n");
101 printf(
"[wheel] [data]...........: set data to goal position address\n");
102 printf(
"[id] [new id]............: change id\n");
103 printf(
"[baud] [new baud]........: change baud rate\n");
104 printf(
"[version] [new version]..: change protocol version\n");
105 printf(
"[reboot].................: reboot a Dynamixel(only protocol version 2.0)\n");
106 printf(
"[reset]..................: command for all data back to factory settings values\n");
107 printf(
"[address name] [data]....: change address value of a Dynamixel\n");
108 printf(
"[exit]...................: shutdown\n");
109 printf(
"----------------------------------------------------------------------\n");
110 printf(
"Press Enter Key To Command A Dynamixel\n");
115 dynamixel_workbench_msgs::DynamixelCommand set_dynamixel_command;
117 set_dynamixel_command.request.command = cmd;
118 set_dynamixel_command.request.addr_name = addr;
119 set_dynamixel_command.request.value = value;
123 if (!set_dynamixel_command.response.comm_result)
137 bool valid_cmd =
false;
146 fgets(input,
sizeof(input), stdin);
149 if ((p = strchr(input,
'\n'))!= NULL) *p =
'\0';
152 if (strlen(input) == 0)
return false;
154 token = strtok(input,
" ");
156 if (token == 0)
return false;
159 token = strtok(0,
" ");
164 strcpy(param[num_param++], token);
165 token = strtok(0,
" ");
168 if (strcmp(cmd,
"help") == 0 || strcmp(cmd,
"h") == 0 || strcmp(cmd,
"?") == 0)
172 else if (strcmp(cmd,
"info") == 0)
174 dynamixel_workbench_msgs::GetDynamixelInfo get_dynamixel_info;
178 printf(
"[ID] %u, [Model Name] %s, [Protocol Version] %1.f.0, [BAUD RATE] %ld\n", get_dynamixel_info.response.dynamixel_info.model_id,
179 get_dynamixel_info.response.dynamixel_info.model_name.c_str(),
180 get_dynamixel_info.response.dynamixel_info.load_info.protocol_version,
181 get_dynamixel_info.response.dynamixel_info.load_info.baud_rate);
184 else if (strcmp(cmd,
"exit") == 0)
191 else if (strcmp(cmd,
"table") == 0)
194 printf(
"It didn't load DYNAMIXEL Control Table\n");
196 else if (strcmp(cmd,
"reboot") == 0)
199 printf(
"It didn't reboot to DYNAMIXEL\n");
201 else if (strcmp(cmd,
"reset") == 0)
204 printf(
"It didn't factory reset to DYNAMIXEL\n");
206 else if (strcmp(cmd,
"torque_on") == 0)
209 printf(
"It didn't works\n");
213 else if (strcmp(cmd,
"torque_off") == 0)
216 printf(
"It didn't works\n");
218 printf(
"Torque Off");
220 else if (strcmp(cmd,
"id") == 0)
223 printf(
"It didn't works\n");
225 else if (strcmp(cmd,
"baud") == 0)
228 printf(
"It didn't works\n");
230 else if (strcmp(cmd,
"version") == 0)
233 printf(
"It didn't works\n");
235 else if (strcmp(cmd,
"joint") == 0)
238 printf(
"It didn't works\n");
240 else if (strcmp(cmd,
"wheel") == 0)
243 printf(
"It didn't works\n");
245 else if (num_param == 1)
248 printf(
"It works!!\n");
250 printf(
"It didn't works!!\n");
254 printf(
"Invalid command. Please check menu[help, h, ?]\n");
260 int main(
int argc,
char **argv)
263 ros::init(argc, argv,
"single_dynamixel_controller");
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
bool shutdownSingleDynamixelController()
#define ENTER_ASCII_VALUE
ros::ServiceClient dynamixel_command_client_
bool sendCommandMsg(std::string cmd, std::string addr="", int64_t value=0)
bool initSingleDynamixelController()
ros::ServiceClient dynamixel_info_client_
ROSCPP_DECL void shutdown()
ros::NodeHandle node_handle_
~SingleDynamixelController()
void viewManagerMenu(void)
ROSCPP_DECL void spinOnce()
int main(int argc, char **argv)
SingleDynamixelController()