hpp-python  6.1.0
python bindings for HPP, based on boost python
graph.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2025, CNRS
3 // Authors: Florent Lamiraux, Paul Sardin
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions
7 // are met:
8 
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 
12 // 2. Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 // OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #ifndef PYHPP_GRAPH_HH
31 #define PYHPP_GRAPH_HH
32 
35 
36 namespace pyhpp {
37 namespace manipulation {
38 
54 
57  bool success;
60 
62  ConstraintResult(bool s, const Configuration_t& config, value_type err)
63  : success(s), configuration(config), error(err) {}
64 };
65 
67 struct PyWState {
69  PyWState(const StatePtr_t& object);
70  std::string name() const;
71 };
72 typedef std::shared_ptr<PyWState> PyWStatePtr_t;
73 
75 struct PyWEdge {
77  PyWEdge(const EdgePtr_t& object);
78  std::string name() const;
79 };
80 typedef std::shared_ptr<PyWEdge> PyWEdgePtr_t;
81 
83 struct PyWGraph {
86 
87  std::map<std::string, std::size_t> id;
88 
89  // Member variables
93 
95 
96  // Constructors
97  PyWGraph(const GraphPtr_t& object);
98  PyWGraph(const std::string& name, const PyWDevicePtr_t& d,
99  const PyWProblemPtr_t& problem);
100 
101  // Configuration methods
102  void maxIterations(size_type iterations);
103  size_type maxIterations() const;
104  void errorThreshold(const value_type& threshold);
105  value_type errorThreshold() const;
106 
107  // Graph construction
108  PyWStatePtr_t createState(const std::string& nodeName, bool waypoint,
109  int priority);
111  const std::string& transitionName, int w,
112  PyWStatePtr_t isInState);
114  PyWStatePtr_t nodeTo,
115  const std::string& edgeName, int nb,
116  int w, PyWStatePtr_t isInState,
117  bool automaticBuilder);
119  PyWStatePtr_t nodeTo,
120  const std::string& edgeName, int w,
121  PyWStatePtr_t isInState);
122 
123  // Edge/State management
125  std::string getContainingNode(PyWEdgePtr_t edge);
126  void setShort(PyWEdgePtr_t edge, bool isShort);
127  bool isShort(PyWEdgePtr_t edge);
128  void getNodesConnectedByTransition(PyWEdgePtr_t edge, std::string& nodeFrom,
129  std::string& nodeTo);
130  void setWeight(PyWEdgePtr_t edge, int weight);
131  size_t getWeight(PyWEdgePtr_t edge);
132  void setWaypoint(PyWEdgePtr_t waypointEdge, int index, PyWEdgePtr_t edge,
133  PyWStatePtr_t state);
135  const boost::python::list& py_constraints);
136  PyWEdgePtr_t getTransition(const std::string& edgeName);
137  PyWStatePtr_t getState(const std::string& stateName);
138 
139  boost::python::list getTransitions();
140  boost::python::list getStates();
141  boost::python::list getTransitionNames();
142  boost::python::list getStateNames();
143 
144  // State queries
145  std::string getStateFromConfiguration(ConfigurationIn_t input);
146 
147  // Constraint management
149  const ImplicitPtr_t& constraint);
151  PyWStatePtr_t component, const boost::python::list& py_constraints);
153  PyWEdgePtr_t component, const boost::python::list& py_constraints);
155  PyWStatePtr_t component, const boost::python::list& py_constraints);
156  void resetConstraints(PyWStatePtr_t component);
157  void registerConstraints(const ImplicitPtr_t& constraint,
158  const ImplicitPtr_t& complement,
159  const ImplicitPtr_t& both);
160 
162  const std::string& name, const boost::python::list& py_surface1,
163  const boost::python::list& py_surface2, const value_type& margin);
165  const std::string& name, const boost::python::list& py_surface1,
166  const boost::python::list& py_surface2, const value_type& width,
167  const value_type& margin);
169  const std::string& name, const boost::python::list& py_surface1,
170  const boost::python::list& py_surface2, const value_type& margin);
172  const std::string& name, const boost::python::list& py_surface1,
173  const boost::python::list& py_surface2);
175  const std::string& name, const boost::python::list& py_surface1,
176  const boost::python::list& py_surface2, const value_type& width,
177  const value_type& margin);
179  const std::string& name, const boost::python::list& py_surface1,
180  const boost::python::list& py_surface2, const value_type& width);
181 
182  boost::python::list createGraspConstraint(const std::string& name,
183  const std::string& gripper,
184  const std::string& handle);
185  ImplicitPtr_t createPreGraspConstraint(const std::string& name,
186  const std::string& gripper,
187  const std::string& handle);
188  boost::python::list getNumericalConstraintsForState(PyWStatePtr_t component);
189  boost::python::list getNumericalConstraintsForEdge(PyWEdgePtr_t component);
190  boost::python::list getNumericalConstraintsForGraph();
191 
192  // Configuration error checking
194  ConfigurationIn_t input);
196  ConfigurationIn_t input);
198  const PyWEdgePtr_t& edge, ConfigurationIn_t leafConfig,
199  ConfigurationIn_t config) const;
201  const PyWEdgePtr_t& edge, ConfigurationIn_t leafConfig,
202  ConfigurationIn_t config) const;
203 
204  // Constraint application
206  ConfigurationIn_t input);
208  ConfigurationIn_t q_rhs,
209  ConfigurationIn_t input);
211  ConfigurationIn_t q_rhs,
212  ConfigurationIn_t input);
213 
214  // Level set edges
216  const boost::python::list& condNC,
217  const boost::python::list& paramNC);
218 
219  // Security margins and collision
220  boost::python::list getSecurityMarginMatrixForTransition(PyWEdgePtr_t edge);
221  void setSecurityMarginForTransition(PyWEdgePtr_t edge, const char* joint1,
222  const char* joint2, double margin);
223  boost::python::list getRelativeMotionMatrix(PyWEdgePtr_t edge);
224  void removeCollisionPairFromTransition(PyWEdgePtr_t edge, const char* joint1,
225  const char* joint2);
226 
227  // Subgraph management
228  void createSubGraph(const char* subgraphName,
229  hpp::core::RoadmapPtr_t roadmap);
230  void setTargetNodeList(const boost::python::list& nodes);
231 
232  // Display and debugging
233  std::string displayStateConstraints(PyWStatePtr_t state);
234  std::string displayTransitionConstraints(PyWEdgePtr_t edge);
236  void display(const char* filename);
237 
238  // Initialization
239  void initialize();
240 };
241 
242 } // namespace manipulation
243 } // namespace pyhpp
244 #endif // PYHPP_GRAPH_HH
std::vector< ConstraintAndComplement_t > ConstraintsAndComplements_t
shared_ptr< Implicit > ImplicitPtr_t
std::vector< constraints::ImplicitPtr_t > NumericalConstraints_t
pinocchio::value_type value_type
shared_ptr< Roadmap > RoadmapPtr_t
pinocchio::ConfigurationIn_t ConfigurationIn_t
pinocchio::size_type size_type
pinocchio::Configuration_t Configuration_t
shared_ptr< Edge > EdgePtr_t
shared_ptr< State > StatePtr_t
shared_ptr< GraphComponent > GraphComponentPtr_t
shared_ptr< Graph > GraphPtr_t
shared_ptr< Problem > ProblemPtr_t
pinocchio::Configuration_t Configuration_t
core::size_type size_type
core::value_type value_type
pinocchio::ConfigurationIn_t ConfigurationIn_t
boost::python::tuple tuple
Definition: path-planner.hh:39
hpp::manipulation::graph::StatePtr_t StatePtr_t
Definition: graph.hh:49
std::shared_ptr< Device > PyWDevicePtr_t
Definition: fwd.hh:42
hpp::manipulation::ConstraintsAndComplements_t ConstraintsAndComplements_t
Definition: graph.hh:52
std::shared_ptr< PyWEdge > PyWEdgePtr_t
Definition: graph.hh:80
hpp::manipulation::ProblemPtr_t ProblemPtr_t
Definition: graph.hh:45
hpp::manipulation::graph::State State
Definition: graph.hh:48
hpp::manipulation::graph::Edge Edge
Definition: graph.hh:46
hpp::pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: device.hh:55
hpp::manipulation::graph::EdgePtr_t EdgePtr_t
Definition: graph.hh:47
hpp::manipulation::ConstraintAndComplement_t ConstraintAndComplement_t
Definition: graph.hh:53
hpp::manipulation::graph::GraphComponentPtr_t GraphComponentPtr_t
Definition: graph.hh:44
std::shared_ptr< PyWState > PyWStatePtr_t
Definition: graph.hh:72
hpp::manipulation::graph::GraphComponent GraphComponent
Definition: graph.hh:43
std::shared_ptr< Problem > PyWProblemPtr_t
Definition: fwd.hh:46
hpp::pinocchio::Configuration_t Configuration_t
Definition: device.hh:54
hpp::manipulation::graph::GraphPtr_t GraphPtr_t
Definition: graph.hh:50
hpp::pinocchio::value_type value_type
Definition: device.hh:57
hpp::pinocchio::size_type size_type
Definition: device.hh:56
Definition: fwd.hh:35
Result structure for constraint operations.
Definition: graph.hh:56
Configuration_t configuration
Definition: graph.hh:58
ConstraintResult()
Definition: graph.hh:61
bool success
Definition: graph.hh:57
ConstraintResult(bool s, const Configuration_t &config, value_type err)
Definition: graph.hh:62
value_type error
Definition: graph.hh:59
Python wrapper for Edge.
Definition: graph.hh:75
PyWEdge(const EdgePtr_t &object)
Definition: graph.cc:259
std::string name() const
Definition: graph.cc:260
EdgePtr_t obj
Definition: graph.hh:76
Python wrapper for Graph.
Definition: graph.hh:83
boost::python::tuple getConfigErrorForTransitionLeaf(const PyWEdgePtr_t &edge, ConfigurationIn_t leafConfig, ConfigurationIn_t config) const
Definition: graph.cc:710
void getNodesConnectedByTransition(PyWEdgePtr_t edge, std::string &nodeFrom, std::string &nodeTo)
Definition: graph.cc:409
void setShort(PyWEdgePtr_t edge, bool isShort)
Definition: graph.cc:393
ConstraintResult generateTargetConfig(PyWEdgePtr_t transition, ConfigurationIn_t q_rhs, ConfigurationIn_t input)
Definition: graph.cc:764
size_t getWeight(PyWEdgePtr_t edge)
Definition: graph.cc:428
boost::python::list getRelativeMotionMatrix(PyWEdgePtr_t edge)
Definition: graph.cc:850
ConstraintResult applyLeafConstraints(PyWEdgePtr_t transition, ConfigurationIn_t q_rhs, ConfigurationIn_t input)
Definition: graph.cc:747
void initialize()
Definition: graph.cc:989
boost::python::list getStates()
Definition: graph.cc:512
ConstraintsAndComplements_t constraintsAndComplements
Definition: graph.hh:94
PyWGraph(const GraphPtr_t &object)
Definition: graph.cc:262
boost::python::tuple getConfigErrorForTransitionTarget(const PyWEdgePtr_t &edge, ConfigurationIn_t leafConfig, ConfigurationIn_t config) const
Definition: graph.cc:719
boost::python::tuple getConfigErrorForTransition(PyWEdgePtr_t edge, ConfigurationIn_t input)
Definition: graph.cc:691
ImplicitPtr_t createPreGraspConstraint(const std::string &name, const std::string &gripper, const std::string &handle)
Definition: graph.cc:1189
ImplicitPtr_t createPrePlacementConstraint(const std::string &name, const boost::python::list &py_surface1, const boost::python::list &py_surface2, const value_type &width, const value_type &margin)
Definition: graph.cc:1108
void setContainingNode(PyWEdgePtr_t edge, PyWStatePtr_t node)
Definition: graph.cc:377
boost::python::tuple createPlacementConstraint1(const std::string &name, const boost::python::list &py_surface1, const boost::python::list &py_surface2, const value_type &margin)
Definition: graph.cc:1097
ConstraintResult applyStateConstraints(PyWStatePtr_t state, ConfigurationIn_t input)
Definition: graph.cc:732
PyWProblemPtr_t problem
Definition: graph.hh:92
boost::python::list getNumericalConstraintsForEdge(PyWEdgePtr_t component)
Definition: graph.cc:653
ImplicitPtr_t createPrePlacementConstraint1(const std::string &name, const boost::python::list &py_surface1, const boost::python::list &py_surface2, const value_type &width, const value_type &margin)
Definition: graph.cc:1151
boost::python::list getNumericalConstraintsForGraph()
Definition: graph.cc:657
PyWEdgePtr_t createLevelSetTransition(PyWStatePtr_t nodeFrom, PyWStatePtr_t nodeTo, const std::string &edgeName, int w, PyWStatePtr_t isInState)
Definition: graph.cc:356
ImplicitPtr_t createPrePlacementConstraint2(const std::string &name, const boost::python::list &py_surface1, const boost::python::list &py_surface2, const value_type &width)
Definition: graph.cc:1158
size_type maxIterations() const
Definition: graph.cc:280
void display(const char *filename)
Definition: graph.cc:974
bool isShort(PyWEdgePtr_t edge)
Definition: graph.cc:401
PyWEdgePtr_t getTransition(const std::string &edgeName)
Definition: graph.cc:461
GraphPtr_t obj
Definition: graph.hh:90
void setWaypoint(PyWEdgePtr_t waypointEdge, int index, PyWEdgePtr_t edge, PyWStatePtr_t state)
Definition: graph.cc:436
boost::python::tuple createPlacementConstraint(const std::string &name, const boost::python::list &py_surface1, const boost::python::list &py_surface2, const value_type &margin)
Definition: graph.cc:1007
void removeCollisionPairFromTransition(PyWEdgePtr_t edge, const char *joint1, const char *joint2)
Definition: graph.cc:876
boost::python::list getNumericalConstraintsForState(PyWStatePtr_t component)
Definition: graph.cc:649
boost::python::list getStateNames()
Definition: graph.cc:546
void addLevelSetFoliation(PyWEdgePtr_t edge, const boost::python::list &condNC, const boost::python::list &paramNC)
Definition: graph.cc:788
hpp::constraints::NumericalConstraints_t NumericalConstraints_t
Definition: graph.hh:85
void resetConstraints(PyWStatePtr_t component)
Definition: graph.cc:661
void createSubGraph(const char *subgraphName, hpp::core::RoadmapPtr_t roadmap)
Definition: graph.cc:901
PyWStatePtr_t createState(const std::string &nodeName, bool waypoint, int priority)
Definition: graph.cc:292
PyWEdgePtr_t createTransition(PyWStatePtr_t nodeFrom, PyWStatePtr_t nodeTo, const std::string &transitionName, int w, PyWStatePtr_t isInState)
Definition: graph.cc:304
value_type errorThreshold() const
Definition: graph.cc:286
boost::python::list createGraspConstraint(const std::string &name, const std::string &gripper, const std::string &handle)
Definition: graph.cc:1164
void addNumericalConstraintsForPath(PyWStatePtr_t component, const boost::python::list &py_constraints)
Definition: graph.cc:633
std::string getContainingNode(PyWEdgePtr_t edge)
Definition: graph.cc:385
PyWEdgePtr_t createWaypointTransition(PyWStatePtr_t nodeFrom, PyWStatePtr_t nodeTo, const std::string &edgeName, int nb, int w, PyWStatePtr_t isInState, bool automaticBuilder)
Definition: graph.cc:317
void setSecurityMarginForTransition(PyWEdgePtr_t edge, const char *joint1, const char *joint2, double margin)
Definition: graph.cc:832
std::string displayStateConstraints(PyWStatePtr_t state)
Definition: graph.cc:938
boost::python::list getTransitionNames()
Definition: graph.cc:529
boost::python::tuple getConfigErrorForState(PyWStatePtr_t component, ConfigurationIn_t input)
Definition: graph.cc:680
boost::python::list getSecurityMarginMatrixForTransition(PyWEdgePtr_t edge)
Definition: graph.cc:816
std::map< std::string, std::size_t > id
Definition: graph.hh:87
void setTargetNodeList(const boost::python::list &nodes)
Definition: graph.cc:913
std::string displayTransitionTargetConstraints(PyWEdgePtr_t edge)
Definition: graph.cc:962
void addNumericalConstraintsToTransition(PyWEdgePtr_t component, const boost::python::list &py_constraints)
Definition: graph.cc:601
hpp::constraints::ImplicitPtr_t ImplicitPtr_t
Definition: graph.hh:84
void addNumericalConstraintsToGraph(const boost::python::list &py_constraints)
Definition: graph.cc:617
std::string getStateFromConfiguration(ConfigurationIn_t input)
Definition: graph.cc:567
boost::python::tuple createPlacementConstraint2(const std::string &name, const boost::python::list &py_surface1, const boost::python::list &py_surface2)
Definition: graph.cc:1102
void addNumericalConstraint(PyWStatePtr_t node, const ImplicitPtr_t &constraint)
Definition: graph.cc:580
PyWDevicePtr_t robot
Definition: graph.hh:91
std::string displayTransitionConstraints(PyWEdgePtr_t edge)
Definition: graph.cc:950
void addNumericalConstraintsToState(PyWStatePtr_t component, const boost::python::list &py_constraints)
Definition: graph.cc:585
void registerConstraints(const ImplicitPtr_t &constraint, const ImplicitPtr_t &complement, const ImplicitPtr_t &both)
Definition: graph.cc:665
boost::python::list getTransitions()
Definition: graph.cc:495
void setWeight(PyWEdgePtr_t edge, int weight)
Definition: graph.cc:420
PyWStatePtr_t getState(const std::string &stateName)
Definition: graph.cc:478
Python wrapper for State.
Definition: graph.hh:67
std::string name() const
Definition: graph.cc:257
StatePtr_t obj
Definition: graph.hh:68
PyWState(const StatePtr_t &object)
Definition: graph.cc:256