26 #define OFFSET_ROSPARAM_KEY "offset" 27 #define OFFSET_INIT_POS_ROSPARAM_KEY "init_pose_for_offset_tuner" 45 robotis_controller_msgs::JointCtrlModule control_msg;
47 std::map<std::string, robotis_framework::DynamixelState *>::iterator joint_iter;
49 ros::Publisher set_ctrl_module_pub = nh.
advertise<robotis_controller_msgs::JointCtrlModule>(
"/robotis/set_ctrl_module", 1);
51 BaseModule* base_module = BaseModule::getInstance();
53 for (joint_iter = base_module->result_.begin(); joint_iter != base_module->result_.end(); ++joint_iter)
55 control_msg.joint_name.push_back(joint_iter->first);
56 control_msg.module_name.push_back(module);
59 set_ctrl_module_pub.
publish(control_msg);
73 if ((offset_file_ ==
"") || (robot_file_ ==
""))
82 ROS_ERROR(
"ROBOTIS Controller Initialize Fail!");
89 for (std::map<std::string, robotis_framework::Dynamixel *>::iterator robot_it =
controller_->
robot_->
dxls_.begin();
92 std::string joint_name = robot_it->first;
98 std::map<std::string, double> _offset_data;
125 YAML::Node offset_yaml_node = YAML::LoadFile(offset_file_.c_str());
132 for (YAML::const_iterator node_it = offset_data_node.begin(); node_it != offset_data_node.end(); node_it++)
134 std::string joint_name = node_it->first.as<std::string>();
135 double offset = node_it->second.as<
double>();
137 std::map<std::string, JointOffsetData*>::iterator robot_offset_data_it =
robot_offset_data_.find(joint_name);
143 for (YAML::const_iterator ode_it = offset_init_pose_node.begin(); ode_it != offset_init_pose_node.end(); ode_it++)
145 std::string joint_name = ode_it->first.as<std::string>();
146 double offset_init_pose = ode_it->second.as<
double>();
148 std::map<std::string, JointOffsetData*>::iterator robot_offset_data_it =
robot_offset_data_.find(joint_name);
182 ROS_INFO_STREAM(
"num" <<
" | " <<
"joint_name" <<
" | " <<
"InitPose" <<
", " <<
"OffsetAngleRad");
185 std::string joint_name = it->first;
209 BaseModule *base_module = BaseModule::getInstance();
236 std::map<std::string, double> offset_init_pose;
237 for (std::map<std::string, JointOffsetData*>::iterator it =
robot_offset_data_.begin();
240 std::string joint_name = it->first;
275 if (msg->data ==
"save")
290 std::map<std::string, double> offset;
291 std::map<std::string, double> init_pose;
292 for (std::map<std::string, JointOffsetData*>::iterator it =
robot_offset_data_.begin();
295 std::string joint_name = it->first;
302 out << YAML::BeginMap;
303 out << YAML::Key <<
"offset" << YAML::Value << offset;
304 out << YAML::Key <<
"init_pose_for_offset_tuner" << YAML::Value << init_pose;
310 else if (msg->data ==
"ini_pose")
325 ROS_INFO_STREAM(msg->joint_name <<
" " << msg->goal_value <<
" " << msg->offset_value
326 <<
" " << msg->p_gain <<
" " << msg->i_gain <<
" " << msg->d_gain);
328 std::map<std::string, JointOffsetData*>::iterator it;
342 double goal_pose_rad = msg->offset_value + msg->goal_value;
343 int32_t goal_pose_value =
controller_->
robot_->
dxls_[msg->joint_name]->convertRadian2Value(goal_pose_rad);
344 uint8_t dxl_error = 0;
349 goal_pose_value, &dxl_error);
352 ROS_ERROR(
"Failed to write goal position");
363 ROS_ERROR_STREAM(
"goal_pos_set : " << msg->joint_name <<
" has error " << (
int) dxl_error);
373 const thormang3_offset_tuner_msgs::JointTorqueOnOffArray::ConstPtr& msg)
375 for (
unsigned int i = 0; i < msg->torque_enable_data.size(); i++)
377 std::string joint_name = msg->torque_enable_data[i].joint_name;
378 bool torque_enable = msg->torque_enable_data[i].torque_enable;
381 std::map<std::string, JointOffsetData*>::iterator it =
robot_offset_data_.find(joint_name);
390 uint8_t dxl_error = 0;
391 uint8_t torque_enable_value = 0;
394 torque_enable_value = 1;
396 torque_enable_value = 0;
400 torque_enable_value, &dxl_error);
403 ROS_ERROR(
"Failed to write goal position");
412 ROS_ERROR_STREAM(
"goal_pos_set : " << joint_name <<
" has error " << (
int) dxl_error);
419 thormang3_offset_tuner_msgs::GetPresentJointOffsetData::Request &req,
420 thormang3_offset_tuner_msgs::GetPresentJointOffsetData::Response &res)
423 ROS_INFO(
"GetPresentJointOffsetDataService Called");
425 for (std::map<std::string, JointOffsetData*>::iterator it =
robot_offset_data_.begin();
428 std::string joint_name = it->first;
431 thormang3_offset_tuner_msgs::JointOffsetPositionData joint_offset_pos;
433 int32_t present_pos_value = 0;
434 uint8_t dxl_error = 0;
439 (uint32_t*) &present_pos_value,
453 joint_offset_pos.joint_name = joint_name;
456 joint_offset_pos.present_value =
controller_->
robot_->
dxls_[joint_name]->convertValue2Radian(present_pos_value);
457 joint_offset_pos.p_gain = joint_data->
p_gain_;
458 joint_offset_pos.i_gain = joint_data->
i_gain_;
459 joint_offset_pos.d_gain = joint_data->
d_gain_;
461 res.present_data_array.push_back(joint_offset_pos);
void poseGenerateProc(Eigen::MatrixXd joint_angle_pose)
void publish(const boost::shared_ptr< M > &message) const
ros::Subscriber joint_torque_enable_sub_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Subscriber command_sub_
void jointOffsetDataCallback(const thormang3_offset_tuner_msgs::JointOffsetData::ConstPtr &msg)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void addMotionModule(MotionModule *module)
ros::Subscriber send_tra_sub_
std::map< std::string, Dynamixel * > dxls_
ros::Subscriber joint_offset_data_sub_
std::map< std::string, bool > robot_torque_enable_data_
bool initialize(const std::string robot_file_path, const std::string init_file_path)
void jointTorqueOnOffCallback(const thormang3_offset_tuner_msgs::JointTorqueOnOffArray::ConstPtr &msg)
bool getPresentJointOffsetDataServiceCallback(thormang3_offset_tuner_msgs::GetPresentJointOffsetData::Request &req, thormang3_offset_tuner_msgs::GetPresentJointOffsetData::Response &res)
double joint_init_pos_rad_
#define OFFSET_ROSPARAM_KEY
ros::ServiceServer offset_data_server_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void setCtrlModule(std::string module)
#define OFFSET_INIT_POS_ROSPARAM_KEY
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void commandCallback(const std_msgs::String::ConstPtr &msg)
robotis_framework::RobotisController * controller_
#define ROS_INFO_STREAM(args)
void stringMsgsCallBack(const std_msgs::String::ConstPtr &msg)
#define ROS_ERROR_STREAM(args)
int writeCtrlItem(const std::string joint_name, const std::string item_name, uint32_t data, uint8_t *error=0)
std::map< std::string, JointOffsetData * > robot_offset_data_
int readCtrlItem(const std::string joint_name, const std::string item_name, uint32_t *data, uint8_t *error=0)