22 int main(
int argc,
char **argv)
24 ros::init(argc, argv,
"move_base_to_manip");
40 as_(nh_,
"move_base_to_manip",
boost::bind(&
base_planner::do_motion_CB, this, _1), false)
56 ROS_INFO(
"[move_base_to_manip] Received a new goal. Moving.");
59 std::string move_group_name;
60 nh_.
getParam(
"/move_base_to_manip/move_group_name", move_group_name);
64 geometry_msgs::PoseStamped start_pose = move_group.
getCurrentPose();
67 std::string base_frame_name;
68 nh_.
getParam(
"/move_base_to_manip/base_frame_name", base_frame_name);
69 move_base_to_manip::desired_poseResult result;
70 if (goal->desired_pose.header.frame_id != base_frame_name)
72 result.success =
false;
74 ROS_WARN_STREAM(
"The target pose should be given in " << base_frame_name);
79 geometry_msgs::PoseStamped desired_height_orient = goal->desired_pose;
80 desired_height_orient.pose.position.x = start_pose.pose.position.x;
81 desired_height_orient.pose.position.y = start_pose.pose.position.y;
86 ROS_INFO_STREAM(
"[move_base_to_manip] Moving to the desired height and orientation.");
92 double object_roll, object_pitch, object_yaw;
99 nh_.
getParam(
"/move_base_to_manip/ok_to_flip", ok_to_flip);
100 if ( !move_group.
plan(move_plan) && ok_to_flip )
103 desired_height_orient.pose.orientation = gripper_quat_msg;
105 if ( !move_group.
plan(move_plan) )
108 desired_height_orient.pose.orientation = gripper_quat_msg;
110 if( !move_group.
plan(move_plan) )
112 ROS_ERROR(
"Failed to reach the desired height and orientation.");
113 ROS_ERROR(
"Try starting from an arm position with better manipulability.");
120 bool prompt_before_motion;
121 nh_.
getParam(
"/move_base_to_manip/prompt_before_motion", prompt_before_motion);
122 if ( prompt_before_motion )
127 std::cin.get(character);
128 if ( character !=
'c' )
138 geometry_msgs::Vector3 vec_from_cur_pose_to_goal;
139 vec_from_cur_pose_to_goal.x = goal->desired_pose.pose.position.x - start_pose.pose.position.x;
140 vec_from_cur_pose_to_goal.y = goal->desired_pose.pose.position.y - start_pose.pose.position.y;
141 vec_from_cur_pose_to_goal.z = 0.;
149 std::vector<geometry_msgs::Pose> waypoints;
150 geometry_msgs::Pose cartesian_target_pose;
151 cartesian_target_pose.position = goal->desired_pose.pose.position;
152 cartesian_target_pose.orientation = goal->desired_pose.pose.orientation;
153 waypoints.push_back(cartesian_target_pose);
157 PLAN_CARTESIAN_AGAIN:
159 ROS_INFO(
"Cartesian path: %.2f%% achieved", fraction * 100.);
161 if ( prompt_before_motion )
165 std::cin.ignore (INT_MAX,
'\n');
166 std::cin.get(character);
167 if ( character !=
'c' )
168 goto PLAN_CARTESIAN_AGAIN;
172 if ( ( 0.999 < fraction) && (fraction < 1.001) )
177 nh_.
getParam(
"/move_base_to_manip/move_cartesian", move_cartesian);
178 if ( move_cartesian )
183 move_group.
plan(move_plan);
188 result.success =
true;
202 ROS_INFO(
"Waiting for the move_base action server to come up");
205 move_base_msgs::MoveBaseGoal goal;
206 goal.target_pose.header.frame_id = base_frame_name;
211 geometry_msgs::PoseStamped currentPose = move_group.
getCurrentPose();
214 double motion_buffer;
215 nh_.
getParam(
"/move_base_to_manip/motion_buffer", motion_buffer);
216 goal.target_pose.pose.position.x = (1-motion_buffer*fraction)*vec_from_cur_pose_to_goal.x;
217 goal.target_pose.pose.position.y = (1-motion_buffer*fraction)*vec_from_cur_pose_to_goal.y;
218 goal.target_pose.pose.position.z = 0.;
220 goal.target_pose.pose.orientation.x = 0.;
221 goal.target_pose.pose.orientation.y = 0.;
222 goal.target_pose.pose.orientation.z = 0.;
223 goal.target_pose.pose.orientation.w = 1.;
227 if (
nh_.
getParam(
"/move_base_to_manip/clear_costmaps", clear_costmaps) )
235 result.success =
true;
249 if (
nh_.
getParam(
"/move_base_to_manip/clear_octomap", clear_octomap) )
253 double cartesian_path_resolution;
254 nh_.
getParam(
"/move_base_to_manip/cartesian_plan_res", cartesian_path_resolution);
255 double fraction = move_group.
computeCartesianPath( waypoints, cartesian_path_resolution, 0.0, trajectory);
269 if (!
nh_.
hasParam(
"/move_base_to_manip/motion_buffer"))
270 nh_.
setParam(
"/move_base_to_manip/motion_buffer", 0.15);
273 if (!
nh_.
hasParam(
"/move_base_to_manip/move_cartesian"))
275 nh_.
setParam(
"/move_base_to_manip/move_cartesian",
false);
279 if (!
nh_.
hasParam(
"/move_base_to_manip/clear_octomap"))
281 nh_.
setParam(
"/move_base_to_manip/clear_octomap",
false);
285 if (!
nh_.
hasParam(
"/move_base_to_manip/clear_costmaps"))
287 nh_.
setParam(
"/move_base_to_manip/clear_costmaps",
false);
291 if (!
nh_.
hasParam(
"/move_base_to_manip/prompt_before_motion"))
293 nh_.
setParam(
"/move_base_to_manip/prompt_before_motion",
true);
297 if (!
nh_.
hasParam(
"/move_base_to_manip/cartesian_plan_res"))
298 nh_.
setParam(
"/move_base_to_manip/cartesian_plan_res", 0.005);
300 if (!
nh_.
hasParam(
"/move_base_to_manip/move_group_name"))
301 nh_.
setParam(
"/move_base_to_manip/move_group_name",
"right_ur5");
303 if (!
nh_.
hasParam(
"/move_base_to_manip/move_group_planner"))
304 nh_.
setParam(
"/move_base_to_manip/move_group_planner",
"RRTConnectkConfigDefault");
306 if (!
nh_.
hasParam(
"/move_base_to_manip/velocity_scale"))
307 nh_.
setParam(
"/move_base_to_manip/velocity_scale", 0.1);
309 if (!
nh_.
hasParam(
"/move_base_to_manip/base_frame_name"))
310 nh_.
setParam(
"/move_base_to_manip/base_frame_name",
"base_link");
312 if (!
nh_.
hasParam(
"/move_base_to_manip/position_tolerance"))
313 nh_.
setParam(
"/move_base_to_manip/position_tolerance", 0.01);
315 if (!
nh_.
hasParam(
"/move_base_to_manip/orientation_tolerance"))
316 nh_.
setParam(
"/move_base_to_manip/orientation_tolerance", 0.01);
319 if (!
nh_.
hasParam(
"/move_base_to_manip/ok_to_flip"))
321 nh_.
setParam(
"/move_base_to_manip/ok_to_flip",
true);
bool waitForServer(const ros::Duration &timeout=ros::Duration(0, 0)) const
bool call(const std::string &service_name, MReq &req, MRes &res)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
actionlib::SimpleActionServer< move_base_to_manip::desired_poseAction > as_
double computeCartesianPath(const std::vector< geometry_msgs::Pose > &waypoints, double eef_step, double jump_threshold, moveit_msgs::RobotTrajectory &trajectory, bool avoid_collisions=true, moveit_msgs::MoveItErrorCodes *error_code=NULL)
bool setPoseTarget(const Eigen::Affine3d &end_effector_pose, const std::string &end_effector_link="")
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
ROSCPP_DECL void spin(Spinner &spinner)
ros::ServiceClient clear_octomap_client_
std_srvs::Empty empty_srv_
const double cartesian_motion(const std::vector< geometry_msgs::Pose > &waypoints, moveit_msgs::RobotTrajectory &trajectory, moveit::planning_interface::MoveGroupInterface &moveGroup)
static void quaternionMsgToTF(const geometry_msgs::Quaternion &msg, Quaternion &bt)
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
robot_trajectory::RobotTrajectory trajectory(rmodel,"right_arm")
int main(int argc, char **argv)
geometry_msgs::PoseStamped getCurrentPose(const std::string &end_effector_link="")
MoveItErrorCode execute(const Plan &plan)
MoveItErrorCode plan(Plan &plan)
#define ROS_WARN_STREAM(args)
ros::ServiceClient clear_costmaps_client_
void sendGoal(const Goal &goal, SimpleDoneCallback done_cb=SimpleDoneCallback(), SimpleActiveCallback active_cb=SimpleActiveCallback(), SimpleFeedbackCallback feedback_cb=SimpleFeedbackCallback())
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
static geometry_msgs::Quaternion createQuaternionMsgFromRollPitchYaw(double roll, double pitch, double yaw)
void do_motion_CB(const move_base_to_manip::desired_poseGoalConstPtr &goal)
ROSCPP_DECL void shutdown()
bool hasParam(const std::string &key) const
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const