$search
00001 #include <ros/ros.h> 00002 #include <kinematics_msgs/GetKinematicSolverInfo.h> 00003 #include <kinematics_msgs/GetPositionFK.h> 00004 00005 int main(int argc, char **argv){ 00006 ros::init (argc, argv, "get_fk"); 00007 ros::NodeHandle rh; 00008 00009 ros::service::waitForService("rosie_right_arm_kinematics/get_fk_solver_info"); 00010 ros::service::waitForService("rosie_right_arm_kinematics/get_fk"); 00011 00012 ros::ServiceClient query_client = 00013 rh.serviceClient<kinematics_msgs::GetKinematicSolverInfo> 00014 ("rosie_right_arm_kinematics/get_fk_solver_info"); 00015 ros::ServiceClient fk_client = rh.serviceClient 00016 <kinematics_msgs::GetPositionFK>("rosie_right_arm_kinematics/get_fk"); 00017 00018 // define the service messages 00019 kinematics_msgs::GetKinematicSolverInfo::Request request; 00020 kinematics_msgs::GetKinematicSolverInfo::Response response; 00021 if(query_client.call(request,response)) 00022 { 00023 for(unsigned int i=0; 00024 i< response.kinematic_solver_info.joint_names.size(); i++) 00025 { 00026 ROS_DEBUG("Joint: %d %s", i, 00027 response.kinematic_solver_info.joint_names[i].c_str()); 00028 } 00029 } 00030 else 00031 { 00032 ROS_ERROR("Could not call query service"); 00033 ros::shutdown(); 00034 exit(1); 00035 } 00036 // define the service messages 00037 kinematics_msgs::GetPositionFK::Request fk_request; 00038 kinematics_msgs::GetPositionFK::Response fk_response; 00039 fk_request.header.frame_id = "calib_right_arm_base_link"; 00040 fk_request.header.frame_id = "base_link"; 00041 fk_request.fk_link_names.resize(2); 00042 fk_request.fk_link_names[0] = "right_arm_hand_link"; 00043 fk_request.fk_link_names[1] = "right_arm_2_link"; 00044 fk_request.robot_state.joint_state.position.resize 00045 (response.kinematic_solver_info.joint_names.size()); 00046 fk_request.robot_state.joint_state.name = 00047 response.kinematic_solver_info.joint_names; 00048 for(unsigned int i=0; 00049 i< response.kinematic_solver_info.joint_names.size(); i++) 00050 { 00051 fk_request.robot_state.joint_state.position[i] = 0.1; 00052 } 00053 if(fk_client.call(fk_request, fk_response)) 00054 { 00055 if(fk_response.error_code.val == fk_response.error_code.SUCCESS) 00056 { 00057 for(unsigned int i=0; i < fk_response.pose_stamped.size(); i ++) 00058 { 00059 ROS_INFO_STREAM("Link : " << fk_response.fk_link_names[i].c_str()); 00060 ROS_INFO_STREAM("Position: " << 00061 fk_response.pose_stamped[i].pose.position.x << "," << 00062 fk_response.pose_stamped[i].pose.position.y << "," << 00063 fk_response.pose_stamped[i].pose.position.z); 00064 ROS_INFO("Orientation: %f %f %f %f", 00065 fk_response.pose_stamped[i].pose.orientation.x, 00066 fk_response.pose_stamped[i].pose.orientation.y, 00067 fk_response.pose_stamped[i].pose.orientation.z, 00068 fk_response.pose_stamped[i].pose.orientation.w); 00069 } 00070 } 00071 else 00072 { 00073 ROS_ERROR("Forward kinematics failed"); 00074 } 00075 } 00076 else 00077 { 00078 ROS_ERROR("Forward kinematics service call failed"); 00079 } 00080 ros::shutdown(); 00081 } 00082 00083