92 struct termios oldt, newt;
94 tcgetattr( STDIN_FILENO, &oldt);
96 newt.c_lflag &= ~(ICANON | ECHO);
97 tcsetattr( STDIN_FILENO, TCSANOW, &newt);
99 tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
105 struct termios oldt, newt;
109 tcgetattr(STDIN_FILENO, &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);
118 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
119 fcntl(STDIN_FILENO, F_SETFL, oldf);
132 tcgetattr(0, &oldterm);
134 new_term.c_lflag &= ~(ICANON | ECHO | ISIG);
142 tcsetattr(0, TCSANOW, &oldterm);
149 cursor = tigetstr(
"cup");
150 esc_sequence = tparm(cursor, row, col);
266 ROS_ERROR(
"ROBOTIS Controller Initialize Fail!");
271 ActionModule::getInstance()->enableAllJoints();
281 for(std::map<std::string, robotis_framework::Dynamixel*>::iterator it =
robot_->
dxls_.begin(); it !=
robot_->
dxls_.end(); it++)
283 std::string joint_name = it->first;
324 for (std::map<std::string, dynamixel::PortHandler *>::iterator it =
robot_->
ports_.begin();
348 double rad = (w4095 - 2048)*M_PI/2048.0;
355 return (
int)((rad + M_PI)*2048.0/M_PI);
371 }
catch (
const std::exception& e)
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)
380 int index = yaml_it->first.as<
int>();
381 if (mp3_index == index)
383 path = yaml_it->second.as<std::string>();
399 }
catch (
const std::exception& e)
405 YAML::Node sub_node = doc[
"upper_body"];
406 for (YAML::iterator yaml_it = sub_node.begin(); yaml_it != sub_node.end(); ++yaml_it)
408 int right_id = yaml_it->first.as<
int>();
409 int left_id = yaml_it->second.as<
int>();
415 YAML::Node sub_node2 = doc[
"lower_body"];
416 for (YAML::iterator yaml_it = sub_node2.begin(); yaml_it != sub_node2.end(); ++yaml_it)
418 int right_id = yaml_it->first.as<
int>();
419 int left_id = yaml_it->second.as<
int>();
432 setupterm(
NULL, fileno(stdout), (
int *) 0);
433 nrows = tigetnum(
"lines");
434 ncolumns = tigetnum(
"cols");
438 printf(
"[Action Editor for %s]\n",
ROBOT_NAME);
441 printf(
" *Current terminal has %d columns and %d rows.\n", ncolumns, nrows);
444 printf(
"Press any key to start program...\n");
461 printf(
"Terminate Action Editor");
474 printf(
" Page Number: \n");
475 printf(
" Address: \n");
476 printf(
" Play Count: \n");
477 printf(
" Page Step: \n");
478 printf(
" Page Speed: \n");
479 printf(
" Accel Time: \n");
480 printf(
" Link to Next: \n");
481 printf(
" Link to Exit: \n");
491 std::string joint_name = it->second;
496 printf(
"ID:%3d",
id);
501 if(joint_name_idx >= joint_name.size())
504 printf(
"%c", joint_name.at(joint_name_idx));
518 printf(
" PauseTime [ ] \n");
521 printf(
" Speed [ ] \n");
523 printf(
" Time(x 8msec) [ ] \n");
525 printf(
" STP7 STP0 STP1 STP2 STP3 STP4 STP5 STP6 \n");
616 int row_idx = it->second;
634 printf(
"%4.3d", step->
pause);
637 printf(
"%4.3d", step->
time);
723 enable[index] =
false;
732 std::map<std::string, robotis_framework::Dynamixel *>::iterator dxls_it;
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;
781 int len = strlen(message);
784 printf(
"] %s", message);
785 for (
int i = 0; i < (
screen_col_ - (len + 2)); i++)
835 if (value >= 0 && value <= 255)
838 printf(
"%4.3d", value);
844 if (value >= 0 && value <= 255)
847 printf(
"%4.3d", value);
853 if (value >= 0 && value <= 4095)
865 printf(
"%.4d", value);
894 if (value >= 0 && value <= 255)
897 printf(
"%4.3d", value);
903 if (value >= 0 && value <= 255)
906 printf(
"%4.3d", value);
912 if (value >= 0 && value <= 4095)
915 printf(
"%.4d", value);
923 if (value >= 1 && value <= 7)
926 printf(
"%.1d", value);
933 if (value >= 1 && value <= 7)
936 printf(
"%.1d", value);
944 if (value >= 0 && value <= 255)
947 printf(
"%.3d", value);
960 printf(
"%.3d", value);
967 if (value >= 0 && value <= 255)
970 printf(
"%.3d", value);
976 if (value >= 0 && value <= 255)
979 printf(
"%.3d", value);
985 if (value >= 0 && value <= 255)
988 printf(
"%.3d", value);
994 if (value >= 0 && value <= 255)
997 printf(
"%.3d", value);
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;
1104 printf(
"%.4d", value);
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");
1196 printf(
" Copyright ROBOTIS CO.,LTD.\n");
1198 printf(
" Press any key to continue...");
1264 printCmd(
"Exist invalid joint value");
1270 printCmd(
"Playing... ('s' to stop, 'b' to brake)");
1275 std_msgs::String
msg;
1276 msg.data =
"action_module";
1280 if (ActionModule::getInstance()->start(
page_idx_, &
page_) ==
false)
1282 printCmd(
"Failed to play this page!");
1288 if (mp3_index != -1)
1290 std::string mp3_path =
"";
1291 bool get_path_result =
loadMp3Path(mp3_index, mp3_path);
1293 if (get_path_result ==
true)
1295 std_msgs::String sound_msg;
1296 sound_msg.data = mp3_path;
1305 if (ActionModule::getInstance()->isRunning() ==
false)
1314 ActionModule::getInstance()->stop();
1315 fprintf(stderr,
"\r] Stopping... ");
1317 else if (key ==
'b')
1319 ActionModule::getInstance()->brake();
1320 fprintf(stderr,
"\r] Braking... ");
1323 fprintf(stderr,
"\r] Playing... ('s' to stop, 'b' to brake)");
1350 for (
int i = 0; i < 22; i++)
1352 for (
int j = 0; j < 4; j++)
1354 int k = (index * 88) + (j * 22 + i);
1356 if (ActionModule::getInstance()->loadPage(k, &page) ==
true)
1358 printf(
" |%.3d.", k);
1375 printf(
"\nAction Page List (%d/3) - Press key n(Next), b(Prev), q(Quit)", index + 1);
1407 uint32_t torque_enable = 0;
1424 for (
int i = 0; i < num_param; i++)
1460 int right_id = it->first;
1461 int left_id = it->second;
1473 int left_id = it->first;
1474 int right_id = it->second;
1489 int right_id = it->first;
1490 int left_id = it->second;
1502 int left_id = it->first;
1503 int right_id = it->second;
1544 if (i == (action_file_define::MAXNUM_STEP - 1))
1586 printCmd(
"Exist invalid joint value");
1641 for (
int i = src; i < dst; i++)
1649 for (
int i = src; i > dst; i--)
1666 if (ActionModule::getInstance()->loadPage(index, &
page_) ==
true)
1677 ActionModule::getInstance()->resetPage(&
page_);
1701 int32_t goal_position, start_position,
distance;
1702 int max_distance = 0;
1707 it->second->clearParam();
1718 printCmd(
"Exist invalid joint value");
1724 printCmd(
"Failed to read position");
1729 if (start_position > goal_position)
1730 distance = start_position - goal_position;
1732 distance = goal_position - start_position;
1735 distance = distance * 0.03;
1737 if (max_distance < distance)
1738 max_distance = distance;
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;
1758 it->second->addParam(
id, param);
1765 it->second->txPacket();
1768 sleep(max_distance / 1000 + 2);
1773 it->second->clearParam();
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;
1805 it->second->addParam(
id, param);
1812 it->second->txPacket();
1818 printf(
"Go Command Completed");
1826 if (ActionModule::getInstance()->savePage(
page_idx_, &
page_) ==
true)
1835 char name[80] = { 0 };
1836 fgets(name, 80, stdin);
bool loadMp3Path(int mp3_index, std::string &path)
void deleteStepCmd(int index)
const int SPEED_BASE_SCHEDULE
bool param(const std::string ¶m_name, T ¶m_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 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_
int max_joint_name_length_
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_
const int TIME_BASE_SCHEDULE
void printCmd(const char *message)
std::map< std::string, Dynamixel * > dxls_
const int TORQUE_OFF_BIT_MASK
void insertStepCmd(int index)
void moveStepCmd(int src, int dst)
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)
const int INVALID_BIT_MASK
robotis_framework::Robot * robot_
ROSLIB_DECL std::string getPath(const std::string &package_name)
std::string mirror_joint_file_path_
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)
std::map< int, std::string > joint_id_to_name_
robotis_framework::RobotisController * ctrl_
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_