Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
loco-3d
Multicontact-api
Commits
308fad23
Commit
308fad23
authored
May 06, 2020
by
Pierre Fernbach
Browse files
Refactor ContactModelPlanar -> ContactModel
parent
ec4f55f9
Changes
8
Hide whitespace changes
Inline
Side-by-side
bindings/python/scenario/contact-model.cpp
View file @
308fad23
...
...
@@ -2,12 +2,12 @@
// Authors: Justin Carpentier <jcarpent@laas.fr>
#include
"multicontact-api/bindings/python/scenario/expose-scenario.hpp"
#include
"multicontact-api/bindings/python/scenario/contact-model
-planar
.hpp"
#include
"multicontact-api/bindings/python/scenario/contact-model.hpp"
namespace
multicontact_api
{
namespace
python
{
void
exposeContactModels
()
{
ContactModelP
lanarP
ythonVisitor
<
multicontact_api
::
scenario
::
ContactModel
Planar
>::
expose
(
"ContactModel
Planar
"
);
ContactModelPythonVisitor
<
multicontact_api
::
scenario
::
ContactModel
>::
expose
(
"ContactModel"
);
}
}
// namespace python
}
// namespace multicontact_api
include/multicontact-api/CMakeLists.txt
View file @
308fad23
...
...
@@ -15,7 +15,7 @@ SET(${PROJECT_NAME}_SERIALIZATION_HEADERS
)
SET
(
${
PROJECT_NAME
}
_SCENARIO_HEADERS
scenario/contact-model
-planar
.hpp
scenario/contact-model.hpp
scenario/contact-patch.hpp
scenario/contact-phase.hpp
scenario/contact-sequence.hpp
...
...
@@ -29,7 +29,7 @@ SET(${PROJECT_NAME}_PYTHON_HEADERS
bindings/python/geometry/linear-cone.hpp
bindings/python/geometry/second-order-cone.hpp
bindings/python/serialization/archive.hpp
bindings/python/scenario/contact-model
-planar
.hpp
bindings/python/scenario/contact-model.hpp
bindings/python/scenario/contact-patch.hpp
bindings/python/scenario/contact-phase.hpp
bindings/python/scenario/contact-sequence.hpp
...
...
include/multicontact-api/bindings/python/scenario/contact-model.hpp
View file @
308fad23
...
...
@@ -6,7 +6,7 @@
#include
<string>
#include
"multicontact-api/scenario/contact-model
-planar
.hpp"
#include
"multicontact-api/scenario/contact-model.hpp"
#include
"multicontact-api/bindings/python/serialization/archive.hpp"
#include
"multicontact-api/bindings/python/utils/printable.hpp"
...
...
@@ -15,18 +15,18 @@ namespace python {
namespace
bp
=
boost
::
python
;
template
<
typename
ContactModel
Planar
>
struct
ContactModelP
lanarP
ythonVisitor
:
public
boost
::
python
::
def_visitor
<
ContactModelP
lanarP
ythonVisitor
<
ContactModel
Planar
>
>
{
typedef
typename
ContactModel
Planar
::
Scalar
Scalar
;
template
<
typename
ContactModel
>
struct
ContactModelPythonVisitor
:
public
boost
::
python
::
def_visitor
<
ContactModelPythonVisitor
<
ContactModel
>
>
{
typedef
typename
ContactModel
::
Scalar
Scalar
;
template
<
class
PyClass
>
void
visit
(
PyClass
&
cl
)
const
{
cl
.
def
(
bp
::
init
<>
())
.
def
(
bp
::
init
<
Scalar
,
Scalar
>
(
bp
::
args
(
"mu"
,
"ZMP_radius"
)))
.
def
(
bp
::
init
<
ContactModel
Planar
>
(
bp
::
args
(
"other"
),
"Copy contructor."
))
.
def_readwrite
(
"mu"
,
&
ContactModel
Planar
::
m_mu
,
"Friction coefficient."
)
.
def_readwrite
(
"ZMP_radius"
,
&
ContactModel
Planar
::
m_ZMP_radius
,
"Radius of the ZMP region."
)
.
def
(
bp
::
init
<
ContactModel
>
(
bp
::
args
(
"other"
),
"Copy contructor."
))
.
def_readwrite
(
"mu"
,
&
ContactModel
::
m_mu
,
"Friction coefficient."
)
.
def_readwrite
(
"ZMP_radius"
,
&
ContactModel
::
m_ZMP_radius
,
"Radius of the ZMP region."
)
.
def
(
bp
::
self
==
bp
::
self
)
.
def
(
bp
::
self
!=
bp
::
self
)
...
...
@@ -35,14 +35,14 @@ struct ContactModelPlanarPythonVisitor
static
void
expose
(
const
std
::
string
&
class_name
)
{
std
::
string
doc
=
"Contact Model Planar"
;
bp
::
class_
<
ContactModel
Planar
>
(
class_name
.
c_str
(),
doc
.
c_str
(),
bp
::
no_init
)
.
def
(
ContactModelP
lanarP
ythonVisitor
<
ContactModel
Planar
>
())
.
def
(
SerializableVisitor
<
ContactModel
Planar
>
())
.
def
(
PrintableVisitor
<
ContactModel
Planar
>
());
bp
::
class_
<
ContactModel
>
(
class_name
.
c_str
(),
doc
.
c_str
(),
bp
::
no_init
)
.
def
(
ContactModelPythonVisitor
<
ContactModel
>
())
.
def
(
SerializableVisitor
<
ContactModel
>
())
.
def
(
PrintableVisitor
<
ContactModel
>
());
}
private:
static
ContactModel
Planar
copy
(
const
ContactModel
Planar
&
self
)
{
return
ContactModel
Planar
(
self
);
}
static
ContactModel
copy
(
const
ContactModel
&
self
)
{
return
ContactModel
(
self
);
}
};
}
// namespace python
}
// namespace multicontact_api
...
...
include/multicontact-api/scenario/contact-model.hpp
0 → 100644
View file @
308fad23
// Copyright (c) 2015-2018, CNRS
// Authors: Justin Carpentier <jcarpent@laas.fr>
#ifndef __multicontact_api_scenario_contact_model_planar_hpp__
#define __multicontact_api_scenario_contact_model_planar_hpp__
#include
"multicontact-api/scenario/fwd.hpp"
#include
"multicontact-api/serialization/archive.hpp"
#include
<iostream>
#include
<Eigen/Dense>
namespace
multicontact_api
{
namespace
scenario
{
template
<
typename
_Scalar
>
struct
ContactModelTpl
:
public
serialization
::
Serializable
<
ContactModelTpl
<
_Scalar
>
>
{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef
_Scalar
Scalar
;
/// \brief Default constructor.
ContactModelTpl
()
:
m_mu
(
-
1.
),
m_ZMP_radius
(
-
1.
)
{}
/// \brief Default constructor.
ContactModelTpl
(
const
Scalar
mu
,
const
Scalar
ZMP_radius
)
:
m_mu
(
mu
),
m_ZMP_radius
(
ZMP_radius
)
{}
/// \brief Copy constructor
template
<
typename
S2
>
explicit
ContactModelTpl
(
const
ContactModelTpl
<
S2
>&
other
)
:
m_mu
(
other
.
mu
),
m_ZMP_radius
(
other
.
ZMP_radius
)
{}
template
<
typename
S2
>
bool
operator
==
(
const
ContactModelTpl
<
S2
>&
other
)
const
{
return
m_mu
==
other
.
m_mu
&&
m_ZMP_radius
==
other
.
m_ZMP_radius
;
}
template
<
typename
S2
>
bool
operator
!=
(
const
ContactModelTpl
<
S2
>&
other
)
const
{
return
!
(
*
this
==
other
);
}
void
disp
(
std
::
ostream
&
os
)
const
{
os
<<
"mu: "
<<
m_mu
<<
std
::
endl
<<
"ZMP radius: "
<<
m_ZMP_radius
<<
std
::
endl
;
}
template
<
typename
S2
>
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ContactModelTpl
<
S2
>&
cp
)
{
cp
.
disp
(
os
);
return
os
;
}
/// \brief Friction coefficient.
Scalar
m_mu
;
/// \brief ZMP radius.
Scalar
m_ZMP_radius
;
private:
// Serialization of the class
friend
class
boost
::
serialization
::
access
;
template
<
class
Archive
>
void
save
(
Archive
&
ar
,
const
unsigned
int
/*version*/
)
const
{
ar
&
boost
::
serialization
::
make_nvp
(
"mu"
,
m_mu
);
ar
&
boost
::
serialization
::
make_nvp
(
"ZMP_radius"
,
m_ZMP_radius
);
}
template
<
class
Archive
>
void
load
(
Archive
&
ar
,
const
unsigned
int
/*version*/
)
{
ar
>>
boost
::
serialization
::
make_nvp
(
"mu"
,
m_mu
);
ar
>>
boost
::
serialization
::
make_nvp
(
"ZMP_radius"
,
m_ZMP_radius
);
}
BOOST_SERIALIZATION_SPLIT_MEMBER
()
};
}
// namespace scenario
}
// namespace multicontact_api
#endif // ifndef __multicontact_api_scenario_contact_model_planar_hpp__
include/multicontact-api/scenario/fwd.hpp
View file @
308fad23
...
...
@@ -26,8 +26,8 @@ struct ContactSequenceTpl;
typedef
ContactSequenceTpl
<
ContactPhase
>
ContactSequence
;
template
<
typename
Scalar
>
struct
ContactModel
Planar
Tpl
;
typedef
ContactModel
Planar
Tpl
<
double
>
ContactModel
Planar
;
struct
ContactModelTpl
;
typedef
ContactModelTpl
<
double
>
ContactModel
;
enum
ConicType
{
CONIC_SOWC
,
CONIC_DOUBLE_DESCRIPTION
,
CONIC_UNDEFINED
};
...
...
unittest/python/scenario.py
View file @
308fad23
...
...
@@ -9,7 +9,7 @@ from curves import SE3Curve, bezier, piecewise, piecewise_SE3, polynomial
from
numpy
import
array
,
array_equal
,
isclose
,
random
import
pinocchio
as
pin
from
multicontact_api
import
ContactModel
Planar
,
ContactPatch
,
ContactPhase
,
ContactSequence
from
multicontact_api
import
ContactModel
,
ContactPatch
,
ContactPhase
,
ContactSequence
from
pinocchio
import
SE3
,
Quaternion
import
pickle
pin
.
switchToNumpyArray
()
...
...
@@ -153,13 +153,13 @@ class ContactModelTest(unittest.TestCase):
mu
=
0.3
zmp_radius
=
0.01
# constructor with both values
mp1
=
ContactModel
Planar
(
mu
,
zmp_radius
)
mp1
=
ContactModel
(
mu
,
zmp_radius
)
# test getter bindings
self
.
assertEqual
(
mp1
.
mu
,
mu
)
self
.
assertEqual
(
mp1
.
ZMP_radius
,
zmp_radius
)
# copy constructor :
mp2
=
ContactModel
Planar
(
mp1
)
mp2
=
ContactModel
(
mp1
)
self
.
assertEqual
(
mp2
.
mu
,
mu
)
self
.
assertEqual
(
mp2
.
ZMP_radius
,
zmp_radius
)
...
...
@@ -169,17 +169,17 @@ class ContactModelTest(unittest.TestCase):
self
.
assertTrue
(
mp1
!=
mp2
)
def
test_contact_model_serialization_default
(
self
):
mp1
=
ContactModel
Planar
()
mp1
=
ContactModel
()
mp1
.
saveAsText
(
"mp_test.txt"
)
mp_txt
=
ContactModel
Planar
()
mp_txt
=
ContactModel
()
mp_txt
.
loadFromText
(
"mp_test.txt"
)
self
.
assertEqual
(
mp1
,
mp_txt
)
mp1
.
saveAsBinary
(
"mp_test"
)
mp_bin
=
ContactModel
Planar
()
mp_bin
=
ContactModel
()
mp_bin
.
loadFromBinary
(
"mp_test"
)
self
.
assertEqual
(
mp1
,
mp_bin
)
mp1
.
saveAsXML
(
"mp_test.xml"
,
'ContactModel'
)
mp_xml
=
ContactModel
Planar
()
mp_xml
=
ContactModel
()
mp_xml
.
loadFromXML
(
"mp_test.xml"
,
'ContactPatch'
)
self
.
assertEqual
(
mp1
,
mp_xml
)
mp_pickled
=
pickle
.
dumps
(
mp1
)
...
...
@@ -190,17 +190,17 @@ class ContactModelTest(unittest.TestCase):
mu
=
0.3
zmp_radius
=
0.01
# constructor with both values
mp1
=
ContactModel
Planar
(
mu
,
zmp_radius
)
mp1
=
ContactModel
(
mu
,
zmp_radius
)
mp1
.
saveAsText
(
"mp_test.txt"
)
mp_txt
=
ContactModel
Planar
()
mp_txt
=
ContactModel
()
mp_txt
.
loadFromText
(
"mp_test.txt"
)
self
.
assertEqual
(
mp1
,
mp_txt
)
mp1
.
saveAsBinary
(
"mp_test"
)
mp_bin
=
ContactModel
Planar
()
mp_bin
=
ContactModel
()
mp_bin
.
loadFromBinary
(
"mp_test"
)
self
.
assertEqual
(
mp1
,
mp_bin
)
mp1
.
saveAsXML
(
"mp_test.xml"
,
'ContactModel'
)
mp_xml
=
ContactModel
Planar
()
mp_xml
=
ContactModel
()
mp_xml
.
loadFromXML
(
"mp_test.xml"
,
'ContactPatch'
)
self
.
assertEqual
(
mp1
,
mp_xml
)
mp_pickled
=
pickle
.
dumps
(
mp1
)
...
...
unittest/python/trivial.py
View file @
308fad23
...
...
@@ -6,7 +6,7 @@ import multicontact_api
class
TrivialTest
(
unittest
.
TestCase
):
""" A test written by someone who has no idea what this software is about"""
def
test_trivial
(
self
):
comopla
=
multicontact_api
.
ContactModel
Planar
()
comopla
=
multicontact_api
.
ContactModel
()
epsilon
=
0.00001
value_wanted
=
-
1.0
self
.
assertTrue
((
comopla
.
mu
-
value_wanted
)
<
epsilon
)
...
...
unittest/scenario.cpp
View file @
308fad23
...
...
@@ -7,7 +7,7 @@
#include
<boost/test/unit_test.hpp>
#include
<boost/utility/binary.hpp>
#include
"multicontact-api/scenario/contact-model
-planar
.hpp"
#include
"multicontact-api/scenario/contact-model.hpp"
#include
"multicontact-api/scenario/contact-patch.hpp"
#include
"multicontact-api/scenario/contact-phase.hpp"
#include
"multicontact-api/scenario/contact-sequence.hpp"
...
...
@@ -343,35 +343,35 @@ BOOST_AUTO_TEST_CASE(contact_model) {
const
double
mu
=
0.3
;
const
double
ZMP_radius
=
0.01
;
ContactModel
Planar
mp1
(
mu
,
ZMP_radius
);
ContactModel
Planar
mp2
(
mp1
);
ContactModel
mp1
(
mu
,
ZMP_radius
);
ContactModel
mp2
(
mp1
);
BOOST_CHECK
(
mp1
.
m_mu
==
mu
);
BOOST_CHECK
(
mp1
.
m_ZMP_radius
==
ZMP_radius
);
BOOST_CHECK
(
mp1
==
mp2
);
mp1
.
m_mu
=
0.5
;
BOOST_CHECK
(
mp1
!=
mp2
);
ContactModel
Planar
mp3
(
mp1
);
ContactModel
mp3
(
mp1
);
BOOST_CHECK
(
mp1
==
mp3
);
mp3
.
m_ZMP_radius
=
0.5
;
BOOST_CHECK
(
mp1
!=
mp3
);
std
::
cout
<<
"ContactModel
Planar
before serialization :
\n
"
<<
mp1
<<
std
::
endl
;
std
::
cout
<<
"ContactModel before serialization :
\n
"
<<
mp1
<<
std
::
endl
;
std
::
string
fileName
(
"fileTest_contactModel"
);
mp1
.
saveAsText
(
fileName
+
".txt"
);
ContactModel
Planar
mp_from_text
;
ContactModel
mp_from_text
;
mp_from_text
.
loadFromText
(
fileName
+
".txt"
);
std
::
cout
<<
"ContactModel
Planar
after serialization :
\n
"
<<
mp_from_text
<<
std
::
endl
;
std
::
cout
<<
"ContactModel after serialization :
\n
"
<<
mp_from_text
<<
std
::
endl
;
BOOST_CHECK
(
mp1
==
mp_from_text
);
mp1
.
saveAsXML
(
fileName
+
".xml"
,
"ContactModel"
);
ContactModel
Planar
mp_from_xml
;
ContactModel
mp_from_xml
;
mp_from_xml
.
loadFromXML
(
fileName
+
".xml"
,
"ContactModel"
);
BOOST_CHECK
(
mp1
==
mp_from_xml
);
mp1
.
saveAsBinary
(
fileName
);
ContactModel
Planar
mp_from_bin
;
ContactModel
mp_from_bin
;
mp_from_bin
.
loadFromBinary
(
fileName
);
BOOST_CHECK
(
mp1
==
mp_from_bin
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment