RcsPySim
A robot control and simulation library
PhysicsParameterManager.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (c) 2020, Fabio Muratore, Honda Research Institute Europe GmbH, and
3  Technical University of Darmstadt.
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  1. Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  2. Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  3. Neither the name of Fabio Muratore, Honda Research Institute Europe GmbH,
14  or Technical University of Darmstadt, nor the names of its contributors may
15  be used to endorse or promote products derived from this software without
16  specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL FABIO MURATORE, HONDA RESEARCH INSTITUTE EUROPE GMBH,
22  OR TECHNICAL UNIVERSITY OF DARMSTADT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  POSSIBILITY OF SUCH DAMAGE.
29 *******************************************************************************/
30 
31 #ifndef _PHYSICSPARAMETERMANAGER_H_
32 #define _PHYSICSPARAMETERMANAGER_H_
33 
34 #include "BodyParamInfo.h"
36 #include "../util/nocopy.h"
37 
38 #include <PhysicsBase.h>
39 
40 #include <vector>
41 #include <list>
42 
43 namespace Rcs
44 {
45 
46 /**
47  * Main physics parameter modification system.
48  * Keeps a list of parameter descriptors, allows setting values on them
49  * and transfers those values to the physics simulation.
50  *
51  */
53 {
54 public:
55  /**
56  * Constructor.
57  * @param graph graph to modify
58  * @param physicsEngineName name of physics engine to use
59  * @param physicsConfigFile config file for the physics engine
60  */
62  RcsGraph* graph,
63  const std::string& physicsEngineName,
64  const std::string& physicsConfigFile);
65 
66  virtual ~PhysicsParameterManager();
67 
68  // not copy- or movable
70 
71  /**
72  * Register a parameter descriptor operating on the given named body.
73  * Takes ownership of the descriptor.
74  * @param bodyName name of body to use
75  * @param desc descriptor of the parameters to make changeable on the body.
76  */
77  void addParam(const char* bodyName, PhysicsParameterDescriptor* desc);
78 
79  /**
80  * Get the BodyParamInfo object for the given named body, creating it if it doesn't exist.
81  * @param bodyName name of body to look up.
82  */
83  BodyParamInfo* getBodyInfo(const char* bodyName);
84 
85  /**
86  * Query current parameter values.
87  */
88  void getValues(PropertySink* outValues) const;
89 
90  /**
91  * Create a new physics simulation using the given physics parameter values.
92  * @param values parameter values to set
93  * @return new physics simulator
94  */
95  PhysicsBase* createSimulator(PropertySource* values);
96 
97 private:
98  // graph to update
99  RcsGraph* graph;
100 
101  // name of physics engine to use
102  std::string physicsEngineName;
103 
104  // parsed physics engine configuration.
105  PhysicsConfig* physicsConfig;
106 
107  // list of modifyable bodies. Uses std::list to get persistent references to elements.
108  std::list<BodyParamInfo> bodyInfos;
109 
110  // list of parameter descriptors
111  std::vector<PhysicsParameterDescriptor*> paramDescs;
112 };
113 
114 } /* namespace Rcs */
115 
116 #endif /* _PHYSICSPARAMETERMANAGER_H_ */
void getValues(PropertySink *outValues) const
PhysicsBase * createSimulator(PropertySource *values)
#define RCSPYSIM_NOCOPY_NOMOVE(cls)
Definition: nocopy.h:40
void addParam(const char *bodyName, PhysicsParameterDescriptor *desc)
BodyParamInfo * getBodyInfo(const char *bodyName)
std::list< BodyParamInfo > bodyInfos
PhysicsParameterManager(RcsGraph *graph, const std::string &physicsEngineName, const std::string &physicsConfigFile)
std::vector< PhysicsParameterDescriptor * > paramDescs