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
ec4f55f9
Commit
ec4f55f9
authored
May 06, 2020
by
Pierre Fernbach
Browse files
[Tests] add test case for serialization of contactModel
parent
73409534
Changes
3
Hide whitespace changes
Inline
Side-by-side
include/multicontact-api/bindings/python/scenario/contact-model
-planar
.hpp
→
include/multicontact-api/bindings/python/scenario/contact-model.hpp
View file @
ec4f55f9
File moved
include/multicontact-api/scenario/contact-model-planar.hpp
deleted
100644 → 0
View file @
73409534
// 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
ContactModelPlanarTpl
:
public
serialization
::
Serializable
<
ContactModelPlanarTpl
<
_Scalar
>
>
{
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef
_Scalar
Scalar
;
/// \brief Default constructor.
ContactModelPlanarTpl
()
:
m_mu
(
-
1.
),
m_ZMP_radius
(
-
1.
)
{}
/// \brief Default constructor.
ContactModelPlanarTpl
(
const
Scalar
mu
,
const
Scalar
ZMP_radius
)
:
m_mu
(
mu
),
m_ZMP_radius
(
ZMP_radius
)
{}
/// \brief Copy constructor
template
<
typename
S2
>
explicit
ContactModelPlanarTpl
(
const
ContactModelPlanarTpl
<
S2
>&
other
)
:
m_mu
(
other
.
mu
),
m_ZMP_radius
(
other
.
ZMP_radius
)
{}
template
<
typename
S2
>
bool
operator
==
(
const
ContactModelPlanarTpl
<
S2
>&
other
)
const
{
return
m_mu
==
other
.
m_mu
&&
m_ZMP_radius
==
other
.
m_ZMP_radius
;
}
template
<
typename
S2
>
bool
operator
!=
(
const
ContactModelPlanarTpl
<
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
ContactModelPlanarTpl
<
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__
unittest/scenario.cpp
View file @
ec4f55f9
...
...
@@ -351,8 +351,29 @@ BOOST_AUTO_TEST_CASE(contact_model) {
BOOST_CHECK
(
mp1
==
mp2
);
mp1
.
m_mu
=
0.5
;
BOOST_CHECK
(
mp1
!=
mp2
);
// TODO : check serialization
ContactModelPlanar
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
::
string
fileName
(
"fileTest_contactModel"
);
mp1
.
saveAsText
(
fileName
+
".txt"
);
ContactModelPlanar
mp_from_text
;
mp_from_text
.
loadFromText
(
fileName
+
".txt"
);
std
::
cout
<<
"ContactModel Planar after serialization :
\n
"
<<
mp_from_text
<<
std
::
endl
;
BOOST_CHECK
(
mp1
==
mp_from_text
);
mp1
.
saveAsXML
(
fileName
+
".xml"
,
"ContactModel"
);
ContactModelPlanar
mp_from_xml
;
mp_from_xml
.
loadFromXML
(
fileName
+
".xml"
,
"ContactModel"
);
BOOST_CHECK
(
mp1
==
mp_from_xml
);
mp1
.
saveAsBinary
(
fileName
);
ContactModelPlanar
mp_from_bin
;
mp_from_bin
.
loadFromBinary
(
fileName
);
BOOST_CHECK
(
mp1
==
mp_from_bin
);
}
BOOST_AUTO_TEST_CASE
(
contact_patch
)
{
...
...
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