From 76c6ba14fa78f262a41ebdecc07e9fddb6aea691 Mon Sep 17 00:00:00 2001 From: v4hn Date: Fri, 23 Feb 2018 22:04:07 +0100 Subject: [PATCH] add a simple GeneratePose stage ComputeIK is a wrapper, so we can't just give it a pose to compute. --- .../task_constructor/stages/generate_pose.h | 63 +++++++++++ core/src/stages/CMakeLists.txt | 2 + core/src/stages/generate_pose.cpp | 100 ++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 core/include/moveit/task_constructor/stages/generate_pose.h create mode 100644 core/src/stages/generate_pose.cpp diff --git a/core/include/moveit/task_constructor/stages/generate_pose.h b/core/include/moveit/task_constructor/stages/generate_pose.h new file mode 100644 index 00000000..d7893639 --- /dev/null +++ b/core/include/moveit/task_constructor/stages/generate_pose.h @@ -0,0 +1,63 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2018, Hamburg 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: Michael Goerner + Desc: Generator Stage for poses +*/ + +#pragma once + +#include +#include + +namespace moveit { namespace task_constructor { namespace stages { + +class GeneratePose : public MonitoringGenerator { +public: + GeneratePose(const std::string& name); + + bool canCompute() const override; + bool compute() override; + + void setPose(const geometry_msgs::PoseStamped pose){ + setProperty("pose", std::move(pose)); + } + +protected: + void onNewSolution(const SolutionBase& s) override; + + std::deque scenes_; +}; + +} } } diff --git a/core/src/stages/CMakeLists.txt b/core/src/stages/CMakeLists.txt index 03959900..1949a14c 100644 --- a/core/src/stages/CMakeLists.txt +++ b/core/src/stages/CMakeLists.txt @@ -5,6 +5,7 @@ add_library(${PROJECT_NAME}_stages ${PROJECT_INCLUDE}/stages/current_state.h ${PROJECT_INCLUDE}/stages/fixed_state.h ${PROJECT_INCLUDE}/stages/generate_grasp_pose.h + ${PROJECT_INCLUDE}/stages/generate_pose.h ${PROJECT_INCLUDE}/stages/compute_ik.h ${PROJECT_INCLUDE}/stages/connect.h @@ -24,6 +25,7 @@ add_library(${PROJECT_NAME}_stages current_state.cpp fixed_state.cpp generate_grasp_pose.cpp + generate_pose.cpp compute_ik.cpp connect.cpp diff --git a/core/src/stages/generate_pose.cpp b/core/src/stages/generate_pose.cpp new file mode 100644 index 00000000..d54eef54 --- /dev/null +++ b/core/src/stages/generate_pose.cpp @@ -0,0 +1,100 @@ +/********************************************************************* + * Software License Agreement (BSD License) + * + * Copyright (c) 2017, Bielefeld + Hamburg 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, Michael Goerner */ + +#include +#include +#include +#include + +#include + +#include +#include + +namespace moveit { namespace task_constructor { namespace stages { + +GeneratePose::GeneratePose(const std::string& name) + : MonitoringGenerator(name) +{ + auto& p = properties(); + p.declare("pose", "target pose to pass on in spawned states"); +} + +void GeneratePose::onNewSolution(const SolutionBase& s) +{ + scenes_.push_back(s.end()->scene()->diff()); +} + +bool GeneratePose::canCompute() const { + return scenes_.size() > 0; +} + +bool GeneratePose::compute(){ + const auto& props = properties(); + + geometry_msgs::PoseStamped target_pose = props.get("pose"); + + if(scenes_.empty()) throw std::runtime_error("GeneratePose called without checking canCompute."); + + planning_scene::PlanningSceneConstPtr scene = scenes_[0]; + scenes_.pop_front(); + + // take care of frame transforms + const std::string& frame = target_pose.header.frame_id; + if( !frame.empty() && frame != scene->getPlanningFrame() ){ + if ( !scene->knowsFrameTransform(frame) ) + throw std::runtime_error("GeneratePose does not know frame '" + frame + "'"); + + Eigen::Affine3d pose; + tf::poseMsgToEigen(target_pose.pose, pose); + pose = scene->getFrameTransform(target_pose.header.frame_id) * pose; + tf::poseEigenToMsg(pose, target_pose.pose); + target_pose.header.frame_id = scene->getPlanningFrame(); + } + + InterfaceState state(scene); + state.properties().set("target_pose", target_pose); + + SubTrajectory trajectory; + trajectory.setCost(0.0); + + rviz_marker_tools::appendFrame(trajectory.markers(), target_pose, 0.1, "pose frame"); + + spawn(std::move(state), std::move(trajectory)); + return true; +} + +} } }