26 : control_cycle_msec_(0),
29 is_direct_control_(true),
34 has_goal_position_(false),
120 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Not Enable");
126 std::cout <<
"wait for receiving current position" << std::endl;
135 for (
int ix = 0; ix < msg->name.size(); ix++)
137 std::string joint_name = msg->name[ix];
138 std::map<std::string, int>::iterator joint_it =
using_joint_name_.find(joint_name);
142 double target_position = 0.0;
143 int joint_index = joint_it->second;
146 if (is_offset ==
true)
147 target_position =
goal_position_.coeff(0, joint_index) + msg->position[ix];
149 target_position = msg->position[ix];
153 if(is_checked ==
false)
170 std::cout <<
" - joint : " << joint_name <<
", Index : " << joint_index <<
"\n Target Angle : " <<
target_position_.coeffRef(0, joint_index) <<
", Curr Goal : " <<
goal_position_.coeff(0, joint_index)
171 <<
", Time : " <<
moving_time_ <<
", msg : " << msg->position[ix] << std::endl;
188 ROS_ERROR_THROTTLE(1,
"Head control module is not enabled, scan command is canceled.");
196 std::srand(std::time(NULL));
203 else if (msg->data ==
"stop")
211 std::map<int, double>::iterator angle_it =
min_angle_.find(joint_index);
214 double min_angle = angle_it->second;
219 double max_angle = angle_it->second;
221 if (goal_position < min_angle)
222 goal_position = min_angle;
223 if (goal_position > max_angle)
224 goal_position = max_angle;
230 std::map<std::string, double> sensors)
238 for (std::map<std::string, robotis_framework::DynamixelState *>::iterator state_it =
result_.begin();
239 state_it !=
result_.end(); state_it++)
241 std::string joint_name = state_it->first;
245 std::map<std::string, robotis_framework::Dynamixel*>::iterator dxl_it = dxls.find(joint_name);
246 if (dxl_it != dxls.end())
247 _dxl = dxl_it->second;
292 for (std::map<std::string, robotis_framework::DynamixelState *>::iterator state_it =
result_.begin();
293 state_it !=
result_.end(); state_it++)
295 std::string joint_name = state_it->first;
300 result_[joint_name]->goal_position_ = goal_position;
341 std::cout <<
"head_control_module : disable";
364 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_INFO,
"Head movement is finished.");
367 std::cout <<
"Trajectory End" << std::endl;
411 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_WARN,
"Stop Module.");
416 switch (head_direction)
453 for (std::map<std::string, robotis_framework::DynamixelState *>::iterator state_it =
result_.begin();
454 state_it !=
result_.end(); state_it++)
456 std::string joint_name = state_it->first;
486 double pos_end,
double vel_end,
double accel_end,
487 double smp_time,
double mov_time)
489 Eigen::MatrixXd poly_matrix(3, 3);
490 Eigen::MatrixXd poly_vector(3, 1);
497 poly_vector << pos_end - pos_start - vel_start * mov_time - accel_start * pow(mov_time, 2) / 2, vel_end - vel_start
498 - accel_start * mov_time, accel_end - accel_start;
500 Eigen::MatrixXd poly_coeff = poly_matrix.inverse() * poly_vector;
502 int all_time_steps = round(mov_time / smp_time + 1);
504 Eigen::MatrixXd time = Eigen::MatrixXd::Zero(all_time_steps, 1);
505 Eigen::MatrixXd minimum_jer_tra = Eigen::MatrixXd::Zero(all_time_steps, 3);
507 for (
int step = 0; step < all_time_steps; step++)
508 time.coeffRef(step, 0) = step * smp_time;
510 for (
int step = 0; step < all_time_steps; step++)
513 minimum_jer_tra.coeffRef(step, 0) = pos_start + vel_start * time.coeff(step, 0)
519 minimum_jer_tra.coeffRef(step, 1) = vel_start + accel_start * time.coeff(step, 0)
524 minimum_jer_tra.coeffRef(step, 2) = accel_start + 6 * poly_coeff.coeff(0, 0) * time.coeff(step, 0)
529 return minimum_jer_tra;
546 catch(std::exception &e)
548 std::cout <<
"All step tile : " << all_time_steps << std::endl;
549 std::cout << e.what() << std::endl;
553 for (std::map<std::string, robotis_framework::DynamixelState *>::iterator state_it =
result_.begin();
554 state_it !=
result_.end(); state_it++)
556 std::string joint_name = state_it->first;
565 Eigen::MatrixXd tra =
calcMinimumJerkTraPVA(ini_value, ini_vel, ini_accel, tar_value, 0.0, 0.0, smp_time,
568 calc_joint_tra_.block(0, index, all_time_steps, 1) = tra.block(0, 0, all_time_steps, 1);
569 calc_joint_vel_tra_.block(0, index, all_time_steps, 1) = tra.block(0, 1, all_time_steps, 1);
593 robotis_controller_msgs::StatusMsg status_msg;
594 status_msg.header.stamp = now;
595 status_msg.type = type;
596 status_msg.module_name =
"Head Control";
597 status_msg.status_msg = msg;
Eigen::MatrixXd calc_joint_vel_tra_
Eigen::MatrixXd calcMinimumJerkTraPVA(double pos_start, double vel_start, double accel_start, double pos_end, double vel_end, double accel_end, double smp_time, double mov_time)
std::map< std::string, DynamixelState * > result_
void publish(const boost::shared_ptr< M > &message) const
std::map< std::string, int > using_joint_name_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
Eigen::MatrixXd target_position_
void initialize(const int control_cycle_msec, robotis_framework::Robot *robot)
void process(std::map< std::string, robotis_framework::Dynamixel * > dxls, std::map< std::string, double > sensors)
void setHeadJointCallback(const sensor_msgs::JointState::ConstPtr &msg)
Eigen::MatrixXd calc_joint_accel_tra_
bool checkAngleLimit(const int joint_index, double &goal_position)
std::map< int, double > max_angle_
ControlMode control_mode_
boost::thread * tra_gene_thread_
#define ROS_ERROR_THROTTLE(rate,...)
Eigen::MatrixXd goal_velocity_
virtual ~HeadControlModule()
ros::Publisher status_msg_pub_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void setCallbackQueue(CallbackQueueInterface *queue)
boost::thread queue_thread_
Eigen::MatrixXd current_position_
std::map< int, double > min_angle_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
void setHeadJointOffsetCallback(const sensor_msgs::JointState::ConstPtr &msg)
void jointTraGeneThread()
Eigen::MatrixXd calc_joint_tra_
void setHeadJoint(const sensor_msgs::JointState::ConstPtr &msg, bool is_offset)
double powDI(double a, int b)
void generateScanTra(const int head_direction)
DynamixelState * dxl_state_
void setHeadScanCallback(const std_msgs::String::ConstPtr &msg)
Eigen::MatrixXd goal_position_
#define ROS_INFO_THROTTLE(rate,...)
#define ROS_ERROR_STREAM(args)
void publishStatusMsg(unsigned int type, std::string msg)
Eigen::MatrixXd goal_acceleration_