From 0fe18799d95dd5e7698b2ee73102ecf17ec831ce Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Wed, 20 Feb 2019 19:58:06 +0100 Subject: [PATCH] GeneratePlacePose --- .../stages/generate_place_pose.h | 61 +++++++++ core/src/stages/CMakeLists.txt | 4 +- core/src/stages/generate_place_pose.cpp | 125 ++++++++++++++++++ 3 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 core/include/moveit/task_constructor/stages/generate_place_pose.h create mode 100644 core/src/stages/generate_place_pose.cpp diff --git a/core/include/moveit/task_constructor/stages/generate_place_pose.h b/core/include/moveit/task_constructor/stages/generate_place_pose.h new file mode 100644 index 00000000..9e3ee47e --- /dev/null +++ b/core/include/moveit/task_constructor/stages/generate_place_pose.h @@ -0,0 +1,61 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2019, Bielefeld University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Bielefeld University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *********************************************************************/ + +/* Authors: Robert Haschke + Desc: Generator Stage to place an object at a certain pose +*/ + +#pragma once + +#include + +namespace moveit { namespace task_constructor { namespace stages { + +/** Simple IK pose generator to place an attached object in a specific pose + * + * The "pose" property, inherited from GeneratePose specifies the target pose + * of the grasped object. This stage transforms this pose into a target pose for the ik_frame */ +class GeneratePlacePose : public GeneratePose { +public: + GeneratePlacePose(const std::string& name = "place pose"); + + void compute() override; + + void setObject(const std::string &object) { setProperty("object", object); } + +protected: + void onNewSolution(const SolutionBase& s) override; +}; + +} } } diff --git a/core/src/stages/CMakeLists.txt b/core/src/stages/CMakeLists.txt index e52bba18..cafba117 100644 --- a/core/src/stages/CMakeLists.txt +++ b/core/src/stages/CMakeLists.txt @@ -6,6 +6,7 @@ add_library(${PROJECT_NAME}_stages ${PROJECT_INCLUDE}/stages/fixed_state.h ${PROJECT_INCLUDE}/stages/generate_pose.h ${PROJECT_INCLUDE}/stages/generate_grasp_pose.h + ${PROJECT_INCLUDE}/stages/generate_place_pose.h ${PROJECT_INCLUDE}/stages/compute_ik.h ${PROJECT_INCLUDE}/stages/predicate_filter.h @@ -21,8 +22,9 @@ add_library(${PROJECT_NAME}_stages current_state.cpp fixed_state.cpp - generate_grasp_pose.cpp generate_pose.cpp + generate_grasp_pose.cpp + generate_place_pose.cpp compute_ik.cpp predicate_filter.cpp diff --git a/core/src/stages/generate_place_pose.cpp b/core/src/stages/generate_place_pose.cpp new file mode 100644 index 00000000..23c46d74 --- /dev/null +++ b/core/src/stages/generate_place_pose.cpp @@ -0,0 +1,125 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2019, Bielefeld University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of Bielefeld University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *********************************************************************/ + +/* Authors: Robert Haschke */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace moveit { namespace task_constructor { namespace stages { + +GeneratePlacePose::GeneratePlacePose(const std::string& name) + : GeneratePose(name) +{ + auto& p = properties(); + p.declare("object"); + p.declare("ik_frame"); +} + +void GeneratePlacePose::onNewSolution(const SolutionBase& s) +{ + planning_scene::PlanningSceneConstPtr scene = s.end()->scene(); + + const auto& props = properties(); + const std::string& object = props.get("object"); + std::string msg; + if (!scene->getCurrentState().hasAttachedBody(object)) + msg = "'" + object + "' is not an attached object"; + if (scene->getCurrentState().getAttachedBody(object)->getFixedTransforms().empty()) + msg = "'" + object + "' has no associated shapes"; + if (!msg.empty()) { + if (storeFailures()) { + InterfaceState state(scene); + SubTrajectory solution; + solution.markAsFailure(); + solution.setComment(msg); + spawn(std::move(state), std::move(solution)); + } else + ROS_WARN_STREAM_NAMED("GeneratePlacePose", msg); + return; + } + + upstream_solutions_.push(&s); +} + +void GeneratePlacePose::compute() { + if (upstream_solutions_.empty()) + return; + + const SolutionBase& s = *upstream_solutions_.pop(); + planning_scene::PlanningSceneConstPtr scene = s.end()->scene()->diff(); + const moveit::core::RobotState& robot_state = scene->getCurrentState(); + const auto& props = properties(); + + const moveit::core::AttachedBody* object + = robot_state.getAttachedBody(props.get("object")); + // current object_pose w.r.t. planning frame + const Eigen::Isometry3d& object_pose = object->getGlobalCollisionBodyTransforms()[0]; + + const geometry_msgs::PoseStamped& pose_msg = props.get("pose"); + Eigen::Isometry3d target_pose; + tf::poseMsgToEigen(pose_msg.pose, target_pose); + // target pose w.r.t. planning frame + scene->getTransforms().transformPose(pose_msg.header.frame_id, target_pose, target_pose); + + const geometry_msgs::PoseStamped& ik_frame_msg = props.get("ik_frame"); + Eigen::Isometry3d ik_frame; + tf::poseMsgToEigen(ik_frame_msg.pose, ik_frame); + ik_frame = robot_state.getGlobalLinkTransform(ik_frame_msg.header.frame_id) * ik_frame; + + // target ik_frame's pose w.r.t. planning frame + geometry_msgs::PoseStamped target_pose_msg; + target_pose_msg.header.frame_id = scene->getPlanningFrame(); + tf::poseEigenToMsg(target_pose * object_pose.inverse() * ik_frame, target_pose_msg.pose); + + InterfaceState state(scene); + forwardProperties(*s.end(), state); // forward properties from inner solutions + state.properties().set("target_pose", target_pose_msg); + + SubTrajectory trajectory; + trajectory.setCost(0.0); + rviz_marker_tools::appendFrame(trajectory.markers(), target_pose_msg, 0.1, "place frame"); + + spawn(std::move(state), std::move(trajectory)); +} + +} } }