30 : control_cycle_msec_(0),
33 is_direct_control_(false),
37 original_position_lidar_(0.0),
107 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Fail to move Lidar");
113 fprintf(stderr,
"TOPIC CALLBACK : get_3d_lidar\n");
122 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_INFO,
"Start head joint in order to make pointcloud");
127 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Fail to move Lidar");
135 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Fail to move Lidar");
141 fprintf(stderr,
"TOPIC CALLBACK : get_3d_lidar\n");
151 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_INFO,
"Start head joint in order to make pointcloud");
156 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Fail to move Lidar");
164 ROS_INFO(
"Head module is not enable.");
165 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Not Enable");
173 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Head is busy.");
184 for (
int ix = 0; ix < msg->name.size(); ix++)
186 std::string joint_name = msg->name[ix];
202 std::cout <<
"joint : " << joint_name <<
", Index : " << iter->second <<
", Angle : " << msg->position[ix]
230 ROS_INFO(
"Head module is not enable.");
231 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Not Enable");
239 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_ERROR,
"Head is busy.");
250 for (
int ix = 0; ix < msg->angle.name.size(); ix++)
252 std::string joint_name = msg->angle.name[ix];
268 std::cout <<
"joint : " << joint_name <<
", Index : " << iter->second <<
", Angle : " << msg->angle.position[ix]
293 std::map<std::string, double> sensors)
301 for (std::map<std::string, robotis_framework::DynamixelState *>::iterator state_iter =
result_.begin();
302 state_iter !=
result_.end(); state_iter++)
304 std::string joint_name = state_iter->first;
308 std::map<std::string, robotis_framework::Dynamixel*>::iterator dxl_it = dxls.find(joint_name);
309 if (dxl_it != dxls.end())
310 dxl = dxl_it->second;
349 for (std::map<std::string, robotis_framework::DynamixelState *>::iterator state_iter =
result_.begin();
350 state_iter !=
result_.end(); state_iter++)
352 std::string joint_name = state_iter->first;
404 double target_angle =
424 "Finish head joint in order to make pointcloud");
428 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_INFO,
"Head movement is finished.");
437 std::cout <<
"Trajectory End" << std::endl;
461 publishStatusMsg(robotis_controller_msgs::StatusMsg::STATUS_WARN,
"Stop Module.");
470 double min_moving_time = 1.0;
488 ROS_INFO(
"Go to Lidar start position");
495 double max_moving_time = 8.0;
514 ROS_INFO(
"Go to Lidar end position");
534 ROS_INFO(
"Go to Lidar before position");
539 std_msgs::String msg;
544 if (msg_data ==
"end")
564 double pos_end,
double vel_end,
double accel_end,
565 double smp_time,
double mov_time)
567 Eigen::MatrixXd poly_matrix(3, 3);
568 Eigen::MatrixXd poly_vector(3, 1);
575 poly_vector << pos_end - pos_start - vel_start * mov_time - accel_start * pow(mov_time, 2) / 2, vel_end - vel_start
576 - accel_start * mov_time, accel_end - accel_start;
578 Eigen::MatrixXd poly_coeff = poly_matrix.inverse() * poly_vector;
580 int all_time_steps = round(mov_time / smp_time + 1);
582 Eigen::MatrixXd time = Eigen::MatrixXd::Zero(all_time_steps, 1);
583 Eigen::MatrixXd minimum_jer_tra = Eigen::MatrixXd::Zero(all_time_steps, 3);
585 for (
int step = 0; step < all_time_steps; step++)
586 time.coeffRef(step, 0) = step * smp_time;
588 for (
int step = 0; step < all_time_steps; step++)
591 minimum_jer_tra.coeffRef(step, 0) = pos_start + vel_start * time.coeff(step, 0)
597 minimum_jer_tra.coeffRef(step, 1) = vel_start + accel_start * time.coeff(step, 0)
602 minimum_jer_tra.coeffRef(step, 2) = accel_start + 6 * poly_coeff.coeff(0, 0) * time.coeff(step, 0)
607 return minimum_jer_tra;
613 double time_steps = mov_time / smp_time;
614 int all_time_steps = round(time_steps + 1);
615 double next_step = (pos_end - pos_start) / all_time_steps;
617 Eigen::MatrixXd minimum_jerk_tra = Eigen::MatrixXd::Zero(all_time_steps, 1);
619 for (
int step = 0; step < all_time_steps; step++)
620 minimum_jerk_tra.coeffRef(step, 0) = pos_start + next_step * (step + 1);
622 return minimum_jerk_tra;
636 for (std::map<std::string, robotis_framework::DynamixelState *>::iterator state_iter =
result_.begin();
637 state_iter !=
result_.end(); state_iter++)
639 std::string joint_name = state_iter->first;
648 Eigen::MatrixXd tra =
calcMinimumJerkTraPVA(ini_value, ini_vel, ini_accel, tar_value, 0.0, 0.0, smp_time,
651 calc_joint_tra_.block(0, index, all_time_steps, 1) = tra.block(0, 0, all_time_steps, 1);
652 calc_joint_vel_tra_.block(0, index, all_time_steps, 1) = tra.block(0, 1, all_time_steps, 1);
677 for (std::map<std::string, robotis_framework::DynamixelState *>::iterator state_iter =
result_.begin();
678 state_iter !=
result_.end(); state_iter++)
680 std::string joint_name = state_iter->first;
688 calc_joint_tra_.block(0, index, all_time_steps, 1) = tra.block(0, 0, all_time_steps, 1);
705 robotis_controller_msgs::StatusMsg status_msg;
707 status_msg.type = type;
708 status_msg.module_name =
"Head Control";
709 status_msg.status_msg = msg;
716 std_msgs::String movement_msg;
717 movement_msg.data = done_msg;
boost::thread * tra_gene_thread_
void lidarJointTraGeneThread()
void setHeadJointTimeCallback(const thormang3_head_control_module_msgs::HeadJointPose::ConstPtr &msg)
std::map< std::string, DynamixelState * > result_
void publish(const boost::shared_ptr< M > &message) const
std::map< std::string, int > using_joint_name_
Eigen::MatrixXd goal_position_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
Eigen::MatrixXd calcLinearInterpolationTra(double pos_start, double pos_end, double smp_time, double mov_time)
const double SCAN_START_ANGLE
const double SCAN_END_ANGLE
void publishDoneMsg(const std::string done_msg)
ControlMode control_mode_
void startMoveLidar(double target_angle)
Eigen::MatrixXd current_position_
virtual ~HeadControlModule()
ros::Publisher movement_done_pub_
void get3DLidarCallback(const std_msgs::String::ConstPtr &msg)
void setCallbackQueue(CallbackQueueInterface *queue)
double original_position_lidar_
ros::Publisher status_msg_pub_
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)
Eigen::MatrixXd target_position_
void setHeadJointCallback(const sensor_msgs::JointState::ConstPtr &msg)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
Eigen::MatrixXd calc_joint_accel_tra_
void jointTraGeneThread()
Eigen::MatrixXd goal_velocity_
Eigen::MatrixXd calc_joint_tra_
double powDI(double a, int b)
#define ROS_INFO_STREAM(args)
void publishStatusMsg(unsigned int type, std::string msg)
DynamixelState * dxl_state_
Eigen::MatrixXd calc_joint_vel_tra_
void initialize(const int control_cycle_msec, robotis_framework::Robot *robot)
boost::thread queue_thread_
ros::Publisher moving_head_pub_
void process(std::map< std::string, robotis_framework::Dynamixel * > dxls, std::map< std::string, double > sensors)
void publishLidarMoveMsg(std::string msg_data)
void get3DLidarRangeCallback(const std_msgs::Float64::ConstPtr &msg)
void beforeMoveLidar(double start_angle)
Eigen::MatrixXd goal_acceleration_