Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <moveit/move_group_interface/move_group.h>
00019
00020 #include "romeo_moveit_actions/postures.hpp"
00021
00022 namespace moveit_simple_actions
00023 {
00024 Posture::Posture(const std::string robot_name,
00025 const std::string eef_name,
00026 const std::string group_name)
00027 {
00028
00029 moveit::planning_interface::MoveGroup move_group_head("head");
00030
00031 move_group_head.getCurrentState()->copyJointGroupPositions(move_group_head.getCurrentState()->getRobotModel()->getJointModelGroup(move_group_head.getName()), pose_head_down_);
00032 if (pose_head_down_.size() > 1)
00033 if (robot_name == "nao")
00034 pose_head_down_[1] = 0.3;
00035 else
00036 pose_head_down_[1] = 0.35;
00037 pose_head_zero_.resize(pose_head_down_.size(), 0.0);
00038
00039
00040 moveit::planning_interface::MoveGroup move_group_plan(group_name);
00041 std::vector<double> pose_arm_init;
00042 move_group_plan.getCurrentState()->copyJointGroupPositions(
00043 move_group_plan.getCurrentState()->getRobotModel()->getJointModelGroup(
00044 move_group_plan.getName()), pose_arm_init);
00045
00046
00047 pose_arm_.resize(5);
00048 pose_arm_[0] = std::vector<double>(pose_arm_init);
00049 for (int i=1; i<pose_arm_.size(); ++i)
00050 pose_arm_[i].resize(pose_arm_[0].size(), 0.0);
00051 if (pose_arm_[0].size() >= 5)
00052 {
00053
00054 pose_arm_[0].assign(pose_arm_[0].size(), 0.0);
00055
00056
00057 pose_arm_[1][0] = 1.56;
00058 pose_arm_[1][1] = 0.14;
00059 pose_arm_[1][2] = -1.22;
00060 pose_arm_[1][3] = -0.52;
00061 pose_arm_[1][4] = -0.02;
00062 if (pose_arm_[1].size() >= 6)
00063 {
00064 if (robot_name == "romeo")
00065 pose_arm_[1][5] = 0.17;
00066 else
00067 pose_arm_[1][5] = 0.02;
00068 }
00069
00070
00071 pose_arm_[2][0] = 1.74;
00072 pose_arm_[2][1] = 0.75;
00073 pose_arm_[2][2] = -2.08;
00074 pose_arm_[2][3] = -1.15;
00075 pose_arm_[2][4] = -0.43;
00076 if (pose_arm_[2].size() >= 6)
00077 {
00078 if (robot_name == "romeo")
00079 pose_arm_[2][5] = 0.17;
00080 else
00081 pose_arm_[1][5] = 0.02;
00082 }
00083
00084
00085 pose_arm_[3][0] = 1.08;
00086 pose_arm_[3][1] = 0.66;
00087 pose_arm_[3][2] = -0.84;
00088 pose_arm_[3][3] = -0.61;
00089 pose_arm_[3][4] = -0.67;
00090 if (pose_arm_[3].size() >= 6)
00091 {
00092 if (robot_name == "romeo")
00093 pose_arm_[3][5] = 0.025;
00094 else
00095 pose_arm_[1][5] = 0.02;
00096 }
00097
00098
00099 pose_arm_[4][0] = 1.87;
00100 pose_arm_[4][1] = 0.56;
00101 pose_arm_[4][2] = -1.99;
00102 pose_arm_[4][3] = -1.05;
00103 pose_arm_[4][4] = -0.67;
00104 if (pose_arm_[4].size() >= 6)
00105 pose_arm_[4][5] = 0.02;
00106 }
00107
00108
00109 if (group_name.find("right") != std::string::npos)
00110 for (int i=0; i<pose_arm_.size(); ++i)
00111 {
00112 if (pose_arm_[i].size() >= 3)
00113 {
00114 pose_arm_[i][1] *= -1;
00115 pose_arm_[i][2] *= -1;
00116 }
00117 if (pose_arm_[i].size() >= 5)
00118 {
00119 pose_arm_[i][3] *= -1;
00120 if (robot_name != "pepper")
00121 pose_arm_[i][4] *= -1;
00122 }
00123 }
00124
00125
00126 std::vector<double> pose_hand;
00127 moveit::planning_interface::MoveGroup move_group_eef(eef_name);
00128 move_group_eef.getCurrentState()->copyJointGroupPositions(move_group_eef.getCurrentState()->getRobotModel()->getJointModelGroup(move_group_eef.getName()), pose_hand);
00129 pose_hand_.resize(2);
00130 pose_hand_[0].resize(pose_hand.size(), 0.0);
00131 pose_hand_[1].resize(pose_hand.size(), 0.8);
00132 }
00133
00134 void Posture::initHandPose(const double &value, const int &pose)
00135 {
00136 if (pose <= pose_hand_.size())
00137 {
00138 pose_hand_[pose].assign(pose_hand_[pose].size(), value);
00139 if (pose_hand_[pose].size() > 0)
00140 pose_hand_[pose][0] = 0.0;
00141 }
00142 }
00143
00144 bool Posture::poseHeadZero()
00145 {
00146 goToPose("head", &pose_head_zero_);
00147 }
00148
00149 bool Posture::poseHeadDown()
00150 {
00151 goToPose("head", &pose_head_down_);
00152 }
00153
00154 bool Posture::poseHand(const std::string &end_eff,
00155 const std::string &group,
00156 const int &pose_id)
00157 {
00158
00159 goToPose(end_eff, &pose_hand_[0]);
00160 bool res = false;
00161 if (pose_id < pose_arm_.size())
00162 res = goToPose(group, &pose_arm_[pose_id]);
00163 return res;
00164 }
00165
00166 bool Posture::poseHandOpen(const std::string &end_eff)
00167 {
00168 goToPose(end_eff, &pose_hand_[0]);
00169 }
00170
00171 bool Posture::poseHandClose(const std::string &end_eff)
00172 {
00173 goToPose(end_eff, &pose_hand_[1]);
00174 }
00175
00176 bool Posture::goToPose(const std::string group_name,
00177 std::vector<double> *pose)
00178 {
00179 moveit::planning_interface::MoveGroup move_group(group_name);
00180
00181
00182 std::vector<double> joints;
00183 move_group.getCurrentState()->copyJointGroupPositions(
00184 move_group.getCurrentState()->getRobotModel()->
00185 getJointModelGroup(move_group.getName()), joints);
00186
00187
00188 if (joints.size() == pose->size())
00189 {
00190
00191 move_group.setJointValueTarget(*pose);
00192
00193 moveit::planning_interface::MoveGroup::Plan plan;
00194 bool success = move_group.plan(plan);
00195 sleep(1.0);
00196 if (success)
00197 {
00198 ROS_INFO("Action with the move_group %s", success?"":"FAILED");
00199 move_group.move();
00200 sleep(1.0);
00201
00202
00203
00204
00205
00206
00207 }
00208 return success;
00209 }
00210 else
00211 ROS_INFO_STREAM("Posture: Joint size is wrong for " << group_name
00212 << ": " << joints.size() << " != " << pose->size());
00213 return false;
00214 }
00215 }