RcsPySim
A robot control and simulation library
PPDMaterialProperties.cpp
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 #include "PPDMaterialProperties.h"
32 
33 #include <libxml/tree.h>
34 #include <array>
35 
36 namespace Rcs
37 {
38 
39 // Vortex extended property list
40 static const char* extended_xml_material_props[] = {
41 // "slip", // TODO detect which solver bullet is suing and then automatically add this entry
42  "compliance",
43 };
44 
46 
48 
49 
51 {
52  std::string prefixedName;
53  // Bullet and Vortex
54  prefixedName = bodyParamInfo->paramNamePrefix + "friction_coefficient";
55  outValues->setProperty(prefixedName.c_str(), bodyParamInfo->material.getFrictionCoefficient());
56  prefixedName = bodyParamInfo->paramNamePrefix + "rolling_friction_coefficient";
57  outValues->setProperty(prefixedName.c_str(), bodyParamInfo->material.getRollingFrictionCoefficient());
58  prefixedName = bodyParamInfo->paramNamePrefix + "restitution";
59  outValues->setProperty(prefixedName.c_str(), bodyParamInfo->material.getRestitution());
60  prefixedName = bodyParamInfo->paramNamePrefix + "slip";
61  double slip = 0; // TODO @Michael: there is no bodyParamInfo->material.getSlip()
62  bodyParamInfo->material.getDouble("slip", slip);
63  outValues->setProperty(prefixedName.c_str(), slip);
64 
65  // Extension properties stored in the config xml-file
66  for (auto propname : extended_xml_material_props) {
67  auto configValue = xmlGetProp(bodyParamInfo->material.materialNode, BAD_CAST propname);
68  if (configValue != nullptr) {
69  prefixedName = bodyParamInfo->paramNamePrefix + propname;
70  outValues->setProperty(prefixedName.c_str(), configValue); // types aren't well defined, assuming string
71  }
72  }
73 }
74 
76 {
77  std::string prefixedName;
78  double value;
79  // Bullet and Vortex
80  prefixedName = bodyParamInfo->paramNamePrefix + "friction_coefficient";
81  if (inValues->getProperty(value, prefixedName.c_str())) {
82  bodyParamInfo->material.setFrictionCoefficient(value);
83  }
84  prefixedName = bodyParamInfo->paramNamePrefix + "rolling_friction_coefficient";
85  if (inValues->getProperty(value, prefixedName.c_str())) {
86  bodyParamInfo->material.setRollingFrictionCoefficient(value);
87  }
88  prefixedName = bodyParamInfo->paramNamePrefix + "restitution";
89  if (inValues->getProperty(value, prefixedName.c_str())) {
90  bodyParamInfo->material.setRestitution(value);
91  }
92  prefixedName = bodyParamInfo->paramNamePrefix + "slip";
93  if (inValues->getProperty(value, prefixedName.c_str())) {
94 // bodyParamInfo->material.setSlip(value); / TODO @Michael: there is no bodyParamInfo->material.setSlip()
95  bodyParamInfo->material.setDouble("slip", value);
96  }
97 
98  // Extension properties stored in the config xml-file
99  std::string configValue;
100  for (auto propname : extended_xml_material_props) {
101  prefixedName = bodyParamInfo->paramNamePrefix + propname;
102  // Transfer config value as string to support all possible kinds
103  if (inValues->getProperty(configValue, prefixedName.c_str())) {
104  // Store in the xml-file
105  xmlSetProp(bodyParamInfo->material.materialNode, BAD_CAST propname, BAD_CAST configValue.c_str());
106  }
107  }
108 }
109 
110 } /* namespace Rcs */
virtual bool getProperty(std::string &out, const char *property)=0
virtual void setValues(PropertySource *inValues)
static const char * extended_xml_material_props[]
virtual void setProperty(const char *property, const std::string &value)=0
std::string paramNamePrefix
prefix for parameter names
Definition: BodyParamInfo.h:67
PhysicsMaterial material
Material of the body&#39;s first shape.
Definition: BodyParamInfo.h:70
virtual void getValues(PropertySink *outValues)