manipulation_pipeline.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
37 #pragma once
38 
40 #include <boost/thread.hpp>
41 #include <boost/function.hpp>
42 #include <vector>
43 #include <deque>
44 
45 namespace pick_place
46 {
48 class ManipulationPipeline
49 {
50 public:
51  ManipulationPipeline(const std::string& name, unsigned int nthreads);
52  virtual ~ManipulationPipeline();
53 
54  const std::string& getName() const
55  {
56  return name_;
57  }
58 
59  void setSolutionCallback(const boost::function<void()>& callback)
60  {
61  solution_callback_ = callback;
62  }
63 
64  void setEmptyQueueCallback(const boost::function<void()>& callback)
65  {
66  empty_queue_callback_ = callback;
67  }
68 
69  ManipulationPipeline& addStage(const ManipulationStagePtr& next);
70  const ManipulationStagePtr& getFirstStage() const;
71  const ManipulationStagePtr& getLastStage() const;
72  void reset();
73 
74  void setVerbose(bool flag);
75 
76  void signalStop();
77  void start();
78  void stop();
79 
80  void push(const ManipulationPlanPtr& grasp);
81  void clear();
82 
83  const std::vector<ManipulationPlanPtr>& getSuccessfulManipulationPlans() const
84  {
85  return success_;
86  }
87 
88  const std::vector<ManipulationPlanPtr>& getFailedManipulationPlans() const
89  {
90  return failed_;
91  }
92 
93  void reprocessLastFailure();
94 
95 protected:
96  void processingThread(unsigned int index);
97 
98  std::string name_;
99  unsigned int nthreads_;
100  bool verbose_;
101  std::vector<ManipulationStagePtr> stages_;
102 
103  std::deque<ManipulationPlanPtr> queue_;
104  std::vector<ManipulationPlanPtr> success_;
105  std::vector<ManipulationPlanPtr> failed_;
106 
107  std::vector<boost::thread*> processing_threads_;
108  boost::condition_variable queue_access_cond_;
109  boost::mutex queue_access_lock_;
110  boost::mutex result_lock_;
111 
112  boost::function<void()> solution_callback_;
113  boost::function<void()> empty_queue_callback_;
114  unsigned int empty_queue_threads_;
115 
116  bool stop_processing_;
117 };
118 } // namespace pick_place
pick_place::ManipulationPipeline::empty_queue_callback_
boost::function< void()> empty_queue_callback_
Definition: manipulation_pipeline.h:177
pick_place::ManipulationPipeline::verbose_
bool verbose_
Definition: manipulation_pipeline.h:164
pick_place::ManipulationPipeline::processingThread
void processingThread(unsigned int index)
Definition: manipulation_pipeline.cpp:172
pick_place::ManipulationPipeline::reset
void reset()
Definition: manipulation_pipeline.cpp:114
pick_place::ManipulationPipeline::name_
std::string name_
Definition: manipulation_pipeline.h:162
pick_place
Definition: approach_and_translate_stage.h:43
pick_place::ManipulationPipeline::queue_access_cond_
boost::condition_variable queue_access_cond_
Definition: manipulation_pipeline.h:172
pick_place::ManipulationPipeline::failed_
std::vector< ManipulationPlanPtr > failed_
Definition: manipulation_pipeline.h:169
pick_place::ManipulationPipeline::clear
void clear()
Definition: manipulation_pipeline.cpp:127
pick_place::ManipulationPipeline::getSuccessfulManipulationPlans
const std::vector< ManipulationPlanPtr > & getSuccessfulManipulationPlans() const
Definition: manipulation_pipeline.h:147
pick_place::ManipulationPipeline::queue_access_lock_
boost::mutex queue_access_lock_
Definition: manipulation_pipeline.h:173
pick_place::ManipulationPipeline::stages_
std::vector< ManipulationStagePtr > stages_
Definition: manipulation_pipeline.h:165
pick_place::ManipulationPipeline::signalStop
void signalStop()
Definition: manipulation_pipeline.cpp:152
pick_place::ManipulationPipeline::result_lock_
boost::mutex result_lock_
Definition: manipulation_pipeline.h:174
pick_place::ManipulationPipeline::nthreads_
unsigned int nthreads_
Definition: manipulation_pipeline.h:163
pick_place::ManipulationPipeline::queue_
std::deque< ManipulationPlanPtr > queue_
Definition: manipulation_pipeline.h:167
pick_place::ManipulationPipeline::stop
void stop()
Definition: manipulation_pipeline.cpp:160
pick_place::ManipulationPipeline::push
void push(const ManipulationPlanPtr &grasp)
Definition: manipulation_pipeline.cpp:240
pick_place::ManipulationPipeline::setEmptyQueueCallback
void setEmptyQueueCallback(const boost::function< void()> &callback)
Definition: manipulation_pipeline.h:128
pick_place::ManipulationPipeline::success_
std::vector< ManipulationPlanPtr > success_
Definition: manipulation_pipeline.h:168
pick_place::ManipulationPipeline::~ManipulationPipeline
virtual ~ManipulationPipeline()
Definition: manipulation_pipeline.cpp:80
pick_place::ManipulationPipeline::setVerbose
void setVerbose(bool flag)
Definition: manipulation_pipeline.cpp:120
pick_place::ManipulationPipeline::getLastStage
const ManipulationStagePtr & getLastStage() const
Definition: manipulation_pipeline.cpp:103
pick_place::ManipulationPipeline::processing_threads_
std::vector< boost::thread * > processing_threads_
Definition: manipulation_pipeline.h:171
pick_place::ManipulationPipeline::getName
const std::string & getName() const
Definition: manipulation_pipeline.h:118
pick_place::ManipulationPipeline::empty_queue_threads_
unsigned int empty_queue_threads_
Definition: manipulation_pipeline.h:178
pick_place::ManipulationPipeline::ManipulationPipeline
ManipulationPipeline(const std::string &name, unsigned int nthreads)
Definition: manipulation_pipeline.cpp:74
manipulation_stage.h
pick_place::ManipulationPipeline::start
void start()
Definition: manipulation_pipeline.cpp:141
pick_place::ManipulationPipeline::setSolutionCallback
void setSolutionCallback(const boost::function< void()> &callback)
Definition: manipulation_pipeline.h:123
pick_place::ManipulationPipeline::solution_callback_
boost::function< void()> solution_callback_
Definition: manipulation_pipeline.h:176
pick_place::ManipulationPipeline::stop_processing_
bool stop_processing_
Definition: manipulation_pipeline.h:180
pick_place::ManipulationPipeline::reprocessLastFailure
void reprocessLastFailure()
Definition: manipulation_pipeline.cpp:249
pick_place::ManipulationPipeline::getFirstStage
const ManipulationStagePtr & getFirstStage() const
Definition: manipulation_pipeline.cpp:92
pick_place::ManipulationPipeline::getFailedManipulationPlans
const std::vector< ManipulationPlanPtr > & getFailedManipulationPlans() const
Definition: manipulation_pipeline.h:152
pick_place::ManipulationPipeline::addStage
ManipulationPipeline & addStage(const ManipulationStagePtr &next)
Definition: manipulation_pipeline.cpp:85


manipulation
Author(s): Ioan Sucan , Sachin Chitta
autogenerated on Fri May 3 2024 02:29:51