Go to the documentation of this file.00001 #include "wam_move_arm_alg.h"
00002 static const std::string FK_SERVICE = "/iri_wam_iri_wam_kinematics/get_fk";
00003 static const std::string INFO_SERVICE = "/iri_wam_iri_wam_kinematics/get_fk_solver_info";
00004 WamMoveArmAlgorithm::WamMoveArmAlgorithm(void)
00005 {
00006
00007
00008 }
00009
00010 WamMoveArmAlgorithm::~WamMoveArmAlgorithm(void)
00011 {
00012 }
00013
00014 void WamMoveArmAlgorithm::config_update(Config& new_cfg, uint32_t level)
00015 {
00016 this->lock();
00017
00018
00019 this->config_=new_cfg;
00020
00021 this->unlock();
00022 }
00023
00024
00025 void WamMoveArmAlgorithm::reconfigure_point(arm_navigation_msgs::PositionConstraint &position_constraint)
00026 {
00027 position_constraint.position.x=position_constraint.position.x-tool_x;
00028 position_constraint.position.y=position_constraint.position.y-tool_y;
00029 position_constraint.position.z=position_constraint.position.z-tool_z;
00030 }
00031 void WamMoveArmAlgorithm::reconfigure_points(std::vector<arm_navigation_msgs::PositionConstraint> & position_constraint)
00032 {
00033 for(size_t i =0; i < position_constraint.size(); ++i)
00034 {
00035 reconfigure_point(position_constraint[i]);
00036 }
00037
00038 }
00039 void WamMoveArmAlgorithm::reconfigure_joint(std::vector<arm_navigation_msgs::JointConstraint>& joint_constraints,arm_navigation_msgs::MoveArmGoal& goal)
00040 {
00041 std::vector<double> position;
00042 geometry_msgs::PoseStamped pose;
00043 arm_navigation_msgs::MoveArmGoal move=goal;
00044 for(size_t i=0; i < joint_constraints.size(); ++i)
00045 {
00046 position.push_back(joint_constraints[i].position);
00047 }
00048 calculateFK(position,pose);
00049 makeMsg(pose,move,link_name);
00050 goal=move;
00051 }
00052 void WamMoveArmAlgorithm::calculateFK(const std::vector<double> &pos,geometry_msgs::PoseStamped& pose)
00053 {
00054 ros::NodeHandle rh;
00055 ros::service::waitForService(INFO_SERVICE);
00056 ros::service::waitForService(FK_SERVICE);
00057 ros::ServiceClient query_client = rh.serviceClient<kinematics_msgs::GetKinematicSolverInfo> (INFO_SERVICE);
00058 ros::ServiceClient fk_client = rh.serviceClient<kinematics_msgs::GetPositionFK>(FK_SERVICE);
00059
00060
00061 kinematics_msgs::GetKinematicSolverInfo::Request request;
00062 kinematics_msgs::GetKinematicSolverInfo::Response response;
00063 if(!query_client.call(request,response))
00064 {
00065 ROS_ERROR("Could not call query service");
00066 ros::shutdown();
00067 exit(1);
00068 }
00069
00070 kinematics_msgs::GetPositionFK::Request fk_request;
00071 kinematics_msgs::GetPositionFK::Response fk_response;
00072 fk_request.header.frame_id = "wam_link0";
00073 fk_request.fk_link_names = response.kinematic_solver_info.link_names;
00074 fk_request.robot_state.joint_state.position=pos;
00075 fk_request.robot_state.joint_state.name = response.kinematic_solver_info.joint_names;
00076 link_name=response.kinematic_solver_info.link_names[response.kinematic_solver_info.link_names.size()-1];
00077 if(fk_client.call(fk_request, fk_response))
00078 {
00079 if(fk_response.error_code.val == fk_response.error_code.SUCCESS)
00080 {
00081 pose=fk_response.pose_stamped[fk_response.pose_stamped.size()-1];
00082 }
00083 else
00084 {
00085 ROS_ERROR("Forward kinematics failed");
00086 ROS_ERROR_STREAM("CODE: "<<fk_response.error_code.val);
00087 }
00088 }
00089 else
00090 {
00091 ROS_ERROR("Forward kinematics service call failed");
00092 ros::shutdown();
00093 exit(1);
00094 }
00095 }
00096 void WamMoveArmAlgorithm::makeMsg(const geometry_msgs::PoseStamped &pose, arm_navigation_msgs::MoveArmGoal& goal, const std::string& link)
00097 {
00098 arm_navigation_msgs::PositionConstraint position_constraint;
00099 arm_navigation_msgs::OrientationConstraint orientation_constraints;
00100 arm_navigation_msgs::poseStampedToPositionOrientationConstraints(pose,link,position_constraint,orientation_constraints);
00101 reconfigure_point(position_constraint);
00102 goal.motion_plan_request.goal_constraints.position_constraints.clear();
00103 goal.motion_plan_request.goal_constraints.orientation_constraints.clear();
00104 goal.motion_plan_request.goal_constraints.joint_constraints.clear();
00105 goal.motion_plan_request.goal_constraints.position_constraints.push_back(position_constraint);
00106 goal.motion_plan_request.goal_constraints.orientation_constraints.push_back(orientation_constraints);
00107 }
00108 bool WamMoveArmAlgorithm::hasPose(const arm_navigation_msgs::MoveArmGoal& goal)
00109 {
00110 return (goal.motion_plan_request.goal_constraints.position_constraints.size() == 0)? false: true;
00111 }
00112 bool WamMoveArmAlgorithm::hasJoint(const arm_navigation_msgs::MoveArmGoal& goal)
00113 {
00114 return (goal.motion_plan_request.goal_constraints.joint_constraints.size() == 0)? false: true;
00115 }
00116 void WamMoveArmAlgorithm::reconfigure(arm_navigation_msgs::MoveArmGoal& goal)
00117 {
00118 if(hasPose(goal))
00119 reconfigure_points(goal.motion_plan_request.goal_constraints.position_constraints);
00120 else if(hasJoint(goal))
00121 reconfigure_joint(goal.motion_plan_request.goal_constraints.joint_constraints,goal);
00122 }