grasp_generator.h
Go to the documentation of this file.
00001 #ifndef IRI_GRASP_ACTIONS_GUARD_INCLUDE_GRASP_GENERATOR_H
00002 #define IRI_GRASP_ACTIONS_GUARD_INCLUDE_GRASP_GENERATOR_H 1
00003 
00004 #include <tf/transform_datatypes.h>
00005 #include <iri_wam_common_msgs/bhand_cmd.h>
00006 #include <iri_wam_common_msgs/SimpleBhandPickUpAction.h>
00007 #include <geometry_msgs/Pose.h>
00008 #include <geometry_msgs/PoseStamped.h>
00009 #include <object_manipulation_msgs/GripperTranslation.h>
00010 
00011 enum GraspPhaseType
00012 {
00013     SET_FINGER_POSITION,
00014     MOVE_ARM
00015 };
00016 
00017 class GraspPhase
00018 {
00019     public:
00020         GraspPhaseType id_;
00021 
00022         GraspPhase(GraspPhaseType id) :
00023             id_(id)
00024         { }
00025 };
00026 
00027 typedef std::vector<std::string> GraspFingersConfiguration;
00028 
00029 class GraspPhaseSetFingers : public GraspPhase
00030 {
00031     public:
00032         GraspFingersConfiguration finger_config_;
00033 
00034         GraspPhaseSetFingers() :
00035             GraspPhase(SET_FINGER_POSITION)
00036         { }
00037 
00038         GraspPhaseSetFingers(GraspFingersConfiguration finger_config) :
00039             GraspPhase(SET_FINGER_POSITION),
00040             finger_config_(finger_config)
00041         { }
00042 };
00043 
00044 class GraspPhaseMoveArm : public GraspPhase
00045 {
00046     public:
00047         geometry_msgs::PoseStamped pose_;
00048 
00049         GraspPhaseMoveArm(const geometry_msgs::PoseStamped pose) :
00050             GraspPhase(MOVE_ARM),
00051             pose_(pose)
00052         { }
00053 };
00054 
00055 typedef boost::shared_ptr<GraspPhase> GraspPhasePtr;
00056 
00057 typedef std::vector<GraspPhasePtr> GraspPhaseSequence;
00058 
00059 class GraspGenerator
00060 {
00061     public:
00062         GraspGenerator()
00063         { }
00064 
00065         GraspPhaseSequence generate(iri_wam_common_msgs::SimpleBhandPickUpGoal goal)
00066         {
00067             GraspPhaseSequence cmd_list;
00068 
00069             // 0.a Convert pre-grasp in a stamped pose
00070             // 0.b Convert Lift in stamped pose
00071             geometry_msgs::PoseStamped pre_grasp_st = calculate_pre_grasp(goal.grasp_pose,
00072                                                                           goal.pre_grasp_modifier);
00073             geometry_msgs::PoseStamped lift_st      = calculate_lift(goal.grasp_pose, goal.lift);
00074 
00075             // 1. Move to pre-grasp position
00076             cmd_list.push_back(GraspPhasePtr(new
00077                                     GraspPhaseMoveArm(pre_grasp_st)));
00078             // 2. Pre-grasp finger posture
00079             cmd_list.push_back(GraspPhasePtr(new
00080                                    GraspPhaseSetFingers(goal.fingers_position_for_pre_grasp)));
00081             // 3. Move to grasp position
00082             cmd_list.push_back(GraspPhasePtr(new
00083                                     GraspPhaseMoveArm(goal.grasp_pose)));
00084             // 4. Grasp finger posture
00085             cmd_list.push_back(GraspPhasePtr(new
00086                                    GraspPhaseSetFingers(goal.fingers_position_for_grasp)));
00087             // 5. Lift movement
00088             cmd_list.push_back(GraspPhasePtr(new
00089                                    GraspPhaseMoveArm(lift_st)));
00090 
00091             return cmd_list;
00092         }
00093 
00094     private:
00095         geometry_msgs::PoseStamped calculate_pre_grasp(const geometry_msgs::PoseStamped grasp_pose,
00096                                                        const geometry_msgs::Pose pre_grasp)
00097         {
00098             geometry_msgs::PoseStamped final_pre_grasp;
00099 
00100             tf::Pose grasp_tf;
00101             tf::Pose pre_grasp_tf;
00102             tf::Pose result_tf;
00103 
00104             // 1. Get the trasnforms from both poses
00105             tf::poseMsgToTF(grasp_pose.pose, grasp_tf);
00106             tf::poseMsgToTF(pre_grasp,       pre_grasp_tf);
00107 
00108             result_tf = grasp_tf * pre_grasp_tf;
00109 
00110             // Save the info into the returning message
00111             final_pre_grasp.header = grasp_pose.header;
00112             tf::poseTFToMsg(result_tf, final_pre_grasp.pose); // will fill pose
00113 
00114             return final_pre_grasp;
00115         }
00116 
00117         geometry_msgs::PoseStamped calculate_lift(
00118                                  const geometry_msgs::PoseStamped grasp_pose,
00119                                  const object_manipulation_msgs::GripperTranslation gripper_trans)
00120         {
00121             geometry_msgs::PoseStamped result;
00122             geometry_msgs::Vector3     displacement;
00123 
00124             // Normalize the vector and apply the distance
00125             tf::Vector3 v_direction;
00126             tf::Vector3 v_displacement;
00127             tf::vector3MsgToTF(gripper_trans.direction.vector, v_direction);
00128 
00129             v_displacement =  v_direction.normalize() * gripper_trans.desired_distance;
00130             tf::vector3TFToMsg(v_displacement, displacement);
00131 
00132             result.header            = grasp_pose.header;
00133             result.pose.orientation  = grasp_pose.pose.orientation;
00134             // geometry::point can not be sum with the vector3 so ... ugly
00135             result.pose.position.x   = grasp_pose.pose.position.x + displacement.x;
00136             result.pose.position.y   = grasp_pose.pose.position.y + displacement.y;
00137             result.pose.position.z   = grasp_pose.pose.position.z + displacement.z;
00138 
00139             return result;
00140         }
00141 };
00142 
00143 
00144 #endif


iri_grasp_actions
Author(s): pmonso
autogenerated on Fri Dec 6 2013 20:14:56