Go to the documentation of this file.00001 #include "arm_movements_by_pose_alg.h"
00002
00003 ArmMovementsByPoseAlgorithm::ArmMovementsByPoseAlgorithm(void)
00004 {
00005 }
00006
00007 ArmMovementsByPoseAlgorithm::~ArmMovementsByPoseAlgorithm(void)
00008 {
00009 }
00010
00011 void ArmMovementsByPoseAlgorithm::config_update(Config& new_cfg, uint32_t level)
00012 {
00013 this->lock();
00014
00015 this->hand_size_offset = new_cfg.hand_size_offset;
00016 this->wam_security_distance = new_cfg.wam_security_distance;
00017 this->tf_target_str = new_cfg.tf_target_str;
00018 this->robot_wam = new_cfg.robot_wam;
00019
00020
00021 this->config_=new_cfg;
00022
00023 this->unlock();
00024 }
00025
00026
00027 geometry_msgs::PoseStamped ArmMovementsByPoseAlgorithm::get_pose_from_tf_with_offset(geometry_msgs::PoseStamped pose_orig,
00028 std::vector<float> plane_coefs)
00029 {
00030 pose_orig.pose.position.x += (hand_size_offset * plane_coefs[0]);
00031 pose_orig.pose.position.y += (hand_size_offset * plane_coefs[1]);
00032 pose_orig.pose.position.z += (hand_size_offset * plane_coefs[2]);
00033
00034 geometry_msgs::PoseStamped pose_wam;
00035
00036
00037 ros::Time common_time;
00038 std::string error_aux;
00039 tf_listener.getLatestCommonTime(this->tf_target_str, pose_orig.header.frame_id, common_time, &error_aux);
00040 tf_listener.transformPose(this->tf_target_str, common_time, pose_orig, pose_orig.header.frame_id, pose_wam);
00041
00042
00043 if (not this->robot_wam && (pose_wam.pose.position.z < wam_security_distance)) {
00044 throw "Movement is below security distance";
00045 }
00046
00047 return pose_wam;
00048 }
00049
00050
00051
00052
00053 std::vector<geometry_msgs::PoseStamped> ArmMovementsByPoseAlgorithm::get_initial_position()
00054 {
00055 std::vector<geometry_msgs::PoseStamped> movements;
00056
00057 geometry_msgs::PoseStamped pose_st;
00058
00059 if (robot_wam) {
00060
00061
00062
00063
00064
00065
00066 pose_st.pose.orientation.x = 0.7071;
00067 pose_st.pose.orientation.y = 0.7071;
00068 pose_st.pose.orientation.z = 0;
00069 pose_st.pose.orientation.w = 0;
00070
00071 pose_st.pose.position.x = 0.5;
00072 pose_st.pose.position.y = 0;
00073 pose_st.pose.position.z = 0.4;
00074
00075 pose_st.header.frame_id = "/wam_fk/wam0";
00076 }
00077 else {
00078
00079 pose_st.pose.orientation.x = 0.7789;
00080 pose_st.pose.orientation.y = -0.6157;
00081 pose_st.pose.orientation.z = 0.0867;
00082 pose_st.pose.orientation.w = -0.0811;
00083
00084 pose_st.pose.position.x = -0.1438;
00085 pose_st.pose.position.y = -0.2728;
00086 pose_st.pose.position.z = 0.8070;
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 pose_st.header.frame_id = "base_footprint";
00101 }
00102
00103 movements.push_back(pose_st);
00104
00105 return movements;
00106 }
00107
00108
00109 std::vector<geometry_msgs::PoseStamped> ArmMovementsByPoseAlgorithm::get_transformed_poses(std::vector<geometry_msgs::PoseStamped> poses,
00110 std::vector<float> plane_coefficients)
00111 {
00112 std::vector<geometry_msgs::PoseStamped> wam_tf_poses;
00113
00114 for (size_t i = 0; i < poses.size(); i++) {
00115 try {
00116 geometry_msgs::PoseStamped pose = get_pose_from_tf_with_offset(poses[i], plane_coefficients);
00117 wam_tf_poses.push_back(pose);
00118 }
00119 catch (char const* e) {
00120 ROS_ERROR_STREAM("SECURITY DISTANCE IS " << wam_security_distance);
00121 }
00122 }
00123
00124 return wam_tf_poses;
00125 }
00126
00127
00128 geometry_msgs::Quaternion ArmMovementsByPoseAlgorithm::rotate_pitch(geometry_msgs::Quaternion orientation_msgs, double angle)
00129 {
00130 using namespace Eigen;
00131
00132 Quaternion<float> q_orig(orientation_msgs.w, orientation_msgs.x, orientation_msgs.y, orientation_msgs.z);
00133 Quaternion<float> q_rot(AngleAxis<float>(angle, Vector3f(0,1,0)));
00134
00135 Quaternion<float> q_dest;
00136 q_dest = q_orig * q_rot;
00137 orientation_msgs.x = q_dest.x();
00138 orientation_msgs.y = q_dest.y();
00139 orientation_msgs.z = q_dest.z();
00140 orientation_msgs.w = q_dest.w();
00141
00142 return orientation_msgs;
00143 }
00144
00145 geometry_msgs::Quaternion ArmMovementsByPoseAlgorithm::rotate_roll(geometry_msgs::Quaternion orientation_msgs, double angle)
00146 {
00147 using namespace Eigen;
00148
00149 Quaternion<float> q_orig(orientation_msgs.w, orientation_msgs.x, orientation_msgs.y, orientation_msgs.z);
00150 Quaternion<float> q_rot(AngleAxis<float>(angle, Vector3f(1,0,0)));
00151
00152 Quaternion<float> q_dest;
00153 q_dest = q_orig * q_rot;
00154 orientation_msgs.x = q_dest.x();
00155 orientation_msgs.y = q_dest.y();
00156 orientation_msgs.z = q_dest.z();
00157 orientation_msgs.w = q_dest.w();
00158
00159 return orientation_msgs;
00160 }
00161
00162 geometry_msgs::Quaternion ArmMovementsByPoseAlgorithm::rotate_yaw(geometry_msgs::Quaternion orientation_msgs, double angle)
00163 {
00164 using namespace Eigen;
00165
00166 Quaternion<float> q_orig(orientation_msgs.w, orientation_msgs.x, orientation_msgs.y, orientation_msgs.z);
00167 Quaternion<float> q_rot(AngleAxis<float>(angle, Vector3f(0,0,1)));
00168
00169 Quaternion<float> q_dest;
00170 q_dest = q_orig * q_rot;
00171
00172 geometry_msgs::Quaternion result_quaterion_msgs;
00173 result_quaterion_msgs.x = q_dest.x();
00174 result_quaterion_msgs.y = q_dest.y();
00175 result_quaterion_msgs.z = q_dest.z();
00176 result_quaterion_msgs.w = q_dest.w();
00177
00178 return result_quaterion_msgs;
00179 }