action_editor.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 /*
18  * action_editor.cpp
19  *
20  * Created on: 2016. 12. 16.
21  * Author: Jay Song
22  */
23 
25 
26 using namespace thormang3;
27 
29 {
30  ctrl_ = 0;
31  robot_ = 0;
32 
33  cmd_col_ = 2;
34  stp7_col_ = 19+2;
35  stp0_col_ = 25+2;
36  stp1_col_ = 30+2;
37  stp2_col_ = 35+2;
38  stp3_col_ = 40+2;
39  stp4_col_ = 45+2;
40  stp5_col_ = 50+2;
41  stp6_col_ = 55+2;
42  cwslope_col_ = 60+2;
43  ccwslope_col_ = 61+2;
44  name_col_ = 63+2;
45  addr_col_ = 72+2;
46  pagenum_col_ = 75+2;
47  pageparam_col_ = 76+2;
48 
49  name_row_ = 0;
50  page_num_row_ = 1;
51  addr_row_ = 2;
52  play_count_row_ = 3;
53  step_num_row_ = 4;
54  play_time_row_ = 5;
55  accel_row_ = 6;
56  next_row_ = 7;
57  exit_row_ = 8;
58 
59  first_joint_row_ = 0;
60  begin_command_mode_ = false;
61  edited_ = false;
62  page_idx_ = 1;
65 
68 
70 
71  //The below variables will be initialized in initialize function.
72  num_of_dxls_ = 1;
73 
74  first_joint_row_ = 0;
76 
78  time_row_ = pause_row_ + 1;
79  cmd_row_ = time_row_ + 2;
80 
81  screen_col_ = 80;
82  screen_row_ = cmd_row_ + 1;
83 }
84 
86 {
87 
88 }
89 
91 {
92  struct termios oldt, newt;
93  int ch;
94  tcgetattr( STDIN_FILENO, &oldt);
95  newt = oldt;
96  newt.c_lflag &= ~(ICANON | ECHO);
97  tcsetattr( STDIN_FILENO, TCSANOW, &newt);
98  ch = getchar();
99  tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
100  return ch;
101 }
102 
104 {
105  struct termios oldt, newt;
106  int ch;
107  int oldf;
108 
109  tcgetattr(STDIN_FILENO, &oldt);
110  newt = oldt;
111  newt.c_lflag &= ~(ICANON | ECHO);
112  tcsetattr(STDIN_FILENO, TCSANOW, &newt);
113  oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
114  fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
115 
116  ch = getchar();
117 
118  tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
119  fcntl(STDIN_FILENO, F_SETFL, oldf);
120 
121  if (ch != EOF)
122  {
123  ungetc(ch, stdin);
124  return 1;
125  }
126 
127  return 0;
128 }
129 
131 {
132  tcgetattr(0, &oldterm);
133  new_term = oldterm;
134  new_term.c_lflag &= ~(ICANON | ECHO | ISIG); // �ǹ̴� struct termios�� ã���� ��.
135  new_term.c_cc[VMIN] = 1;
136  new_term.c_cc[VTIME] = 0;
137  tcsetattr(0, TCSANOW, &new_term);
138 }
139 
141 {
142  tcsetattr(0, TCSANOW, &oldterm);
143 }
144 
145 void ActionEditor::goToCursor(int col, int row)
146 {
147  char *cursor;
148  char *esc_sequence;
149  cursor = tigetstr("cup");
150  esc_sequence = tparm(cursor, row, col);
151  putp(esc_sequence);
152 
153  curr_col_ = col;
154  curr_row_ = row;
155 }
156 
158 {
160  {
162  {
163  // If last_joint_row_ is less than 9 and the difference from pause_row_ is not 1,
164  // it must be specified separately if it is pause_row_.
165  if(curr_row_ == pause_row_)
167  else
169  }
170  }
171  else
172  {
175  }
176 }
177 
179 {
180  if (curr_col_ >= stp7_col_ && curr_col_ <= stp6_col_)
181  {
182  if(curr_row_ < time_row_)
183  {
184  // If last_joint_row_ is less than 9 and the difference from pause_row_ is not 1,
185  // it must be specified separately if it is last_joint_row_.
188  else
190  }
191  }
192  else if (curr_col_ <= ccwslope_col_)
193  {
196  }
197  else
198  {
199  if (curr_row_ < exit_row_)
201  }
202 }
203 
205 {
206  if (curr_col_ == stp0_col_)
208  else if (curr_col_ == stp1_col_)
210  else if (curr_col_ == stp2_col_)
212  else if (curr_col_ == stp3_col_)
214  else if (curr_col_ == stp4_col_)
216  else if (curr_col_ == stp5_col_)
218  else if (curr_col_ == stp6_col_)
220  else if (curr_col_ == cwslope_col_)
222  else if (curr_col_ == ccwslope_col_)
224  else if (curr_col_ == pageparam_col_)
226  else
227  return;
228 }
229 
231 {
232  if (curr_col_ == stp7_col_)
234  else if (curr_col_ == stp0_col_)
236  else if (curr_col_ == stp1_col_)
238  else if (curr_col_ == stp2_col_)
240  else if (curr_col_ == stp3_col_)
242  else if (curr_col_ == stp4_col_)
244  else if (curr_col_ == stp5_col_)
246  else if (curr_col_ == stp6_col_)
248  else if (curr_col_ == cwslope_col_)
250  else if (curr_col_ == ccwslope_col_)
251  {
254  }
255  else
256  return;
257 }
258 
259 bool ActionEditor::initializeActionEditor(std::string robot_file_path, std::string init_file_path, std::string offset_file_path)
260 {
262 
263  //Controller Initialize with robot file info
264  if (ctrl_->initialize(robot_file_path, init_file_path) == false)
265  {
266  ROS_ERROR("ROBOTIS Controller Initialize Fail!");
267  return false;
268  }
269  ctrl_->loadOffset(offset_file_path);
270  ctrl_->addMotionModule((robotis_framework::MotionModule*)ActionModule::getInstance());
271  ActionModule::getInstance()->enableAllJoints();
272 
273  robot_ = ctrl_->robot_;
274 
275  //Initialize Publisher
276  ros::NodeHandle nh;
277  enable_ctrl_module_pub_ = nh.advertise<std_msgs::String>("/robotis/enable_ctrl_module", 0);
278  play_sound_pub_ = nh.advertise<std_msgs::String>("/play_sound_file", 0);
279 
280  //Initialize Member variable
281  for(std::map<std::string, robotis_framework::Dynamixel*>::iterator it = robot_->dxls_.begin(); it != robot_->dxls_.end(); it++)
282  {
283  std::string joint_name = it->first;
284  robotis_framework::Dynamixel* dxl_info = it->second;
285 
286  joint_name_to_id_[joint_name] = dxl_info->id_;
287  joint_id_to_name_[dxl_info->id_] = joint_name;
288  }
289 
290  //Since joint_id_to_name_ is automatically sorted by id,
291  //joint_id_to_row_index_ should be initialized after initialization of joint_id_to_name_.
292  int row_idx = 0;
293  for(std::map<int, std::string>::iterator it = joint_id_to_name_.begin(); it != joint_id_to_name_.end(); it++)
294  {
295  int id = it->first;
296  if((id != 0) && (id <= action_file_define::MAXNUM_JOINTS))
297  {
298  joint_id_to_row_index_[id] = row_idx;
299  joint_row_index_to_id_[row_idx] = id;
300  row_idx++;
301  }
302  }
303 
305 
306  first_joint_row_ = 0;
308 
309  if(last_joint_row_ < 9)
310  pause_row_ = 9 + 1;
311  else
313 
314 
315  time_row_ = pause_row_ + 1;
316  cmd_row_ = time_row_ + 2;
317 
318  screen_col_ = 80;
319  screen_row_ = cmd_row_ + 1;
320 
324  for (std::map<std::string, dynamixel::PortHandler *>::iterator it = robot_->ports_.begin();
325  it != robot_->ports_.end(); it++)
326  {
328  it->second, dynamixel::PacketHandler::getPacketHandler(2.0), 596, // "profile_velocity"
329  8);
330  }
331 
332  default_editor_script_path_ = ros::package::getPath("op3_action_editor") + "/script/editor_script.yaml";
333  mirror_joint_file_path_ = ros::package::getPath("op3_action_editor") + "/config/config_mirror_joint.yaml";
334 
335  // for mirroring
340 
341  loadMirrorJoint();
342 
343  return true;
344 }
345 
347 {
348  double rad = (w4095 - 2048)*M_PI/2048.0;
349  return robot_->dxls_[joint_id_to_name_[id]]->convertRadian2Value(rad);
350 }
351 
352 int ActionEditor::convertPositionValueTo4095(int id, int PositionValue)
353 {
354  double rad = robot_->dxls_[joint_id_to_name_[id]]->convertValue2Radian(PositionValue);
355  return (int)((rad + M_PI)*2048.0/M_PI);
356 }
357 
358 int ActionEditor::convert4095ToMirror(int id, int w4095)
359 {
360  return 4095 - w4095;
361 }
362 
363 bool ActionEditor::loadMp3Path(int mp3_index, std::string &path)
364 {
365  YAML::Node doc;
366 
367  try
368  {
369  // load yaml
370  doc = YAML::LoadFile(default_editor_script_path_.c_str());
371  } catch (const std::exception& e)
372  {
373  return false;
374  }
375 
376  // parse action_sound table
377  YAML::Node sub_node = doc["action_and_sound"];
378  for (YAML::iterator yaml_it = sub_node.begin(); yaml_it != sub_node.end(); ++yaml_it)
379  {
380  int index = yaml_it->first.as<int>();
381  if (mp3_index == index)
382  {
383  path = yaml_it->second.as<std::string>();
384  return true;
385  }
386  }
387 
388  return false;
389 }
390 
392 {
393  YAML::Node doc;
394 
395  try
396  {
397  // load yaml
398  doc = YAML::LoadFile(mirror_joint_file_path_.c_str());
399  } catch (const std::exception& e)
400  {
401  return false;
402  }
403 
404  // parse action_sound table
405  YAML::Node sub_node = doc["upper_body"];
406  for (YAML::iterator yaml_it = sub_node.begin(); yaml_it != sub_node.end(); ++yaml_it)
407  {
408  int right_id = yaml_it->first.as<int>();
409  int left_id = yaml_it->second.as<int>();
410 
411  upper_body_mirror_joints_rl_[right_id] = left_id;
412  upper_body_mirror_joints_lr_[left_id] = right_id;
413  }
414 
415  YAML::Node sub_node2 = doc["lower_body"];
416  for (YAML::iterator yaml_it = sub_node2.begin(); yaml_it != sub_node2.end(); ++yaml_it)
417  {
418  int right_id = yaml_it->first.as<int>();
419  int left_id = yaml_it->second.as<int>();
420 
421  lower_body_mirror_joints_rl_[right_id] = left_id;
422  lower_body_mirror_joints_lr_[left_id] = right_id;
423  }
424 
425  return true;
426 }
427 
428 // Disp & Drawing
430 {
431  int nrows, ncolumns;
432  setupterm(NULL, fileno(stdout), (int *) 0);
433  nrows = tigetnum("lines");
434  ncolumns = tigetnum("cols");
435 
436  system("clear");
437  printf("\n");
438  printf("[Action Editor for %s]\n", ROBOT_NAME);
439  printf("\n");
440  printf(" *Terminal screen size must be %d(col)x%d(row).\n", screen_col_, screen_row_);
441  printf(" *Current terminal has %d columns and %d rows.\n", ncolumns, nrows);
442  printf("\n");
443  printf("\n");
444  printf("Press any key to start program...\n");
445  _getch();
446 
447  ActionModule::getInstance()->loadPage(page_idx_, &page_);
448 
449  readStep();
450 
451  step_.pause = 0;
452  step_.time = 0;
453 
454  drawPage();
455 }
456 
458 {
459  system("clear");
460  printf("\n");
461  printf("Terminate Action Editor");
462  printf("\n");
463 }
464 
466 {
467  int old_col = curr_col_;
468  int old_row = curr_row_;
469 
470  system("clear");
471  // 80 0 1 2 3 4 5 6 7
472  // 80 01234567890123456789012345678901234567890123456789012345678901234567890123456789 //24
473  printf(" \n");
474  printf(" Page Number: \n"); //1
475  printf(" Address: \n"); //2
476  printf(" Play Count: \n"); //3
477  printf(" Page Step: \n"); //4
478  printf(" Page Speed: \n"); //5
479  printf(" Accel Time: \n"); //6
480  printf(" Link to Next: \n"); //7
481  printf(" Link to Exit: \n"); //8
482  printf(" \n"); //9
483 
484  // Draw joint list
485  goToCursor(0, 0);
486  for(std::map<int, std::string>::iterator it = joint_id_to_name_.begin();
487  it != joint_id_to_name_.end();
488  it++)
489  {
490  int id = it->first;
491  std::string joint_name = it->second;
492 
493  if((id == 0) || (id > action_file_define::MAXNUM_JOINTS))
494  continue;
495 
496  printf("ID:%3d", id);
497 
498  printf("(");
499  for(int joint_name_idx = 0; joint_name_idx < max_joint_name_length_; joint_name_idx++)
500  {
501  if(joint_name_idx >= joint_name.size())
502  printf(" ");
503  else
504  printf("%c", joint_name.at(joint_name_idx));
505  }
506  printf(")");
507 
508  //printf("[ ] ");
509  printf("[ ]");
511  printf("%.1d%.1d", page_.header.pgain[id] >> 4, page_.header.pgain[id] & 0x0f);
512 
513  goToCursor(0, curr_row_+1);
514  }
515 
516  // Draw pause row
518  printf(" PauseTime [ ] \n");
519 
521  printf(" Speed [ ] \n");
523  printf(" Time(x 8msec) [ ] \n");
524 
525  printf(" STP7 STP0 STP1 STP2 STP3 STP4 STP5 STP6 \n");
526  printf("] ");
527 
528  // Draw Step
529  for (int i = 0; i <= action_file_define::MAXNUM_STEP; i++)
530  drawStep(i);
531 
532  // Draw Page parameter
534  printf("%.3d", page_.header.repeat);
535 
537  printf("%.3d", page_.header.stepnum);
538 
540  printf("%.3d", page_.header.speed);
541 
543  printf("%.3d", page_.header.accel);
544 
546  printf("%.3d", page_.header.next);
547 
549  printf("%.3d", page_.header.exit);
550 
551  // Draw Page information
552  drawName();
553 
555  printf("%.4d", page_idx_);
556 
558  printf("0x%.5X", (int)(page_idx_ * sizeof(action_file_define::Page)));
559 
560  drawStepLine(false);
561 
562  goToCursor(old_col, old_row);
563 }
564 
565 void ActionEditor::drawStep(int index)
566 {
567  int old_col = curr_col_;
568  int old_row = curr_row_;
570  int col;
571 
572  switch (index)
573  {
574  case 0:
575  col = stp0_col_;
576  step = &page_.step[0];
577  break;
578  case 1:
579  col = stp1_col_;
580  step = &page_.step[1];
581  break;
582  case 2:
583  col = stp2_col_;
584  step = &page_.step[2];
585  break;
586  case 3:
587  col = stp3_col_;
588  step = &page_.step[3];
589  break;
590  case 4:
591  col = stp4_col_;
592  step = &page_.step[4];
593  break;
594  case 5:
595  col = stp5_col_;
596  step = &page_.step[5];
597  break;
598  case 6:
599  col = stp6_col_;
600  step = &page_.step[6];
601  break;
602  case 7:
603  col = stp7_col_;
604  step = &step_;
605  break;
606  default:
607  return;
608  }
609 
610 
611  for(std::map<int, int>::iterator it = joint_id_to_row_index_.begin();
612  it != joint_id_to_row_index_.end();
613  it++)
614  {
615  int id = it->first;
616  int row_idx = it->second;
618  {
619  goToCursor(col, row_idx);
621  {
622  printf("----");
623  }
625  printf("????");
626  else
627  printf("%.4d", step->position[id]);
628  }
629  else
630  continue;
631  }
632 
633  goToCursor(col, pause_row_);
634  printf("%4.3d", step->pause);
635 
636  goToCursor(col, time_row_);
637  printf("%4.3d", step->time);
638 
639  goToCursor(old_col, old_row);
640 }
641 
643 {
644  int old_col = curr_col_;
645  int old_row = curr_row_;
646 
648  printf(" ");
650 
651  for (int i = 0; i < action_file_define::MAXNUM_NAME; i++)
652  printf("%c", (char) page_.header.name[i]);
653 
654  goToCursor(old_col, old_row);
655 }
656 
658 {
659  int old_col = curr_col_;
660  int old_row = curr_row_;
661  int col;
662 
663  switch (page_.header.stepnum)
664  {
665  case 0:
666  col = stp0_col_;
667  break;
668 
669  case 1:
670  col = stp1_col_;
671  break;
672 
673  case 2:
674  col = stp2_col_;
675  break;
676 
677  case 3:
678  col = stp3_col_;
679  break;
680 
681  case 4:
682  col = stp4_col_;
683  break;
684 
685  case 5:
686  col = stp5_col_;
687  break;
688 
689  case 6:
690  col = stp6_col_;
691  break;
692 
693  case 7:
694  col = cwslope_col_;
695  break;
696 
697  default:
698  return;
699  }
700  col--;
701 
702  for (int index = 0; index < joint_id_to_row_index_.size(); index++)
703  {
704  goToCursor(col, index);
705  if (erase == true)
706  printf(" ");
707  else
708  printf("|");
709  }
710 
711  goToCursor(old_col, old_row);
712 }
713 
715 {
716  uint8_t error = 0;
717  uint32_t value = 0;
718  int id;
719  bool* enable = new bool[joint_id_to_row_index_.size()];
720 
721  for (int index = 0; index < joint_id_to_row_index_.size(); index++)
722  {
723  enable[index] = false;
724  }
725 
726  for (std::map<int, int>::iterator it = joint_id_to_row_index_.begin();
727  it != joint_id_to_row_index_.end();
728  it++)
729  {
730  id = it->first;
731  std::string joint_name = joint_id_to_name_[id];
732  std::map<std::string, robotis_framework::Dynamixel *>::iterator dxls_it;
733 
734  dxls_it = robot_->dxls_.find(joint_name);
735  if (dxls_it != robot_->dxls_.end())
736  {
737  if (ctrl_->readCtrlItem(joint_name, "torque_enable", &value, &error) == COMM_SUCCESS)
738  {
739  if (value == 1)
740  {
741  if (ctrl_->readCtrlItem(joint_name, "present_position", &value, &error) == COMM_SUCCESS)
742  {
743  int offset = robot_->dxls_[joint_name]->convertRadian2Value(
744  robot_->dxls_[joint_name]->dxl_state_->position_offset_)
745  - robot_->dxls_[joint_name]->value_of_0_radian_position_;
746  value = value - offset;
747  step_.position[id] = convertPositionValueTo4095(id, value);
748  enable[id] = true;
749  }
750  else
751  {
753  }
754  }
755  else
756  {
758  }
759  }
760  else
761  {
763  }
764 
765  }
766  else
767  {
769  }
770  }
771 }
772 
774 {
775  printCmd(" ");
776 }
777 
778 
779 void ActionEditor::printCmd(const char *message)
780 {
781  int len = strlen(message);
782  goToCursor(0, cmd_row_);
783 
784  printf("] %s", message);
785  for (int i = 0; i < (screen_col_ - (len + 2)); i++)
786  printf(" ");
787 
788  goToCursor(len + 2, cmd_row_);
789 }
790 
792 {
793  if (edited_ == true)
794  {
795  printCmd("Are you sure? (y/n)");
796  if (_getch() != 'y')
797  {
798  clearCmd();
799  return true;
800  }
801  }
802 
803  return false;
804 }
805 
806 // Edit value
807 
809 {
810  setValue(getValue() + offset);
811 }
812 
813 
814 void ActionEditor::setValue(int value)
815 {
816  int col;
817  int row;
818  if (begin_command_mode_ == true)
819  {
820  col = old_col_;
821  row = old_row_;
822  }
823  else
824  {
825  col = curr_col_;
826  row = curr_row_;
827  }
828 
829  goToCursor(col, row);
830 
831  if (col == stp7_col_)
832  {
833  if (row == pause_row_)
834  {
835  if (value >= 0 && value <= 255)
836  {
837  step_.pause = value;
838  printf("%4.3d", value);
839  edited_ = true;
840  }
841  }
842  else if (row == time_row_)
843  {
844  if (value >= 0 && value <= 255)
845  {
846  step_.time = value;
847  printf("%4.3d", value);
848  edited_ = true;
849  }
850  }
851  else
852  {
853  if (value >= 0 && value <= 4095)
854  {
855  int id = joint_row_index_to_id_[row];
858  {
859  uint8_t error;
860  uint32_t ivalue;
861  ivalue = (uint32_t) convert4095ToPositionValue(id, value);
862  if (ctrl_->writeCtrlItem(joint_id_to_name_[id], "goal_position", ivalue, &error) == COMM_SUCCESS)
863  {
864  step_.position[id] = value;
865  printf("%.4d", value);
866  edited_ = true;
867  }
868  }
869  }
870  }
871  }
872  else if (col <= stp6_col_)
873  {
874  int i = 0;
875  if(col == stp0_col_)
876  i = 0;
877  else if(col == stp1_col_)
878  i = 1;
879  else if(col == stp2_col_)
880  i = 2;
881  else if(col == stp3_col_)
882  i = 3;
883  else if(col == stp4_col_)
884  i = 4;
885  else if(col == stp5_col_)
886  i = 5;
887  else if(col == stp6_col_)
888  i = 6;
889 
890  int id = joint_row_index_to_id_[row];
891 
892  if (row == pause_row_)
893  {
894  if (value >= 0 && value <= 255)
895  {
896  page_.step[i].pause = value;
897  printf("%4.3d", value);
898  edited_ = true;
899  }
900  }
901  else if (row == time_row_)
902  {
903  if (value >= 0 && value <= 255)
904  {
905  page_.step[i].time = value;
906  printf("%4.3d", value);
907  edited_ = true;
908  }
909  }
910  else
911  {
912  if (value >= 0 && value <= 4095)
913  {
914  page_.step[i].position[id] = value;
915  printf("%.4d", value);
916  edited_ = true;
917  }
918  }
919  }
920  else if (col == cwslope_col_)
921  {
922  int id = joint_row_index_to_id_[row];
923  if (value >= 1 && value <= 7)
924  {
925  page_.header.pgain[id] = (value << 4) + (page_.header.pgain[id] & 0x0f);
926  printf("%.1d", value);
927  edited_ = true;
928  }
929  }
930  else if (col == ccwslope_col_)
931  {
932  int id = joint_row_index_to_id_[row];
933  if (value >= 1 && value <= 7)
934  {
935  page_.header.pgain[id] = (page_.header.pgain[id] & 0xf0) + (value & 0x0f);
936  printf("%.1d", value);
937  edited_ = true;
938  }
939  }
940  else if (col == pageparam_col_)
941  {
942  if (row == play_count_row_)
943  {
944  if (value >= 0 && value <= 255)
945  {
946  page_.header.repeat = value;
947  printf("%.3d", value);
948  edited_ = true;
949  }
950  }
951  else if (row == step_num_row_)
952  {
953  if (value >= 0 && value <= action_file_define::MAXNUM_STEP)
954  {
955  if (page_.header.stepnum != value)
956  {
957  drawStepLine(true);
958  page_.header.stepnum = value;
959  drawStepLine(false);
960  printf("%.3d", value);
961  edited_ = true;
962  }
963  }
964  }
965  else if (row == play_time_row_)
966  {
967  if (value >= 0 && value <= 255)
968  {
969  page_.header.speed = value;
970  printf("%.3d", value);
971  edited_ = true;
972  }
973  }
974  else if (row == accel_row_)
975  {
976  if (value >= 0 && value <= 255)
977  {
978  page_.header.accel = value;
979  printf("%.3d", value);
980  edited_ = true;
981  }
982  }
983  else if (row == next_row_)
984  {
985  if (value >= 0 && value <= 255)
986  {
987  page_.header.next = value;
988  printf("%.3d", value);
989  edited_ = true;
990  }
991  }
992  else if (row == exit_row_)
993  {
994  if (value >= 0 && value <= 255)
995  {
996  page_.header.exit = value;
997  printf("%.3d", value);
998  edited_ = true;
999  }
1000  }
1001  }
1002 
1003  goToCursor(col, row);
1004 }
1005 
1007 {
1008  int col;
1009  int row;
1010  if (begin_command_mode_ == true)
1011  {
1012  col = old_col_;
1013  row = old_row_;
1014  }
1015  else
1016  {
1017  col = curr_col_;
1018  row = curr_row_;
1019  }
1020 
1021  if (col == stp7_col_)
1022  {
1023  if (row == pause_row_)
1024  return step_.pause;
1025  else if (row == time_row_)
1026  return step_.time;
1027  else
1028  return step_.position[row + 1];
1029  }
1030  else if (col <= stp6_col_)
1031  {
1032  int i = 0;
1033  if(col == stp0_col_)
1034  i = 0;
1035  else if(col == stp1_col_)
1036  i = 1;
1037  else if(col == stp2_col_)
1038  i = 2;
1039  else if(col == stp3_col_)
1040  i = 3;
1041  else if(col == stp4_col_)
1042  i = 4;
1043  else if(col == stp5_col_)
1044  i = 5;
1045  else if(col == stp6_col_)
1046  i = 6;
1047 
1048  int id = joint_row_index_to_id_[row];
1049 
1050  if (row == pause_row_)
1051  return page_.step[i].pause;
1052  else if (row == time_row_)
1053  return page_.step[i].time;
1054  else
1055  return page_.step[i].position[id];
1056  }
1057  else if (col == cwslope_col_)
1058  return (page_.header.pgain[joint_row_index_to_id_[row]] >> 4);
1059  else if (col == ccwslope_col_)
1060  return (page_.header.pgain[joint_row_index_to_id_[row]] & 0x0f);
1061  else if (col == pageparam_col_)
1062  {
1063  if (row == play_count_row_)
1064  return page_.header.repeat;
1065  else if (row == step_num_row_)
1066  return page_.header.stepnum;
1067  else if (row == play_time_row_)
1068  return page_.header.speed;
1069  else if (row == accel_row_)
1070  return page_.header.accel;
1071  else if (row == next_row_)
1072  return page_.header.next;
1073  else if (row == exit_row_)
1074  return page_.header.exit;
1075  }
1076 
1077  return -1;
1078 }
1079 
1081 {
1083  return;
1084 
1086 
1087  std::string joint_name = joint_id_to_name_[id];
1088 
1090  {
1091  if (ctrl_->writeCtrlItem(joint_name, "torque_enable", 1, 0) != COMM_SUCCESS)
1092  return;
1093 
1094  uint32_t value;
1095  if (ctrl_->readCtrlItem(joint_name, "present_position", &value, 0) != COMM_SUCCESS)
1096  return;
1097 
1098  int offset = robot_->dxls_[joint_name]->convertRadian2Value(
1099  robot_->dxls_[joint_name]->dxl_state_->position_offset_)
1100  - robot_->dxls_[joint_name]->value_of_0_radian_position_;
1101  value = value - offset;
1102 
1103  step_.position[id] = convertPositionValueTo4095(id, value);
1104  printf("%.4d", value);
1105  }
1106  else
1107  {
1108  if (ctrl_->writeCtrlItem(joint_name, "torque_enable", 0, 0) != COMM_SUCCESS)
1109  return;
1110 
1112  printf("????");
1113  }
1114 
1116 }
1117 
1119 {
1120  cache_value_ = getValue();
1121 }
1122 
1124 {
1125  // cache is empty.
1126  if (cache_value_ == -1)
1127  {
1128  int cursor_col = curr_col_;
1129  int cursor_row = curr_row_;
1130 
1131  printCmd("Cache is empty.");
1132  goToCursor(cursor_col, cursor_row);
1133 
1134  return;
1135  }
1136 
1137  // set value
1139 }
1140 
1142 {
1143  cache_value_ = -1;
1144 }
1145 
1146 // Command process
1148 {
1149  old_col_ = curr_col_;
1150  old_row_ = curr_row_;
1151  clearCmd();
1153  begin_command_mode_ = true;
1154 }
1155 
1157 {
1159  begin_command_mode_ = false;
1160 }
1161 
1163 {
1164  system("clear");
1165  printf(" exit Exits the program.\n");
1166  printf(" re Refreshes the screen.\n");
1167  printf(" b Move to previous page.\n");
1168  printf(" n Move to next page.\n");
1169  printf(" page [index] Move to page [index].\n");
1170  printf(" list View list of pages.\n");
1171  printf(" new Clears data of current page and initializes page.\n");
1172  printf(" copy [index] Copy data from page [index].\n");
1173  printf(" set [value] Sets value on cursor [value].\n");
1174  printf(" save Saves changes.\n");
1175  printf(" play Motion playback of current page.\n");
1176  printf(" playboth [index] Motion playback of current page with [index] mp3.\n");
1177  printf(" g [index] Motion playback of STP[index].\n");
1178  printf(" name Name for current page or changes the name of current page.\n");
1179  printf(" time Change time base playing.\n");
1180  printf(" speed Change speed base playing.\n");
1181  printf(" w [index] Overwrites data from STP[index] with STP7.\n");
1182  printf(" i Inserts data from STP7 to STP0. \n"
1183  " Moves data from STP[x] to STP[x+1].\n");
1184  printf(" i [index] Inserts data from STP7 to STP[index]. \n"
1185  " Moves data from STP[index] to STP[index+1].\n");
1186  printf(" m [index] [index2] Moves data from [index] to [index2] step.\n");
1187  printf(" d [index] Deletes data from STP[index]. \n"
1188  " Pushes data from STP[index] to STP[index-1].\n");
1189  printf(" mlr [index] Mirror the left side value to the right of STP[index]. \n");
1190  printf(" mrl [index] Mirror the right side value to the left of STP[index]. \n");
1191  printf(" ms [index] Switch the values between left and right of STP[index]. \n");
1192  printf(" on/off Turn On/Off torque from ALL actuators.\n");
1193  printf(" on/off [index1] [index2] ... \n"
1194  " turns On/Off torque from ID[index1] ID[index2]...\n");
1195  printf("\n");
1196  printf(" Copyright ROBOTIS CO.,LTD.\n");
1197  printf("\n");
1198  printf(" Press any key to continue...");
1199  _getch();
1200 
1201  drawPage();
1202 }
1203 
1205 {
1206  pageCmd(page_idx_ + 1);
1207 }
1208 
1210 {
1211  pageCmd(page_idx_ - 1);
1212 }
1213 
1214 void ActionEditor::pageCmd(int index)
1215 {
1216  if (askSave() == true)
1217  return;
1218 
1219  if (index > 0 && index < action_file_define::MAXNUM_PAGE)
1220  {
1221  page_idx_ = index;
1222  ActionModule::getInstance()->loadPage(page_idx_, &page_);
1223 
1224  curr_col_ = stp7_col_;
1226  drawPage();
1227  }
1228  else
1229  printCmd("Invalid page index");
1230 
1231  edited_ = false;
1232 }
1233 
1235 {
1237  edited_ = true;
1238  drawPage();
1239 }
1240 
1242 {
1244  edited_ = true;
1245  drawPage();
1246 }
1247 
1249 {
1250  playCmd(-1);
1251 }
1252 
1253 void ActionEditor::playCmd(int mp3_index)
1254 {
1255  uint32_t value;
1256 
1257  for (int i = 0; i < page_.header.stepnum; i++)
1258  {
1259  for (std::map<int, int>::iterator it = joint_id_to_row_index_.begin(); it != joint_id_to_row_index_.end(); it++)
1260  {
1261  int id = it->first;
1263  {
1264  printCmd("Exist invalid joint value");
1265  return;
1266  }
1267  }
1268  }
1269 
1270  printCmd("Playing... ('s' to stop, 'b' to brake)");
1271 
1272  ctrl_->startTimer();
1273  ros::Duration(0.03).sleep(); // waiting for timer start
1274 
1275  std_msgs::String msg;
1276  msg.data = "action_module";
1278  ros::Duration(0.03).sleep(); // waiting for enable
1279 
1280  if (ActionModule::getInstance()->start(page_idx_, &page_) == false)
1281  {
1282  printCmd("Failed to play this page!");
1283  ctrl_->stopTimer();
1284  return;
1285  }
1286 
1287  // play mp3
1288  if (mp3_index != -1)
1289  {
1290  std::string mp3_path = "";
1291  bool get_path_result = loadMp3Path(mp3_index, mp3_path);
1292 
1293  if (get_path_result == true)
1294  {
1295  std_msgs::String sound_msg;
1296  sound_msg.data = mp3_path;
1297 
1298  play_sound_pub_.publish(sound_msg);
1299  }
1300  }
1301 
1302  setSTDin();
1303  while (1)
1304  {
1305  if (ActionModule::getInstance()->isRunning() == false)
1306  break;
1307 
1308  if (kbhit())
1309  {
1310  int key = _getch();
1312  if (key == 's')
1313  {
1314  ActionModule::getInstance()->stop();
1315  fprintf(stderr, "\r] Stopping... ");
1316  }
1317  else if (key == 'b')
1318  {
1319  ActionModule::getInstance()->brake();
1320  fprintf(stderr, "\r] Braking... ");
1321  }
1322  else
1323  fprintf(stderr, "\r] Playing... ('s' to stop, 'b' to brake)");
1324  }
1325 
1326  usleep(10000);
1327  }
1328  resetSTDin();
1329 
1330  ctrl_->stopTimer();
1331 
1333  printCmd("Done.");
1334 
1335  usleep(10000);
1336 
1337  readStep();
1338  drawStep(7);
1339 }
1340 
1342 {
1343  int old_col = curr_col_;
1344  int old_row = curr_row_;
1345  int index = 0;
1346 
1347  while (1)
1348  {
1349  system("clear");
1350  for (int i = 0; i < 22; i++)
1351  {
1352  for (int j = 0; j < 4; j++)
1353  {
1354  int k = (index * 88) + (j * 22 + i); //first page number is 1
1356  if (ActionModule::getInstance()->loadPage(k, &page) == true)
1357  {
1358  printf(" |%.3d.", k);
1359  for (int n = 0; n < action_file_define::MAXNUM_NAME; n++)
1360  {
1361  if ((char) page.header.name[n] >= ' ' && (char) page.header.name[n] <= '~')
1362  printf("%c", (char) page.header.name[n]);
1363  else
1364  printf(" ");
1365  }
1366  }
1367  else
1368  {
1369  printf(" | ");
1370  }
1371  }
1372  printf("\n");
1373  }
1374 
1375  printf("\nAction Page List (%d/3) - Press key n(Next), b(Prev), q(Quit)", index + 1);
1376  while (1)
1377  {
1378  int ch = _getch();
1379  if (ch == 'n')
1380  {
1381  if (index < 2)
1382  {
1383  index++;
1384  break;
1385  }
1386  }
1387  else if (ch == 'b')
1388  {
1389  if (index > 0)
1390  {
1391  index--;
1392  break;
1393  }
1394  }
1395  else if (ch == 'q')
1396  {
1397  drawPage();
1398  goToCursor(old_col, old_row);
1399  return;
1400  }
1401  }
1402  }
1403 }
1404 
1405 void ActionEditor::turnOnOffCmd(bool on, int num_param, int *list)
1406 {
1407  uint32_t torque_enable = 0;
1408  if (on)
1409  torque_enable = 1;
1410 
1411  if (num_param == 0)
1412  {
1413  for (std::map<int, int>::iterator it = joint_id_to_row_index_.begin();
1414  it != joint_id_to_row_index_.end();
1415  it++)
1416  {
1417  int id = it->first;
1418  std::string joint_name = joint_id_to_name_[id];
1419  ctrl_->writeCtrlItem(joint_name, "torque_enable", torque_enable, 0);
1420  }
1421  }
1422  else
1423  {
1424  for (int i = 0; i < num_param; i++)
1425  {
1426  int id = list[i];
1427  std::map<int, int>::iterator it = joint_id_to_row_index_.find(id);
1428  if(it != joint_id_to_row_index_.end())
1429  {
1430  std::string joint_name = joint_id_to_name_[id];
1431  ctrl_->writeCtrlItem(joint_name, "torque_enable", torque_enable, 0);
1432  }
1433  }
1434  }
1435 
1436  readStep();
1437  drawStep(7);
1438 }
1439 
1440 void ActionEditor::mirrorStepCmd(int index, int mirror_type, int target_type)
1441 {
1442  // check index
1443  if (index < 0 || index >= action_file_define::MAXNUM_STEP)
1444  {
1445  printCmd("Invalid step index");
1446  return;
1447  }
1448 
1449  // store previous step
1450  action_file_define::Step before_step = page_.step[index];
1451 
1452  //check target_type
1453  if (target_type == UpperBody || target_type == AllBody)
1454  {
1455  if (mirror_type == RightToLeft || mirror_type == SwitchEach)
1456  {
1457  for (std::map<int, int>::iterator it = upper_body_mirror_joints_rl_.begin();
1458  it != upper_body_mirror_joints_rl_.end(); it++)
1459  {
1460  int right_id = it->first;
1461  int left_id = it->second;
1462  int mirror_value = convert4095ToMirror(right_id, before_step.position[right_id]);
1463 
1464  page_.step[index].position[left_id] = mirror_value;
1465  }
1466  }
1467 
1468  if (mirror_type == LeftToRight || mirror_type == SwitchEach)
1469  {
1470  for (std::map<int, int>::iterator it = upper_body_mirror_joints_lr_.begin();
1471  it != upper_body_mirror_joints_lr_.end(); it++)
1472  {
1473  int left_id = it->first;
1474  int right_id = it->second;
1475  int mirror_value = convert4095ToMirror(left_id, before_step.position[left_id]);
1476 
1477  page_.step[index].position[right_id] = mirror_value;
1478  }
1479  }
1480  }
1481 
1482  if (target_type == LowerBody || target_type == AllBody)
1483  {
1484  if (mirror_type == RightToLeft || mirror_type == SwitchEach)
1485  {
1486  for (std::map<int, int>::iterator it = lower_body_mirror_joints_rl_.begin();
1487  it != lower_body_mirror_joints_rl_.end(); it++)
1488  {
1489  int right_id = it->first;
1490  int left_id = it->second;
1491  int mirror_value = convert4095ToMirror(right_id, before_step.position[right_id]);
1492 
1493  page_.step[index].position[left_id] = mirror_value;
1494  }
1495  }
1496 
1497  if (mirror_type == LeftToRight || mirror_type == SwitchEach)
1498  {
1499  for (std::map<int, int>::iterator it = lower_body_mirror_joints_lr_.begin();
1500  it != lower_body_mirror_joints_lr_.end(); it++)
1501  {
1502  int left_id = it->first;
1503  int right_id = it->second;
1504  int mirror_value = convert4095ToMirror(left_id, before_step.position[left_id]);
1505 
1506  page_.step[index].position[right_id] = mirror_value;
1507  }
1508  }
1509  }
1510 
1511  // draw step
1512  drawStep(index);
1513  edited_ = true;
1514 }
1515 
1517 {
1518  for (std::map<int, int>::iterator it = joint_id_to_row_index_.begin();
1519  it != joint_id_to_row_index_.end();
1520  it++)
1521  {
1522  int id = it->first;
1523 
1525  return;
1526  }
1527 
1528  if (index >= 0 && index < action_file_define::MAXNUM_STEP)
1529  {
1530  page_.step[index] = step_;
1531  drawStep(index);
1532  edited_ = true;
1533  }
1534  else
1535  printCmd("Invalid step index");
1536 }
1537 
1539 {
1540  if (index >= 0 && index < action_file_define::MAXNUM_STEP)
1541  {
1542  for (int i = index; i < action_file_define::MAXNUM_STEP; i++)
1543  {
1544  if (i == (action_file_define::MAXNUM_STEP - 1))
1545  {
1546  for (int jointIndex = 0; jointIndex < action_file_define::MAXNUM_JOINTS; jointIndex++)
1548 
1549  page_.step[i].pause = 0;
1550  page_.step[i].time = 0;
1551  }
1552  else
1553  page_.step[i] = page_.step[i + 1];
1554 
1555  drawStep(i);
1556  }
1557 
1558  if (index < page_.header.stepnum)
1559  {
1560  if (page_.header.stepnum != 0)
1561  {
1562  drawStepLine(true);
1563  page_.header.stepnum--;
1564  drawStepLine(false);
1565  }
1566 
1568  printf("%.3d", page_.header.stepnum);
1569  }
1570 
1571  edited_ = true;
1572  }
1573  else
1574  printCmd("Invalid step index");
1575 }
1576 
1578 {
1579  for (std::map<int, int>::iterator it = joint_id_to_row_index_.begin();
1580  it != joint_id_to_row_index_.end();
1581  it++)
1582  {
1583  int id = it->first;
1585  {
1586  printCmd("Exist invalid joint value");
1587  return;
1588  }
1589  }
1590 
1591  if (index >= 0 && index < action_file_define::MAXNUM_STEP)
1592  {
1593  for (int i = action_file_define::MAXNUM_STEP - 1; i > index; i--)
1594  {
1595  page_.step[i] = page_.step[i - 1];
1596  drawStep(i);
1597  }
1598 
1599  page_.step[index] = step_;
1600  drawStep(index);
1601 
1602  if (index == 0 || index < page_.header.stepnum)
1603  {
1605  {
1606  drawStepLine(true);
1607  page_.header.stepnum++;
1608  drawStepLine(false);
1609  }
1610 
1612  printf("%.3d", page_.header.stepnum);
1613  }
1614 
1615  edited_ = true;
1616  }
1617  else
1618  printCmd("Invalid step index");
1619 }
1620 
1621 void ActionEditor::moveStepCmd(int src, int dst)
1622 {
1623  if (src < 0 || src >= action_file_define::MAXNUM_STEP)
1624  {
1625  printCmd("Invalid step index");
1626  return;
1627  }
1628 
1629  if (dst < 0 || dst >= action_file_define::MAXNUM_STEP)
1630  {
1631  printCmd("Invalid step index");
1632  return;
1633  }
1634 
1635  if (src == dst)
1636  return;
1637 
1639  if (src < dst)
1640  {
1641  for (int i = src; i < dst; i++)
1642  {
1643  page_.step[i] = page_.step[i + 1];
1644  drawStep(i);
1645  }
1646  }
1647  else
1648  {
1649  for (int i = src; i > dst; i--)
1650  {
1651  page_.step[i] = page_.step[i - 1];
1652  drawStep(i);
1653  }
1654  }
1655 
1656  page_.step[dst] = step;
1657  drawStep(dst);
1658  edited_ = true;
1659 }
1660 
1661 void ActionEditor::copyCmd(int index)
1662 {
1663  if (index == page_idx_)
1664  return;
1665 
1666  if (ActionModule::getInstance()->loadPage(index, &page_) == true)
1667  {
1668  drawPage();
1669  edited_ = true;
1670  }
1671  else
1672  printCmd("Invalid page index");
1673 }
1674 
1676 {
1677  ActionModule::getInstance()->resetPage(&page_);
1678  drawPage();
1679  edited_ = true;
1680 }
1681 
1682 void ActionEditor::goCmd(int index)
1683 {
1684  if (index < 0 || index >= action_file_define::MAXNUM_STEP)
1685  {
1686  printCmd("Invalid step index");
1687  return;
1688  }
1689 
1690  if (index > page_.header.stepnum)
1691  {
1692  printCmd("Are you sure? (y/n)");
1693  if (_getch() != 'y')
1694  {
1695  clearCmd();
1696  return;
1697  }
1698  }
1699 
1700  int id;
1701  int32_t goal_position, start_position, distance;
1702  int max_distance = 0;
1703 
1704  for (std::map<std::string, dynamixel::GroupSyncWrite *>::iterator it = port_to_sync_write_go_cmd_.begin();
1705  it != port_to_sync_write_go_cmd_.end(); it++)
1706  {
1707  it->second->clearParam();
1708  }
1709 
1710  for (std::map<int, int>::iterator it = joint_id_to_row_index_.begin();
1711  it != joint_id_to_row_index_.end();
1712  it++)
1713  {
1714  id = it->first;
1715  std::string joint_name = joint_id_to_name_[id];
1717  {
1718  printCmd("Exist invalid joint value");
1719  return;
1720  }
1721 
1722  if (ctrl_->readCtrlItem(joint_name, "present_position", (uint32_t*)&start_position, 0) != COMM_SUCCESS)
1723  {
1724  printCmd("Failed to read position");
1725  return;
1726  }
1727 
1728  goal_position = convert4095ToPositionValue(id, page_.step[index].position[id]);
1729  if (start_position > goal_position)
1730  distance = start_position - goal_position;
1731  else
1732  distance = goal_position - start_position;
1733 
1734 // wDistance = 200;
1735  distance = distance * 0.03;
1736 
1737  if (max_distance < distance)
1738  max_distance = distance;
1739 
1740  int offset = robot_->dxls_[joint_name]->convertRadian2Value(robot_->dxls_[joint_name]->dxl_state_->position_offset_)
1741  - robot_->dxls_[joint_name]->value_of_0_radian_position_;
1742  goal_position = goal_position + offset;
1743 
1744  uint8_t param[8];
1745 
1746  param[0] = DXL_LOBYTE(DXL_LOWORD(goal_position));
1747  param[1] = DXL_HIBYTE(DXL_LOWORD(goal_position));
1748  param[2] = DXL_LOBYTE(DXL_HIWORD(goal_position));
1749  param[3] = DXL_HIBYTE(DXL_HIWORD(goal_position));
1750  param[4] = DXL_LOBYTE(DXL_LOWORD(distance));
1751  param[5] = DXL_HIBYTE(DXL_LOWORD(distance));
1752  param[6] = DXL_LOBYTE(DXL_HIWORD(distance));
1753  param[7] = DXL_HIBYTE(DXL_HIWORD(distance));
1754 
1755  for (std::map<std::string, dynamixel::GroupSyncWrite *>::iterator it = port_to_sync_write_go_cmd_.begin();
1756  it != port_to_sync_write_go_cmd_.end(); it++)
1757  {
1758  it->second->addParam(id, param);
1759  }
1760  }
1761 
1762  for (std::map<std::string, dynamixel::GroupSyncWrite *>::iterator it = port_to_sync_write_go_cmd_.begin();
1763  it != port_to_sync_write_go_cmd_.end(); it++)
1764  {
1765  it->second->txPacket();
1766  }
1767 
1768  sleep(max_distance / 1000 + 2);
1769 
1770  for (std::map<std::string, dynamixel::GroupSyncWrite *>::iterator it = port_to_sync_write_go_cmd_.begin();
1771  it != port_to_sync_write_go_cmd_.end(); it++)
1772  {
1773  it->second->clearParam();
1774  }
1775 
1776  for (std::map<int, int>::iterator it = joint_id_to_row_index_.begin();
1777  it != joint_id_to_row_index_.end();
1778  it++)
1779  {
1780  id = it->first;
1781  std::string joint_name = joint_id_to_name_[id];
1782 
1783  distance = 0;
1784 
1785  goal_position = convert4095ToPositionValue(id, page_.step[index].position[id]);
1786 
1787  int offset = robot_->dxls_[joint_name]->convertRadian2Value(robot_->dxls_[joint_name]->dxl_state_->position_offset_)
1788  - robot_->dxls_[joint_name]->value_of_0_radian_position_;
1789  goal_position = goal_position + offset;
1790 
1791  uint8_t param[8];
1792 
1793  param[0] = DXL_LOBYTE(DXL_LOWORD(goal_position));
1794  param[1] = DXL_HIBYTE(DXL_LOWORD(goal_position));
1795  param[2] = DXL_LOBYTE(DXL_HIWORD(goal_position));
1796  param[3] = DXL_HIBYTE(DXL_HIWORD(goal_position));
1797  param[4] = DXL_LOBYTE(DXL_LOWORD(distance));
1798  param[5] = DXL_HIBYTE(DXL_LOWORD(distance));
1799  param[6] = DXL_LOBYTE(DXL_HIWORD(distance));
1800  param[7] = DXL_HIBYTE(DXL_HIWORD(distance));
1801 
1802  for (std::map<std::string, dynamixel::GroupSyncWrite *>::iterator it = port_to_sync_write_go_cmd_.begin();
1803  it != port_to_sync_write_go_cmd_.end(); it++)
1804  {
1805  it->second->addParam(id, param);
1806  }
1807  }
1808 
1809  for (std::map<std::string, dynamixel::GroupSyncWrite *>::iterator it = port_to_sync_write_go_cmd_.begin();
1810  it != port_to_sync_write_go_cmd_.end(); it++)
1811  {
1812  it->second->txPacket();
1813  }
1814 
1815  step_ = page_.step[index];
1816  drawStep(7);
1818  printf("Go Command Completed");
1819 }
1820 
1822 {
1823  if (edited_ == false)
1824  return;
1825 
1826  if (ActionModule::getInstance()->savePage(page_idx_, &page_) == true)
1827  edited_ = false;
1828 }
1829 
1831 {
1832  clearCmd();
1834  printf("name: ");
1835  char name[80] = { 0 };
1836  fgets(name, 80, stdin);
1837  fflush(stdin);
1838  for (int i = 0; i <= action_file_define::MAXNUM_NAME; i++)
1839  page_.header.name[i] = name[i];
1840  drawName();
1841  edited_ = true;
1842 }
msg
#define NULL
bool loadMp3Path(int mp3_index, std::string &path)
void deleteStepCmd(int index)
bool param(const std::string &param_name, T &param_val, const T &default_val)
int convert4095ToMirror(int id, int w4095)
int convert4095ToPositionValue(int id, int w4095)
void publish(const boost::shared_ptr< M > &message) const
unsigned char name[MAXNUM_NAME+1]
unsigned short position[MAXNUM_JOINTS]
bool initializeActionEditor(std::string robot_file_path, std::string init_file_path, std::string offset_file_path)
ros::Publisher play_sound_pub_
void writeStepCmd(int index)
std::map< std::string, dynamixel::GroupSyncWrite * > port_to_sync_write_go_cmd_
bool sleep() const
void drawStep(int index)
unsigned char pgain[MAXNUM_JOINTS]
void setValueUpDown(int offset)
std::string default_editor_script_path_
std::map< int, int > joint_id_to_row_index_
std::map< int, int > lower_body_mirror_joints_rl_
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
int convertPositionValueTo4095(int id, int PositionValue)
void goToCursor(int col, int row)
void addMotionModule(MotionModule *module)
std::map< int, int > upper_body_mirror_joints_lr_
std::map< std::string, dynamixel::PortHandler * > ports_
void printCmd(const char *message)
std::map< std::string, Dynamixel * > dxls_
void insertStepCmd(int index)
void moveStepCmd(int src, int dst)
int COMM_SUCCESS
action_file_define::Step step_
bool initialize(const std::string robot_file_path, const std::string init_file_path)
void loadOffset(const std::string path)
struct termios oldterm new_term
void mirrorStepCmd(int index, int mirror_type, int target_type)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static PacketHandler * getPacketHandler(float protocol_version=2.0)
void turnOnOffCmd(bool on, int num_param, int *list)
def DXL_HIBYTE(w)
robotis_framework::Robot * robot_
ROSLIB_DECL std::string getPath(const std::string &package_name)
def DXL_LOWORD(l)
unsigned int step
std::string mirror_joint_file_path_
def DXL_HIWORD(l)
void drawStepLine(bool erase)
std::map< int, int > lower_body_mirror_joints_lr_
std::map< std::string, int > joint_name_to_id_
int writeCtrlItem(const std::string joint_name, const std::string item_name, uint32_t data, uint8_t *error=0)
void setValue(int value)
#define ROS_ERROR(...)
std::map< int, std::string > joint_id_to_name_
robotis_framework::RobotisController * ctrl_
def DXL_LOBYTE(w)
#define ROBOT_NAME
Definition: action_editor.h:43
ros::Publisher enable_ctrl_module_pub_
std::map< int, int > joint_row_index_to_id_
int readCtrlItem(const std::string joint_name, const std::string item_name, uint32_t *data, uint8_t *error=0)
std::map< int, int > upper_body_mirror_joints_rl_
action_file_define::Page page_


thormang3_action_editor
Author(s): Kayman , SCH , Jay Song
autogenerated on Mon Jun 10 2019 15:37:46