From d4dfcf962b6be76090f60a8d021ea3452052f4f5 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Mon, 4 Mar 2019 11:00:58 +0100 Subject: [PATCH] FixedCartesianPoses --- .../stages/fixed_cartesian_poses.h | 62 +++++++++++ core/src/stages/CMakeLists.txt | 2 + core/src/stages/fixed_cartesian_poses.cpp | 105 ++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 core/include/moveit/task_constructor/stages/fixed_cartesian_poses.h create mode 100644 core/src/stages/fixed_cartesian_poses.cpp diff --git a/core/include/moveit/task_constructor/stages/fixed_cartesian_poses.h b/core/include/moveit/task_constructor/stages/fixed_cartesian_poses.h new file mode 100644 index 00000000..31911feb --- /dev/null +++ b/core/include/moveit/task_constructor/stages/fixed_cartesian_poses.h @@ -0,0 +1,62 @@ +/********************************************************************* + * 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: Spawn fixed Cartesian poses +*/ + +#pragma once + +#include +#include +#include + +namespace moveit { namespace task_constructor { namespace stages { + +class FixedCartesianPoses : public MonitoringGenerator { +public: + FixedCartesianPoses(const std::string& name = "generate poses"); + + void reset() override; + bool canCompute() const override; + void compute() override; + + void addPose(const geometry_msgs::PoseStamped& pose); + +protected: + void onNewSolution(const SolutionBase& s) override; + ordered upstream_solutions_; +}; + +} } } diff --git a/core/src/stages/CMakeLists.txt b/core/src/stages/CMakeLists.txt index cafba117..c254762f 100644 --- a/core/src/stages/CMakeLists.txt +++ b/core/src/stages/CMakeLists.txt @@ -4,6 +4,7 @@ add_library(${PROJECT_NAME}_stages ${PROJECT_INCLUDE}/stages/current_state.h ${PROJECT_INCLUDE}/stages/fixed_state.h + ${PROJECT_INCLUDE}/stages/fixed_cartesian_poses.h ${PROJECT_INCLUDE}/stages/generate_pose.h ${PROJECT_INCLUDE}/stages/generate_grasp_pose.h ${PROJECT_INCLUDE}/stages/generate_place_pose.h @@ -22,6 +23,7 @@ add_library(${PROJECT_NAME}_stages current_state.cpp fixed_state.cpp + fixed_cartesian_poses.cpp generate_pose.cpp generate_grasp_pose.cpp generate_place_pose.cpp diff --git a/core/src/stages/fixed_cartesian_poses.cpp b/core/src/stages/fixed_cartesian_poses.cpp new file mode 100644 index 00000000..63b357cb --- /dev/null +++ b/core/src/stages/fixed_cartesian_poses.cpp @@ -0,0 +1,105 @@ +/********************************************************************* + * 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 + +namespace moveit { namespace task_constructor { namespace stages { + +typedef std::vector PosesList; + +FixedCartesianPoses::FixedCartesianPoses(const std::string& name) + : MonitoringGenerator(name) +{ + auto& p = properties(); + p.declare("poses", PosesList(), "target poses to spawn"); +} + +void FixedCartesianPoses::addPose(const geometry_msgs::PoseStamped& pose) +{ + moveit::task_constructor::Property& poses = properties().property("poses"); + if (!poses.defined()) + poses.setValue(PosesList({pose})); + else + boost::any_cast(poses.value()).push_back(pose); +} + +void FixedCartesianPoses::reset() +{ + upstream_solutions_.clear(); + MonitoringGenerator::reset(); +} + +void FixedCartesianPoses::onNewSolution(const SolutionBase& s) +{ + // It's safe to store a pointer to this solution, as the generating stage stores it + upstream_solutions_.push(&s); +} + +bool FixedCartesianPoses::canCompute() const { + return upstream_solutions_.size() > 0; +} + +void FixedCartesianPoses::compute() { + if (upstream_solutions_.empty()) + return; + + planning_scene::PlanningScenePtr scene = upstream_solutions_.pop()->end()->scene()->diff(); + for (geometry_msgs::PoseStamped pose : properties().get("poses")) + { + if (pose.header.frame_id.empty()) + pose.header.frame_id = scene->getPlanningFrame(); + else if (!scene->knowsFrameTransform(pose.header.frame_id)) { + ROS_WARN_NAMED("FixedCartesianPoses", "Unknown frame: '%s'", pose.header.frame_id.c_str()); + continue; + } + + InterfaceState state(scene); + state.properties().set("target_pose", pose); + + SubTrajectory trajectory; + trajectory.setCost(0.0); + + rviz_marker_tools::appendFrame(trajectory.markers(), pose, 0.1, "pose frame"); + + spawn(std::move(state), std::move(trajectory)); + } +} + +} } }