00001 /* 00002 * Software License Agreement (Modified BSD License) 00003 * 00004 * Copyright (c) 2011, PAL Robotics, S.L. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of PAL Robotics, S.L. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 00039 #include <string> 00040 00041 #include <kdl/frames.hpp> 00042 #include <kdl/jntarray.hpp> 00043 #include <kdl/jntarrayvel.hpp> 00044 #include <kdl/treeiksolver.hpp> 00045 #include <ros/ros.h> 00046 #include <tf/transform_listener.h> 00047 00048 00049 class ReemTeleop 00050 { 00051 public: 00052 ReemTeleop(ros::NodeHandle &nh, KDL::Tree &kdl_tree); 00053 ~ReemTeleop(); 00054 00055 00056 ros::NodeHandle nh_; 00057 00058 // ROS subscribers listening for desired endpoints' poses 00059 ros::Subscriber sub_command_pose_torso_; 00060 ros::Subscriber sub_command_pose_shoulder_left_; 00061 ros::Subscriber sub_command_pose_elbow_left_; 00062 ros::Subscriber sub_command_pose_hand_left_; 00063 ros::Subscriber sub_command_pose_shoulder_right_; 00064 ros::Subscriber sub_command_pose_elbow_right_; 00065 ros::Subscriber sub_command_pose_hand_right_; 00066 ros::Subscriber sub_command_pose_head_; 00067 00068 void commandPoseTorsoCB(const geometry_msgs::PoseStamped::ConstPtr &command); 00069 void commandPoseLeftShoulderCB(const geometry_msgs::PoseStamped::ConstPtr &command); 00070 void commandPoseLeftElbowCB(const geometry_msgs::PoseStamped::ConstPtr &command); 00071 void commandPoseLeftHandCB(const geometry_msgs::PoseStamped::ConstPtr &command); 00072 void commandPoseRightShoulderCB(const geometry_msgs::PoseStamped::ConstPtr &command); 00073 void commandPoseRightElbowCB(const geometry_msgs::PoseStamped::ConstPtr &command); 00074 void commandPoseRightHandCB(const geometry_msgs::PoseStamped::ConstPtr &command); 00075 void commandPoseHeadCB(const geometry_msgs::PoseStamped::ConstPtr &command); 00076 00077 // tf for transforming geometry_msgs::PoseStamped to KDL::Frame 00078 tf::TransformListener tf_; 00079 00080 // The tree's root name for calculatiing transforms by tf 00081 std::string tree_root_name_; 00082 00083 // Boolean flags indicating if new poses have arrived 00084 bool new_x_desi_torso_; 00085 bool new_x_desi_l_shoulder_; 00086 bool new_x_desi_l_elbow_; 00087 bool new_x_desi_l_hand_; 00088 bool new_x_desi_r_shoulder_; 00089 bool new_x_desi_r_elbow_; 00090 bool new_x_desi_r_hand_; 00091 bool new_x_desi_head_; 00092 00093 // KDL variables (which need to be pre-allocated). 00094 KDL::Tree kdl_tree_; 00095 00096 KDL::JntArray q_; // Joint positions 00097 KDL::JntArray q_desi_; // Desired joint positions 00098 00099 KDL::Frames x0s_; // (Map of) Inital frames of the endpoints 00100 KDL::Frames xs_; // (Map of) Frames of the endpoints 00101 KDL::Frames xs_desi_; // (Map of) Desired positions of the endpoints 00102 00103 KDL::Frame x0_torso_; // Torso initial pose 00104 KDL::Frame x_torso_; // Torso pose 00105 KDL::Frame x_desi_torso_; // Torso desired pose 00106 00107 KDL::Frame x0_l_shoulder_; // Left shoulder initial pose 00108 KDL::Frame x_l_shoulder_; // Left shoulder pose 00109 KDL::Frame x_desi_l_shoulder_; // Left shoulder desired pose 00110 00111 KDL::Frame x0_l_elbow_; // Left elbow initial pose 00112 KDL::Frame x_l_elbow_; // Left elbow pose 00113 KDL::Frame x_desi_l_elbow_; // Left elbow desired pose 00114 00115 KDL::Frame x0_l_hand_; // Left hand initial pose 00116 KDL::Frame x_l_hand_; // Left hand pose 00117 KDL::Frame x_desi_l_hand_; // Left hand desired pose 00118 00119 KDL::Frame x0_r_shoulder_; // Right shoulder initial pose 00120 KDL::Frame x_r_shoulder_; // Right shoulder pose 00121 KDL::Frame x_desi_r_shoulder_; // Right shoulder desired pose 00122 00123 KDL::Frame x0_r_elbow_; // Right elbow initial pose 00124 KDL::Frame x_r_elbow_; // Right elbow pose 00125 KDL::Frame x_desi_r_elbow_; // Right elbow desired pose 00126 00127 KDL::Frame x0_r_hand_; // Right hand initial pose 00128 KDL::Frame x_r_hand_; // Right hand pose 00129 KDL::Frame x_desi_r_hand_; // Right hand desired pose 00130 00131 KDL::Frame x0_head_; // Head initial pose 00132 KDL::Frame x_head_; // Head pose 00133 KDL::Frame x_desi_head_; // Head desired pose 00134 private: 00135 }; 00136